diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 5267336ed02f8207da85958e082d3ab2998fce8d..2b72faa879640c4e21e01dc4465c4fbee261baac 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -29,8 +29,8 @@ import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponses; +import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.utils.ModelUtils; -import org.openapitools.codegen.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,9 +96,9 @@ public class InlineModelResolver { } for (Operation operation : operations) { - flattenRequestBody(pathname, operation); - flattenParameters(pathname, operation); - flattenResponses(pathname, operation); + flattenOperationRequestBody(pathname, operation); + flattenOperationParameters(pathname, operation); + flattenOperationResponses(pathname, operation); } } } @@ -312,20 +312,30 @@ public class InlineModelResolver { * @param pathname target pathname * @param operation target operation */ - private void flattenRequestBody(String pathname, Operation operation) { + private void flattenOperationRequestBody(String pathname, Operation operation) { RequestBody requestBody = operation.getRequestBody(); if (requestBody == null) { return; } + String requestBodyName = ""; + + // Handle Swagger 2 -> OAS 3 conversion where the request body name is + // set as a vendor extension. + if (operation.getExtensions() != null && operation.getExtensions().containsKey("x-codegen-request-body-name")) { + requestBodyName = (String) operation.getExtensions().get("x-codegen-request-body-name"); + } + Schema model = ModelUtils.getSchemaFromRequestBody(requestBody); if (model instanceof ObjectSchema) { Schema obj = model; + if (StringUtils.isBlank(requestBodyName)) { + requestBodyName = obj.getTitle(); + } if (obj.getType() == null || "object".equals(obj.getType())) { if (obj.getProperties() != null && obj.getProperties().size() > 0) { flattenProperties(openAPI, obj.getProperties(), pathname); - // for model name, use "title" if defined, otherwise default to 'inline_object' - String modelName = resolveModelName(obj.getTitle(), "inline_object"); + String modelName = resolveModelName(requestBodyName, "inline_object"); addGenerated(modelName, model); openAPI.getComponents().addSchemas(modelName, model); @@ -373,10 +383,13 @@ public class InlineModelResolver { Schema inner = am.getItems(); if (inner instanceof ObjectSchema) { ObjectSchema op = (ObjectSchema) inner; + if (StringUtils.isBlank(requestBodyName)) { + requestBodyName = op.getTitle(); + } if (op.getProperties() != null && op.getProperties().size() > 0) { flattenProperties(openAPI, op.getProperties(), pathname); // Generate a unique model name based on the title. - String modelName = resolveModelName(op.getTitle(), null); + String modelName = resolveModelName(requestBodyName, null); Schema innerModel = modelFromProperty(openAPI, op, modelName); String existing = matchGenerated(innerModel); if (existing != null) { @@ -401,7 +414,7 @@ public class InlineModelResolver { * @param pathname target pathname * @param operation target operation */ - private void flattenParameters(String pathname, Operation operation) { + private void flattenOperationParameters(String pathname, Operation operation) { List<Parameter> parameters = operation.getParameters(); if (parameters == null) { return; @@ -458,7 +471,7 @@ public class InlineModelResolver { * @param pathname target pathname * @param operation target operation */ - private void flattenResponses(String pathname, Operation operation) { + private void flattenOperationResponses(String pathname, Operation operation) { ApiResponses responses = operation.getResponses(); if (responses == null) { return; @@ -614,6 +627,14 @@ public class InlineModelResolver { * Flatten inline models in components */ private void flattenComponents() { + flattenSchemaComponents(); + flattenRequestBodyComponents(); + } + + /** + * Flatten inline models in schemas + */ + private void flattenSchemaComponents() { Map<String, Schema> models = openAPI.getComponents().getSchemas(); if (models == null) { return; @@ -661,6 +682,69 @@ public class InlineModelResolver { } } + /** + * Flatten inline models in request bodies + */ + private void flattenRequestBodyComponents() { + Map<String, RequestBody> requestBodies = openAPI.getComponents().getRequestBodies(); + if (requestBodies == null) { + return; + } + + List<String> requestBodyNames = new ArrayList<String>(requestBodies.keySet()); + for (String requestBodyName : requestBodyNames) { + RequestBody requestBody = requestBodies.get(requestBodyName); + + Content content = requestBody.getContent(); + if (content == null || content.isEmpty()) { + continue; + } + + for (MediaType mt : content.values()) { + Schema model = mt.getSchema(); + if (model instanceof ObjectSchema) { + if (model.getType() != null && !"object".equals(model.getType())) { + continue; + } + if (model.getProperties() == null || model.getProperties().isEmpty()) { + continue; + } + + flattenProperties(openAPI, model.getProperties(), requestBodyName); + String modelName = resolveModelName(requestBodyName, "inline_request_body"); + addGenerated(modelName, model); + openAPI.getComponents().addSchemas(modelName, model); + + mt.setSchema(new Schema().$ref(modelName)); + } else if (model instanceof ArraySchema) { + ArraySchema am = (ArraySchema) model; + Schema inner = am.getItems(); + if (inner instanceof ObjectSchema) { + ObjectSchema op = (ObjectSchema) inner; + if (op.getProperties() != null && op.getProperties().size() > 0) { + flattenProperties(openAPI, op.getProperties(), requestBodyName); + // Generate a unique model name based on the title. + String modelName = resolveModelName(requestBodyName, null); + Schema innerModel = modelFromProperty(openAPI, op, modelName); + String existing = matchGenerated(innerModel); + if (existing != null) { + Schema schema = new Schema().$ref(existing); + schema.setRequired(op.getRequired()); + am.setItems(schema); + } else { + Schema schema = new Schema().$ref(modelName); + schema.setRequired(op.getRequired()); + am.setItems(schema); + addGenerated(modelName, innerModel); + openAPI.getComponents().addSchemas(modelName, innerModel); + } + } + } + } + } + } + } + /** * This function fix models that are string (mostly enum). Before this fix, the * example would look something like that in the doc: "\"example from def\"" diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java index 3ac23d849eff75787642cb6818bb24de97235069..3a835511924c229e94106141fb597ec1097fab67 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java @@ -454,6 +454,29 @@ public class InlineModelResolverTest { assertEquals("#/components/schemas/resolveInlineArrayRequestBodyWithTitleItems", requestBodySchema.getItems().get$ref()); } + @Test + public void testResolveInlineRequestBodyRef() { + OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); + new InlineModelResolver().flatten(openAPI); + + RequestBody requestBodyReference = openAPI + .getPaths() + .get("/resolve_inline_request_body_ref") + .getPost() + .getRequestBody(); + assertNotNull(requestBodyReference.get$ref()); + + RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, requestBodyReference); + assertTrue(requestBody.getRequired()); + MediaType mediaType = requestBody.getContent().get("application/json"); + assertNotNull(mediaType.getSchema().get$ref()); + assertEquals("#/components/schemas/ResolveInlineRequestBodyRefRequest", mediaType.getSchema().get$ref()); + + Schema schema = ModelUtils.getReferencedSchema(openAPI, mediaType.getSchema()); + assertTrue(schema instanceof ObjectSchema); + assertTrue(schema.getProperties().get("name") instanceof StringSchema); + } + @Test public void resolveInlineArrayResponse() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index de2b775456bd566a4d18f6c0970c4df8939284d4..8938b0eef05ff006beed2a996f5658550eca210e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -1365,4 +1365,18 @@ public class SpringCodegenTest { .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\"")); } + + @Test + public void testInlineRequestBody() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_10435.yaml"); + final SpringCodegen codegen = new SpringCodegen(); + codegen.setOpenAPI(openAPI); + + Schema target = openAPI.getComponents().getSchemas().get("setupReq"); + Assert.assertNotNull(target); + CodegenModel cm = codegen.fromModel("setupReq", target); + + Assert.assertEquals(cm.dataType, "Object"); + Assert.assertEquals(cm.vars.get(0).name, "property"); + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/AbstractPhpCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/AbstractPhpCodegenTest.java index 5f7c52e542081f8c670f817383eae290cd394aa0..4bd68f96eae45dc0779e8bbd2a1a1d1fb12036d4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/AbstractPhpCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/AbstractPhpCodegenTest.java @@ -166,6 +166,23 @@ public class AbstractPhpCodegenTest { Assert.assertEquals(cp1.getDefaultValue(), "'VALUE'"); } + @Test(description = "Issue #9123") + public void TestNamedInlineRequestBody() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_9123.yaml"); + final AbstractPhpCodegen codegen = new P_AbstractPhpCodegen(); + codegen.setOpenAPI(openAPI); + + Schema target = openAPI.getComponents().getSchemas().get("ListOfDefinitions"); + Assert.assertNotNull(target); + CodegenModel cm = codegen.fromModel("ListOfDefinitions", target); + + Assert.assertEquals(cm.getDataType(), "object"); + Assert.assertEquals(codegen.getTypeDeclaration("ListOfDefinitions"), "\\php\\Model\\ListOfDefinitions"); + + CodegenProperty label = cm.vars.get(0); + Assert.assertEquals(label.getName(), "label"); + } + private static class P_AbstractPhpCodegen extends AbstractPhpCodegen { @Override public CodegenType getTag() { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java index 24870864376554617165455023be951967e8a6d3..0df5ce739aee173824493861493d6fdf3eb2f39f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java @@ -30,6 +30,7 @@ import java.io.File; import java.math.BigDecimal; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -548,5 +549,24 @@ public class PythonClientTest { Assert.assertEquals(codegen.toModelName(input), want); } + @Test + public void testRequestBodyInlineSchema() throws Exception { + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python") + .setInputSpec("src/test/resources/3_0/issue_8605.json") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + DefaultGenerator generator = new DefaultGenerator(); + List<File> files = generator.opts(clientOptInput).generate(); + files.forEach(File::deleteOnExit); + Path apiFile = Paths.get(output + "/openapi_client/api/example_api.py"); + TestUtils.assertFileNotContains(apiFile, "import UNKNOWNBASETYPE"); + TestUtils.assertFileContains(apiFile, "from openapi_client.model.example_runs_input import ExampleRunsInput"); + TestUtils.ensureContainsFile(files, output, "openapi_client/model/example_runs_input.py"); + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java index 9bc7c709487ae97f92387d3ca3f638fd8008416f..f81b5dc43e99c4a4af1af2fbba8d506d8ffa6233 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchModelTest.java @@ -386,4 +386,18 @@ public class TypeScriptFetchModelTest { Assert.assertEquals(codegen.getTypeDeclaration(model), "{ [key: string]: string; }"); } + + @Test(description = "Inline request bodies create models") + public void testInlineRequestBody() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_11811.yaml"); + final DefaultCodegen codegen = new TypeScriptFetchClientCodegen(); + codegen.setOpenAPI(openAPI); + + Schema target = openAPI.getComponents().getSchemas().get("UserPost"); + Assert.assertNotNull(target); + CodegenModel cm = codegen.fromModel("UserPost", target); + + Assert.assertEquals(cm.dataType, "object"); + Assert.assertEquals(cm.vars.get(0).name, "firstName"); + } } diff --git a/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml b/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml index c7937795ced19eab8466774be70e56dd1e4bdc53..eeaa4dcaee03a913f820dfa9e81c13741744a000 100644 --- a/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml @@ -115,7 +115,6 @@ parameters: in: body required: true schema: - # Erroneously ends up as `Option<models::InlineObject>` properties: id: type: string diff --git a/modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml b/modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml index 4d10bef6205c9eb3aa589fbdbf9fcd2901989d78..5f4e403842a094aaa21eebf93a0b50d99e037693 100644 --- a/modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml @@ -105,6 +105,14 @@ paths: responses: '200': description: OK + /resolve_inline_request_body_ref: + post: + operationId: resolveInlineRequestBodyRef + requestBody: + $ref: '#/components/requestBodies/ResolveInlineRequestBodyRefRequest' + responses: + '200': + description: OK /resolve_inline_array_response: get: operationId: resolveInlineArrayResponse @@ -328,6 +336,16 @@ paths: data: type: string components: + requestBodies: + ResolveInlineRequestBodyRefRequest: + content: + application/json: + schema: + type: object + properties: + name: + type: string + required: true schemas: Users: type: array diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_10435.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_10435.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ff5fcc8d5c5a59f9111ca905c67554bc26a6c283 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_10435.yaml @@ -0,0 +1,22 @@ +openapi: 3.0.1 +info: + title: Example API + version: '1.0' +paths: + /test: + post: + requestBody: + $ref: '#/components/requestBodies/setupReq' + responses: + '201': + description: ok +components: + requestBodies: + setupReq: + content: + application/json: + schema: + type: object + properties: + property: + type: string diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_11811.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_11811.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c9277a05d54f15bae6a1d57a069204a1528f4fd0 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_11811.yaml @@ -0,0 +1,23 @@ +openapi: 3.0.0 +paths: + /user: + post: + summary: Create New User + operationId: post-user + requestBody: + $ref: '#/components/requestBodies/UserPost' + responses: + '200': + description: OK +components: + requestBodies: + UserPost: + content: + application/json: + schema: + type: object + properties: + firstName: + type: string + lastName: + type: string diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_8605.json b/modules/openapi-generator/src/test/resources/3_0/issue_8605.json new file mode 100644 index 0000000000000000000000000000000000000000..0d264930fb8e4a2d7e6473ae9bc58fbf7088f9db --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_8605.json @@ -0,0 +1,106 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "example", + "description": "example", + "version": "1.2.3", + "contact": {} + }, + "servers": [ + { + "url": "/api/example/v1", + "description": "relative path" + } + ], + "tags": [ + { + "name": "example", + "description": "example" + } + ], + "paths": { + "/example/{id}/run": { + "post": { + "tags": [ + "example" + ], + "summary": "Execute example", + "description": "Execute example", + "operationId": "runExample", + "parameters": [ + { + "$ref": "#/components/parameters/ExampleId" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/ExampleRunsInput" + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ExecuteExample" + } + } + } + } + } + } + } + }, + "components": { + "parameters": { + "ExampleId": { + "in": "path", + "name": "remediation", + "description": "example identifier (uuid)", + "required": true, + "schema": { + "$ref": "#/components/schemas/ExampleId" + } + } + }, + "requestBodies": { + "ExampleRunsInput": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "exclude": { + "type": "array", + "items": { + "type": "string", + "format": "uuid" + } + } + } + } + } + } + } + }, + "schemas": { + "ExampleId": { + "type": "string", + "format": "uuid", + "example": "9197ba55-0abc-4028-9bbe-269e530f8bd5" + }, + "ExecuteExample": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "$ref": "#/components/schemas/ExampleId" + } + } + } + } + } +} diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_9123.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_9123.yaml new file mode 100644 index 0000000000000000000000000000000000000000..582147b87fad122819515ced39c28bad7214f95b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_9123.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.1 +info: + title: test + description: test + version: 1.0.0 +servers: + - url: / +paths: + /definitions: + put: + summary: test + operationId: putTest + requestBody: + description: test + content: + application/json: + schema: + type: object + properties: + label: + type: string + description: label + required: true + responses: + 204: + description: successful operation + content: {} + x-codegen-request-body-name: ListOfDefinitions diff --git a/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES index 1495d4416fbc41e19c8b42fbe0cdd2755baa046e..4e7aed02c9f26202eb0fdc4ea09c854434cab80a 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES @@ -8,7 +8,7 @@ docs/AdditionalPropertiesObject.md docs/AllOfObject.md docs/BaseAllOf.md docs/GetYamlResponse.md -docs/InlineObject.md +docs/NestedResponse.md docs/ObjectOfObjects.md docs/ObjectOfObjectsInner.md docs/default_api.md diff --git a/samples/server/petstore/rust-server/output/rust-server-test/README.md b/samples/server/petstore/rust-server/output/rust-server-test/README.md index 13d136522ec53ec9dbd0155242d32bbfd1d7ec0b..613beb2cc991b71a627c859878b4c502fbe8f8fa 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/README.md +++ b/samples/server/petstore/rust-server/output/rust-server-test/README.md @@ -119,7 +119,7 @@ Method | HTTP request | Description - [AllOfObject](docs/AllOfObject.md) - [BaseAllOf](docs/BaseAllOf.md) - [GetYamlResponse](docs/GetYamlResponse.md) - - [InlineObject](docs/InlineObject.md) + - [NestedResponse](docs/NestedResponse.md) - [ObjectOfObjects](docs/ObjectOfObjects.md) - [ObjectOfObjectsInner](docs/ObjectOfObjectsInner.md) diff --git a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml index e7cef9a3cf2a22eb9864a974fdfe0d7ef035a5af..1497d3032a62052ade143359307ccca8090cdb76 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml @@ -17,7 +17,7 @@ paths: put: operationId: dummyPut requestBody: - $ref: '#/components/requestBodies/inline_object' + $ref: '#/components/requestBodies/nested_response' content: '*/*': schema: @@ -135,20 +135,7 @@ components: content: '*/*': schema: - properties: - id: - type: string - password: - type: string - required: - - id - type: object - required: true - inline_object: - content: - '*/*': - schema: - $ref: '#/components/schemas/inline_object' + $ref: '#/components/schemas/nested_response' required: true schemas: additionalPropertiesObject: @@ -194,7 +181,7 @@ components: description: Inner string type: string type: object - inline_object: + nested_response: properties: id: type: string diff --git a/samples/server/petstore/rust-server/output/rust-server-test/docs/InlineObject.md b/samples/server/petstore/rust-server/output/rust-server-test/docs/NestedResponse.md similarity index 95% rename from samples/server/petstore/rust-server/output/rust-server-test/docs/InlineObject.md rename to samples/server/petstore/rust-server/output/rust-server-test/docs/NestedResponse.md index c29026e8d7e0acfcaa2b10ebbbdc873d12a696ff..2882791f872214ee157219aea8ee9dcaf87a5cd7 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/docs/InlineObject.md +++ b/samples/server/petstore/rust-server/output/rust-server-test/docs/NestedResponse.md @@ -1,4 +1,4 @@ -# InlineObject +# NestedResponse ## Properties Name | Type | Description | Notes diff --git a/samples/server/petstore/rust-server/output/rust-server-test/docs/default_api.md b/samples/server/petstore/rust-server/output/rust-server-test/docs/default_api.md index 765136251f6c8448c9d0491e18d34f50800b101a..2b69a341b9a9b301840726a7b2b3d93b5e0a5cc5 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/docs/default_api.md +++ b/samples/server/petstore/rust-server/output/rust-server-test/docs/default_api.md @@ -69,7 +69,7 @@ No authorization required Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **nested_response** | [**InlineObject**](InlineObject.md)| | + **nested_response** | [**NestedResponse**](NestedResponse.md)| | ### Return type diff --git a/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs b/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs index 5fcce139cb7779df60ff7544bf5ac961c865b79e..4fe5395322aef2818ee9cd17bd4ee2b11daa7fe3 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/examples/server/server.rs @@ -131,7 +131,7 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync async fn dummy_put( &self, - nested_response: models::InlineObject, + nested_response: models::NestedResponse, context: &C) -> Result<DummyPutResponse, ApiError> { let context = context.clone(); diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs index 3cb82b64ab119e37910022b2859df383e0256538..7d233b73163a5fec9daf4e130329d0d4e8799f8d 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs @@ -536,7 +536,7 @@ impl<S, C> Api<C> for Client<S, C> where async fn dummy_put( &self, - param_nested_response: models::InlineObject, + param_nested_response: models::NestedResponse, context: &C) -> Result<DummyPutResponse, ApiError> { let mut client_service = self.client_service.clone(); diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs index 0d7e47499bd90c00d2ccdb91b4e6288a3f81da39..b801ced53b17f7865a6c8430b9298bce6bc33d83 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs @@ -89,7 +89,7 @@ pub trait Api<C: Send + Sync> { async fn dummy_put( &self, - nested_response: models::InlineObject, + nested_response: models::NestedResponse, context: &C) -> Result<DummyPutResponse, ApiError>; /// Get a file @@ -144,7 +144,7 @@ pub trait ApiNoContext<C: Send + Sync> { async fn dummy_put( &self, - nested_response: models::InlineObject, + nested_response: models::NestedResponse, ) -> Result<DummyPutResponse, ApiError>; /// Get a file @@ -222,7 +222,7 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex async fn dummy_put( &self, - nested_response: models::InlineObject, + nested_response: models::NestedResponse, ) -> Result<DummyPutResponse, ApiError> { let context = self.context().clone(); diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs index 5bb9c13acba1e6090c8ffd7d78010c2646eb3ed0..5a63b23d46ecf3dcb7eb6d8c3de7a06d77e00cf0 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs @@ -546,7 +546,7 @@ impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderVal #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] -pub struct InlineObject { +pub struct NestedResponse { #[serde(rename = "id")] pub id: String, @@ -556,19 +556,19 @@ pub struct InlineObject { } -impl InlineObject { - pub fn new(id: String, ) -> InlineObject { - InlineObject { +impl NestedResponse { + pub fn new(id: String, ) -> NestedResponse { + NestedResponse { id: id, password: None, } } } -/// Converts the InlineObject value to the Query Parameters representation (style=form, explode=false) +/// Converts the NestedResponse value to the Query Parameters representation (style=form, explode=false) /// specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde serializer -impl std::string::ToString for InlineObject { +impl std::string::ToString for NestedResponse { fn to_string(&self) -> String { let mut params: Vec<String> = vec![]; @@ -585,10 +585,10 @@ impl std::string::ToString for InlineObject { } } -/// Converts Query Parameters representation (style=form, explode=false) to a InlineObject value +/// Converts Query Parameters representation (style=form, explode=false) to a NestedResponse value /// as specified in https://swagger.io/docs/specification/serialization/ /// Should be implemented in a serde deserializer -impl std::str::FromStr for InlineObject { +impl std::str::FromStr for NestedResponse { type Err = String; fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { @@ -608,14 +608,14 @@ impl std::str::FromStr for InlineObject { while key_result.is_some() { let val = match string_iter.next() { Some(x) => x, - None => return std::result::Result::Err("Missing value while parsing InlineObject".to_string()) + None => return std::result::Result::Err("Missing value while parsing NestedResponse".to_string()) }; if let Some(key) = key_result { match key { "id" => intermediate_rep.id.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), "password" => intermediate_rep.password.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?), - _ => return std::result::Result::Err("Unexpected key while parsing InlineObject".to_string()) + _ => return std::result::Result::Err("Unexpected key while parsing NestedResponse".to_string()) } } @@ -624,41 +624,41 @@ impl std::str::FromStr for InlineObject { } // Use the intermediate representation to return the struct - std::result::Result::Ok(InlineObject { - id: intermediate_rep.id.into_iter().next().ok_or("id missing in InlineObject".to_string())?, + std::result::Result::Ok(NestedResponse { + id: intermediate_rep.id.into_iter().next().ok_or("id missing in NestedResponse".to_string())?, password: intermediate_rep.password.into_iter().next(), }) } } -// Methods for converting between header::IntoHeaderValue<InlineObject> and hyper::header::HeaderValue +// Methods for converting between header::IntoHeaderValue<NestedResponse> and hyper::header::HeaderValue #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue { +impl std::convert::TryFrom<header::IntoHeaderValue<NestedResponse>> for hyper::header::HeaderValue { type Error = String; - fn try_from(hdr_value: header::IntoHeaderValue<InlineObject>) -> std::result::Result<Self, Self::Error> { + fn try_from(hdr_value: header::IntoHeaderValue<NestedResponse>) -> std::result::Result<Self, Self::Error> { let hdr_value = hdr_value.to_string(); match hyper::header::HeaderValue::from_str(&hdr_value) { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(e) => std::result::Result::Err( - format!("Invalid header value for InlineObject - value: {} is invalid {}", + format!("Invalid header value for NestedResponse - value: {} is invalid {}", hdr_value, e)) } } } #[cfg(any(feature = "client", feature = "server"))] -impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> { +impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<NestedResponse> { type Error = String; fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> { match hdr_value.to_str() { std::result::Result::Ok(value) => { - match <InlineObject as std::str::FromStr>::from_str(value) { + match <NestedResponse as std::str::FromStr>::from_str(value) { std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)), std::result::Result::Err(err) => std::result::Result::Err( - format!("Unable to convert header value '{}' into InlineObject - {}", + format!("Unable to convert header value '{}' into NestedResponse - {}", value, err)) } }, diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs index 6fbb80b39637d21d4dd7d79bd2a3a32680fc8cb9..06401b8d870bb5987fa361de35dfd6f928e49618 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs @@ -235,7 +235,7 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where match result { Ok(body) => { let mut unused_elements = Vec::new(); - let param_nested_response: Option<models::InlineObject> = if !body.is_empty() { + let param_nested_response: Option<models::NestedResponse> = if !body.is_empty() { let deserializer = &mut serde_json::Deserializer::from_slice(&*body); match serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path);