diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index f57c6f66fa3b..1d3c4cb05b5b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -22,7 +22,6 @@ import com.samskivert.mustache.Mustache.Compiler; import io.swagger.v3.core.util.Json; -import io.swagger.v3.core.util.Yaml; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.headers.Header; @@ -47,6 +46,7 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.examples.ExampleGenerator; +import org.openapitools.codegen.serializer.SerializerUtils; import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -4336,12 +4336,9 @@ public void generateJSONSpecFile(Map objs) { */ public void generateYAMLSpecFile(Map objs) { OpenAPI openAPI = (OpenAPI) objs.get("openAPI"); - if (openAPI != null) { - try { - objs.put("openapi-yaml", Yaml.mapper().writeValueAsString(openAPI)); - } catch (JsonProcessingException e) { - LOGGER.error(e.getMessage(), e); - } + String yaml = SerializerUtils.toYamlString(openAPI); + if(yaml != null) { + objs.put("openapi-yaml", yaml); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/OpenAPISerializer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/OpenAPISerializer.java new file mode 100644 index 000000000000..e0d22992e97a --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/OpenAPISerializer.java @@ -0,0 +1,49 @@ +package org.openapitools.codegen.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import io.swagger.v3.oas.models.OpenAPI; + +import java.io.IOException; +import java.util.Map.Entry; + +public class OpenAPISerializer extends JsonSerializer { + + @Override + public void serialize(OpenAPI value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + if (value != null) { + gen.writeStartObject(); + gen.writeStringField("openapi", value.getOpenapi()); + if(value.getInfo() != null) { + gen.writeObjectField("info", value.getInfo()); + } + if(value.getExternalDocs() != null) { + gen.writeObjectField("externalDocs", value.getExternalDocs()); + } + if(value.getServers() != null) { + gen.writeObjectField("servers", value.getServers()); + } + if(value.getSecurity() != null) { + gen.writeObjectField("security", value.getSecurity()); + } + if(value.getTags() != null) { + gen.writeObjectField("tags", value.getTags()); + } + if(value.getPaths() != null) { + gen.writeObjectField("paths", value.getPaths()); + } + if(value.getComponents() != null) { + gen.writeObjectField("components", value.getComponents()); + } + if(value.getExtensions() != null) { + for (Entry e : value.getExtensions().entrySet()) { + gen.writeObjectField(e.getKey(), e.getValue()); + } + } + gen.writeEndObject(); + } + } + +} diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/SerializerUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/SerializerUtils.java new file mode 100644 index 000000000000..a7044c4b9123 --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/serializer/SerializerUtils.java @@ -0,0 +1,34 @@ +package org.openapitools.codegen.serializer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import io.swagger.v3.core.util.Yaml; +import io.swagger.v3.oas.models.OpenAPI; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SerializerUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(SerializerUtils.class); + + public static String toYamlString(OpenAPI openAPI) { + if(openAPI == null) { + return null; + } + + SimpleModule module = new SimpleModule("OpenAPIModule"); + module.addSerializer(OpenAPI.class, new OpenAPISerializer()); + try { + return Yaml.mapper() + .registerModule(module) + .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) + .writeValueAsString(openAPI) + .replace("\r\n", "\n"); + } catch (JsonProcessingException e) { + LOGGER.warn("Can not create yaml content", e); + } + return null; + } +} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/serializer/SerializerUtilsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/serializer/SerializerUtilsTest.java new file mode 100644 index 000000000000..88dd873d32db --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/serializer/SerializerUtilsTest.java @@ -0,0 +1,123 @@ +package org.openapitools.codegen.serializer; + +import static org.testng.Assert.assertEquals; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.responses.ApiResponse; +import io.swagger.v3.oas.models.responses.ApiResponses; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.tags.Tag; + +import org.testng.annotations.Test; + +import java.util.Arrays; + +public class SerializerUtilsTest { + + @Test + public void testToYamlStringCompleteExample() throws Exception { + OpenAPI openAPI = new OpenAPI(); + openAPI.setInfo(new Info().title("Some title").description("Some description")); + openAPI.setExternalDocs(new ExternalDocumentation().url("http://abcdef.com").description("a-description")); + openAPI.setServers(Arrays.asList( + new Server().url("http://www.server1.com").description("first server"), + new Server().url("http://www.server2.com").description("second server") + )); + openAPI.setSecurity(Arrays.asList( + new SecurityRequirement().addList("some_auth", Arrays.asList("write", "read")) + )); + openAPI.setTags(Arrays.asList( + new Tag().name("tag1").description("some 1 description"), + new Tag().name("tag2").description("some 2 description"), + new Tag().name("tag3").description("some 3 description") + )); + openAPI.path("/ping/pong", new PathItem().get(new Operation() + .description("Some description") + .operationId("pingOp") + .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok"))))); + openAPI.components(new Components().addSchemas("SomeObject", new ObjectSchema().description("An Obj").addProperties("id", new StringSchema()))); + openAPI.addExtension("x-custom", "value1"); + openAPI.addExtension("x-other", "value2"); + + String content = SerializerUtils.toYamlString(openAPI); + String expected = "openapi: 3.0.1\n" + + "info:\n" + + " description: Some description\n" + + " title: Some title\n" + + "externalDocs:\n" + + " description: a-description\n" + + " url: http://abcdef.com\n" + + "servers:\n" + + "- description: first server\n" + + " url: http://www.server1.com\n" + + "- description: second server\n" + + " url: http://www.server2.com\n" + + "security:\n" + + "- some_auth:\n" + + " - write\n" + + " - read\n" + + "tags:\n" + + "- description: some 1 description\n" + + " name: tag1\n" + + "- description: some 2 description\n" + + " name: tag2\n" + + "- description: some 3 description\n" + + " name: tag3\n" + + "paths:\n" + + " /ping/pong:\n" + + " get:\n" + + " description: Some description\n" + + " operationId: pingOp\n" + + " responses:\n" + + " 200:\n" + + " description: Ok\n" + + "components:\n" + + " schemas:\n" + + " SomeObject:\n" + + " description: An Obj\n" + + " properties:\n" + + " id:\n" + + " type: string\n" + + " type: object\n" + + "x-other: value2\n" + + "x-custom: value1\n"; + assertEquals(content, expected); + } + + @Test + public void testToYamlStringMinimalExample() throws Exception { + OpenAPI openAPI = new OpenAPI(); + openAPI.setInfo(new Info().title("Some title")); + openAPI.setServers(Arrays.asList( + new Server().url("http://www.server1.com") + )); + openAPI.path("/ping/pong", new PathItem().get(new Operation() + .description("Some description") + .operationId("pingOp") + .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok"))))); + + String content = SerializerUtils.toYamlString(openAPI); + String expected = "openapi: 3.0.1\n" + + "info:\n" + + " title: Some title\n" + + "servers:\n" + + "- url: http://www.server1.com\n" + + "paths:\n" + + " /ping/pong:\n" + + " get:\n" + + " description: Some description\n" + + " operationId: pingOp\n" + + " responses:\n" + + " 200:\n" + + " description: Ok\n"; + assertEquals(content, expected); + } +} diff --git a/samples/server/petstore/java-inflector/.openapi-generator/VERSION b/samples/server/petstore/java-inflector/.openapi-generator/VERSION index 096bf47efe31..ad121e8340e0 100644 --- a/samples/server/petstore/java-inflector/.openapi-generator/VERSION +++ b/samples/server/petstore/java-inflector/.openapi-generator/VERSION @@ -1 +1 @@ -3.0.0-SNAPSHOT \ No newline at end of file +3.0.1-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/java-inflector/src/main/openapi/openapi.yaml b/samples/server/petstore/java-inflector/src/main/openapi/openapi.yaml index 85c967d45395..819110c3f904 100644 --- a/samples/server/petstore/java-inflector/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/java-inflector/src/main/openapi/openapi.yaml @@ -1,31 +1,27 @@ openapi: 3.0.1 info: - title: OpenAPI Petstore description: 'This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: " \' license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html + title: OpenAPI Petstore version: 1.0.0 servers: - url: http://petstore.swagger.io:80/v2 tags: -- name: pet - description: Everything about your Pets -- name: store - description: Access to Petstore orders -- name: user - description: Operations about user +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user paths: /pet: - put: - tags: - - pet - summary: Update an existing pet - operationId: updatePet + post: + operationId: addPet requestBody: - description: Pet object that needs to be added to the store content: application/json: schema: @@ -33,30 +29,24 @@ paths: application/xml: schema: $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store required: true responses: - 400: - description: Invalid ID supplied - content: {} - 404: - description: Pet not found - content: {} 405: - description: Validation exception content: {} + description: Invalid input security: - petstore_auth: - write:pets - read:pets - x-contentType: application/json - x-accepts: application/json - post: + summary: Add a new pet to the store tags: - pet - summary: Add a new pet to the store - operationId: addPet + x-contentType: application/json + x-accepts: application/json + put: + operationId: updatePet requestBody: - description: Pet object that needs to be added to the store content: application/json: schema: @@ -64,119 +54,153 @@ paths: application/xml: schema: $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store required: true responses: + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Pet not found 405: - description: Invalid input content: {} + description: Validation exception security: - petstore_auth: - write:pets - read:pets + summary: Update an existing pet + tags: + - pet x-contentType: application/json x-accepts: application/json /pet/findByStatus: get: - tags: - - pet - summary: Finds Pets by status description: Multiple status values can be provided with comma separated strings operationId: findPetsByStatus parameters: - - name: status + - description: Status values that need to be considered for filter + explode: false in: query - description: Status values that need to be considered for filter + name: status required: true - explode: false schema: - type: array items: - type: string default: available enum: - available - pending - sold + type: string + type: array + style: form responses: 200: - description: successful operation content: application/xml: schema: - type: array items: $ref: '#/components/schemas/Pet' + type: array application/json: schema: - type: array items: $ref: '#/components/schemas/Pet' + type: array + description: successful operation 400: - description: Invalid status value content: {} + description: Invalid status value security: - petstore_auth: - write:pets - read:pets + summary: Finds Pets by status + tags: + - pet x-accepts: application/json /pet/findByTags: get: - tags: - - pet - summary: Finds Pets by tags + deprecated: true description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. operationId: findPetsByTags parameters: - - name: tags + - description: Tags to filter by + explode: false in: query - description: Tags to filter by + name: tags required: true - explode: false schema: - type: array items: type: string + type: array + style: form responses: 200: - description: successful operation content: application/xml: schema: - type: array items: $ref: '#/components/schemas/Pet' + type: array application/json: schema: - type: array items: $ref: '#/components/schemas/Pet' + type: array + description: successful operation 400: - description: Invalid tag value content: {} - deprecated: true + description: Invalid tag value security: - petstore_auth: - write:pets - read:pets + summary: Finds Pets by tags + tags: + - pet x-accepts: application/json /pet/{petId}: - get: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + 400: + content: {} + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet tags: - pet - summary: Find pet by ID + x-accepts: application/json + get: description: Returns a single pet operationId: getPetById parameters: - - name: petId + - description: ID of pet to return in: path - description: ID of pet to return + name: petId required: true schema: - type: integer format: int64 + type: integer responses: 200: - description: successful operation content: application/xml: schema: @@ -184,150 +208,124 @@ paths: application/json: schema: $ref: '#/components/schemas/Pet' + description: successful operation 400: - description: Invalid ID supplied content: {} + description: Invalid ID supplied 404: - description: Pet not found content: {} + description: Pet not found security: - api_key: [] - x-accepts: application/json - post: + summary: Find pet by ID tags: - pet - summary: Updates a pet in the store with form data + x-accepts: application/json + post: operationId: updatePetWithForm parameters: - - name: petId + - description: ID of pet that needs to be updated in: path - description: ID of pet that needs to be updated + name: petId required: true schema: - type: integer format: int64 + type: integer requestBody: content: application/x-www-form-urlencoded: schema: properties: name: - type: string description: Updated name of the pet - status: type: string + status: description: Updated status of the pet + type: string responses: 405: - description: Invalid input content: {} + description: Invalid input security: - petstore_auth: - write:pets - read:pets - x-contentType: application/x-www-form-urlencoded - x-accepts: application/json - delete: + summary: Updates a pet in the store with form data tags: - pet - summary: Deletes a pet - operationId: deletePet - parameters: - - name: api_key - in: header - schema: - type: string - - name: petId - in: path - description: Pet id to delete - required: true - schema: - type: integer - format: int64 - responses: - 400: - description: Invalid pet value - content: {} - security: - - petstore_auth: - - write:pets - - read:pets + x-contentType: application/x-www-form-urlencoded x-accepts: application/json /pet/{petId}/uploadImage: post: - tags: - - pet - summary: uploads an image operationId: uploadFile parameters: - - name: petId + - description: ID of pet to update in: path - description: ID of pet to update + name: petId required: true schema: - type: integer format: int64 + type: integer requestBody: content: multipart/form-data: schema: properties: additionalMetadata: - type: string description: Additional data to pass to server - file: type: string + file: description: file to upload format: binary + type: string responses: 200: - description: successful operation content: application/json: schema: $ref: '#/components/schemas/ApiResponse' + description: successful operation security: - petstore_auth: - write:pets - read:pets + summary: uploads an image + tags: + - pet x-contentType: multipart/form-data x-accepts: application/json /store/inventory: get: - tags: - - store - summary: Returns pet inventories by status description: Returns a map of status codes to quantities operationId: getInventory responses: 200: - description: successful operation content: application/json: schema: - type: object additionalProperties: - type: integer format: int32 + type: integer + type: object + description: successful operation security: - api_key: [] + summary: Returns pet inventories by status + tags: + - store x-accepts: application/json /store/order: post: - tags: - - store - summary: Place an order for a pet operationId: placeOrder requestBody: - description: order placed for purchasing the pet content: '*/*': schema: $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet required: true responses: 200: - description: successful operation content: application/xml: schema: @@ -335,31 +333,52 @@ paths: application/json: schema: $ref: '#/components/schemas/Order' + description: successful operation 400: - description: Invalid Order content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store x-contentType: '*/*' x-accepts: application/json /store/order/{order_id}: - get: + delete: + description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - description: ID of the order that needs to be deleted + in: path + name: order_id + required: true + schema: + type: string + responses: + 400: + content: {} + description: Invalid ID supplied + 404: + content: {} + description: Order not found + summary: Delete purchase order by ID tags: - store - summary: Find purchase order by ID + x-accepts: application/json + get: description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions operationId: getOrderById parameters: - - name: order_id + - description: ID of pet that needs to be fetched in: path - description: ID of pet that needs to be fetched + name: order_id required: true schema: + format: int64 maximum: 5 minimum: 1 type: integer - format: int64 responses: 200: - description: successful operation content: application/xml: schema: @@ -367,167 +386,167 @@ paths: application/json: schema: $ref: '#/components/schemas/Order' + description: successful operation 400: - description: Invalid ID supplied content: {} + description: Invalid ID supplied 404: - description: Order not found content: {} - x-accepts: application/json - delete: + description: Order not found + summary: Find purchase order by ID tags: - store - summary: Delete purchase order by ID - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - operationId: deleteOrder - parameters: - - name: order_id - in: path - description: ID of the order that needs to be deleted - required: true - schema: - type: string - responses: - 400: - description: Invalid ID supplied - content: {} - 404: - description: Order not found - content: {} x-accepts: application/json /user: post: - tags: - - user - summary: Create user description: This can only be done by the logged in user. operationId: createUser requestBody: - description: Created user object content: '*/*': schema: $ref: '#/components/schemas/User' + description: Created user object required: true responses: default: - description: successful operation content: {} + description: successful operation + summary: Create user + tags: + - user x-contentType: '*/*' x-accepts: application/json /user/createWithArray: post: - tags: - - user - summary: Creates list of users with given input array operationId: createUsersWithArrayInput requestBody: - description: List of user object content: '*/*': schema: - type: array items: $ref: '#/components/schemas/User' + type: array + description: List of user object required: true responses: default: - description: successful operation content: {} - x-contentType: '*/*' - x-accepts: application/json - /user/createWithList: - post: + description: successful operation + summary: Creates list of users with given input array tags: - user - summary: Creates list of users with given input array + x-contentType: '*/*' + x-accepts: application/json + /user/createWithList: + post: operationId: createUsersWithListInput requestBody: - description: List of user object content: '*/*': schema: - type: array items: $ref: '#/components/schemas/User' + type: array + description: List of user object required: true responses: default: - description: successful operation content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user x-contentType: '*/*' x-accepts: application/json /user/login: get: - tags: - - user - summary: Logs user into the system operationId: loginUser parameters: - - name: username + - description: The user name for login in: query - description: The user name for login + name: username required: true schema: type: string - - name: password + - description: The password for login in clear text in: query - description: The password for login in clear text + name: password required: true schema: type: string responses: 200: + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string description: successful operation headers: X-Rate-Limit: description: calls per hour allowed by the user schema: - type: integer format: int32 + type: integer X-Expires-After: description: date in UTC when token expires schema: - type: string format: date-time - content: - application/xml: - schema: - type: string - application/json: - schema: type: string 400: - description: Invalid username/password supplied content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user x-accepts: application/json /user/logout: get: - tags: - - user - summary: Logs out current logged in user session operationId: logoutUser responses: default: - description: successful operation content: {} + description: successful operation + summary: Logs out current logged in user session + tags: + - user x-accepts: application/json /user/{username}: - get: + delete: + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - description: The name that needs to be deleted + in: path + name: username + required: true + schema: + type: string + responses: + 400: + content: {} + description: Invalid username supplied + 404: + content: {} + description: User not found + summary: Delete user tags: - user - summary: Get user by user name + x-accepts: application/json + get: operationId: getUserByName parameters: - - name: username + - description: The name that needs to be fetched. Use user1 for testing. in: path - description: The name that needs to be fetched. Use user1 for testing. + name: username required: true schema: type: string responses: 200: - description: successful operation content: application/xml: schema: @@ -535,196 +554,197 @@ paths: application/json: schema: $ref: '#/components/schemas/User' + description: successful operation 400: - description: Invalid username supplied content: {} + description: Invalid username supplied 404: - description: User not found content: {} - x-accepts: application/json - put: + description: User not found + summary: Get user by user name tags: - user - summary: Updated user + x-accepts: application/json + put: description: This can only be done by the logged in user. operationId: updateUser parameters: - - name: username + - description: name that need to be deleted in: path - description: name that need to be deleted + name: username required: true schema: type: string requestBody: - description: Updated user object content: '*/*': schema: $ref: '#/components/schemas/User' + description: Updated user object required: true responses: 400: - description: Invalid user supplied content: {} + description: Invalid user supplied 404: - description: User not found content: {} - x-contentType: '*/*' - x-accepts: application/json - delete: + description: User not found + summary: Updated user tags: - user - summary: Delete user - description: This can only be done by the logged in user. - operationId: deleteUser - parameters: - - name: username - in: path - description: The name that needs to be deleted - required: true - schema: - type: string - responses: - 400: - description: Invalid username supplied - content: {} - 404: - description: User not found - content: {} + x-contentType: '*/*' x-accepts: application/json /fake_classname_test: patch: - tags: - - fake_classname_tags 123#$%^ - summary: To test class name in snake case description: To test class name in snake case operationId: testClassname requestBody: - description: client model content: application/json: schema: $ref: '#/components/schemas/Client' + description: client model required: true responses: 200: - description: successful operation content: application/json: schema: $ref: '#/components/schemas/Client' + description: successful operation security: - api_key_query: [] + summary: To test class name in snake case + tags: + - fake_classname_tags 123#$%^ x-contentType: application/json x-accepts: application/json /fake: get: - tags: - - fake - summary: To test enum parameters description: To test enum parameters operationId: testEnumParameters parameters: - - name: enum_header_string_array + - description: Header parameter enum test (string array) + explode: false in: header - description: Header parameter enum test (string array) + name: enum_header_string_array schema: - type: array items: - type: string default: $ enum: - '>' - $ - - name: enum_header_string + type: string + type: array + style: simple + - description: Header parameter enum test (string) in: header - description: Header parameter enum test (string) + name: enum_header_string schema: - type: string default: -efg enum: - _abc - -efg - (xyz) - - name: enum_query_string_array - in: query - description: Query parameter enum test (string array) + type: string + - description: Query parameter enum test (string array) explode: false + in: query + name: enum_query_string_array schema: - type: array items: - type: string default: $ enum: - '>' - $ - - name: enum_query_string + type: string + type: array + style: form + - description: Query parameter enum test (string) in: query - description: Query parameter enum test (string) + name: enum_query_string schema: - type: string default: -efg enum: - _abc - -efg - (xyz) - - name: enum_query_integer + type: string + - description: Query parameter enum test (double) in: query - description: Query parameter enum test (double) + name: enum_query_integer schema: - type: integer - format: int32 enum: - 1 - -2 - - name: enum_query_double + format: int32 + type: integer + - description: Query parameter enum test (double) in: query - description: Query parameter enum test (double) + name: enum_query_double schema: - type: number - format: double enum: - 1.1 - -1.2 + format: double + type: number requestBody: content: application/x-www-form-urlencoded: schema: properties: enum_form_string_array: - type: array description: Form parameter enum test (string array) items: - type: string default: $ enum: - '>' - $ + type: string + type: array enum_form_string: - type: string - description: Form parameter enum test (string) default: -efg + description: Form parameter enum test (string) enum: - _abc - -efg - (xyz) + type: string responses: 400: - description: Invalid request content: {} + description: Invalid request 404: - description: Not found content: {} + description: Not found + summary: To test enum parameters + tags: + - fake x-contentType: application/x-www-form-urlencoded x-accepts: application/json - post: + patch: + description: To test "client" model + operationId: testClientModel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: client model + required: true + responses: + 200: + content: + application/json: + schema: + $ref: '#/components/schemas/Client' + description: successful operation + summary: To test "client" model tags: - fake - summary: | - Fake endpoint for testing various parameters - 假端點 - 偽のエンドポイント - 가짜 엔드 포인트 + x-contentType: application/json + x-accepts: application/json + post: description: | Fake endpoint for testing various parameters 假端點 @@ -735,254 +755,237 @@ paths: content: application/x-www-form-urlencoded: schema: - required: - - byte - - double - - number - - pattern_without_delimiter properties: integer: + description: None maximum: 100 minimum: 10 type: integer - description: None int32: + description: None + format: int32 maximum: 200 minimum: 20 type: integer - description: None - format: int32 int64: - type: integer description: None format: int64 + type: integer number: + description: None maximum: 543.2 minimum: 32.1 type: number - description: None float: - maximum: 987.6 - type: number description: None format: float + maximum: 987.6 + type: number double: + description: None + format: double maximum: 123.4 minimum: 67.8 type: number - description: None - format: double string: + description: None pattern: /[a-z]/i type: string - description: None pattern_without_delimiter: + description: None pattern: ^[A-Z].* type: string - description: None byte: - type: string description: None format: byte - binary: type: string + binary: description: None format: binary - date: type: string + date: description: None format: date - dateTime: type: string + dateTime: description: None format: date-time + type: string password: + description: None + format: password maxLength: 64 minLength: 10 type: string - description: None - format: password callback: - type: string description: None + type: string + required: + - byte + - double + - number + - pattern_without_delimiter required: true responses: 400: - description: Invalid username supplied content: {} + description: Invalid username supplied 404: - description: User not found content: {} + description: User not found security: - http_basic_test: [] - x-contentType: application/x-www-form-urlencoded - x-accepts: application/json - patch: + summary: | + Fake endpoint for testing various parameters + 假端點 + 偽のエンドポイント + 가짜 엔드 포인트 tags: - fake - summary: To test "client" model - description: To test "client" model - operationId: testClientModel - requestBody: - description: client model - content: - application/json: - schema: - $ref: '#/components/schemas/Client' - required: true - responses: - 200: - description: successful operation - content: - application/json: - schema: - $ref: '#/components/schemas/Client' - x-contentType: application/json + x-contentType: application/x-www-form-urlencoded x-accepts: application/json /fake/outer/number: post: - tags: - - fake description: Test serialization of outer number types operationId: fakeOuterNumberSerialize requestBody: - description: Input number as post body content: '*/*': schema: $ref: '#/components/schemas/OuterNumber' + description: Input number as post body required: false responses: 200: - description: Output number content: '*/*': schema: $ref: '#/components/schemas/OuterNumber' + description: Output number + tags: + - fake x-contentType: '*/*' x-accepts: '*/*' /fake/outer/string: post: - tags: - - fake description: Test serialization of outer string types operationId: fakeOuterStringSerialize requestBody: - description: Input string as post body content: '*/*': schema: $ref: '#/components/schemas/OuterString' + description: Input string as post body required: false responses: 200: - description: Output string content: '*/*': schema: $ref: '#/components/schemas/OuterString' + description: Output string + tags: + - fake x-contentType: '*/*' x-accepts: '*/*' /fake/outer/boolean: post: - tags: - - fake description: Test serialization of outer boolean types operationId: fakeOuterBooleanSerialize requestBody: - description: Input boolean as post body content: '*/*': schema: $ref: '#/components/schemas/OuterBoolean' + description: Input boolean as post body required: false responses: 200: - description: Output boolean content: '*/*': schema: $ref: '#/components/schemas/OuterBoolean' + description: Output boolean + tags: + - fake x-contentType: '*/*' x-accepts: '*/*' /fake/outer/composite: post: - tags: - - fake description: Test serialization of object with outer number type operationId: fakeOuterCompositeSerialize requestBody: - description: Input composite as post body content: '*/*': schema: $ref: '#/components/schemas/OuterComposite' + description: Input composite as post body required: false responses: 200: - description: Output composite content: '*/*': schema: $ref: '#/components/schemas/OuterComposite' + description: Output composite + tags: + - fake x-contentType: '*/*' x-accepts: '*/*' /fake/jsonFormData: get: - tags: - - fake - summary: test json serialization of form data operationId: testJsonFormData requestBody: content: application/x-www-form-urlencoded: schema: - required: - - param - - param2 properties: param: - type: string description: field1 - param2: type: string + param2: description: field2 + type: string + required: + - param + - param2 required: true responses: 200: - description: successful operation content: {} + description: successful operation + summary: test json serialization of form data + tags: + - fake x-contentType: application/x-www-form-urlencoded x-accepts: application/json /fake/inline-additionalProperties: post: - tags: - - fake - summary: test inline additionalProperties operationId: testInlineAdditionalProperties requestBody: - description: request body content: application/json: schema: - type: object additionalProperties: type: string + type: object + description: request body required: true responses: 200: - description: successful operation content: {} + description: successful operation + summary: test inline additionalProperties + tags: + - fake x-contentType: application/json x-accepts: application/json /fake/body-with-query-params: put: - tags: - - fake operationId: testBodyWithQueryParams parameters: - - name: query - in: query + - in: query + name: query required: true schema: type: string @@ -994,54 +997,64 @@ paths: required: true responses: 200: - description: Success content: {} + description: Success + tags: + - fake x-contentType: application/json x-accepts: application/json /another-fake/dummy: patch: - tags: - - $another-fake? - summary: To test special tags description: To test special tags operationId: test_special_tags requestBody: - description: client model content: application/json: schema: $ref: '#/components/schemas/Client' + description: client model required: true responses: 200: - description: successful operation content: application/json: schema: $ref: '#/components/schemas/Client' + description: successful operation + summary: To test special tags + tags: + - $another-fake? x-contentType: application/json x-accepts: application/json components: schemas: Category: - type: object + example: + name: name + id: 6 properties: id: - type: integer format: int64 + type: integer name: type: string - example: - name: name - id: 6 + type: object xml: name: Category User: - type: object + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username properties: id: - type: integer format: int64 + type: integer x-is-unique: true username: type: string @@ -1056,31 +1069,22 @@ components: phone: type: string userStatus: - type: integer description: User Status format: int32 - example: - firstName: firstName - lastName: lastName - password: password - userStatus: 6 - phone: phone - id: 0 - email: email - username: username + type: integer + type: object xml: name: User OuterNumber: type: number ArrayOfNumberOnly: - type: object properties: ArrayNumber: - type: array items: type: number - Capitalization: + type: array type: object + Capitalization: properties: smallCamel: type: string @@ -1093,240 +1097,241 @@ components: SCA_ETH_Flow_Points: type: string ATT_NAME: - type: string description: | Name of the pet - MixedPropertiesAndAdditionalPropertiesClass: + type: string type: object + MixedPropertiesAndAdditionalPropertiesClass: properties: uuid: - type: string format: uuid - dateTime: type: string + dateTime: format: date-time + type: string map: - type: object additionalProperties: $ref: '#/components/schemas/Animal' - ApiResponse: + type: object type: object + ApiResponse: + example: + code: 0 + type: type + message: message properties: code: - type: integer format: int32 + type: integer type: type: string message: type: string - example: - code: 0 - type: type - message: message - Name: - required: - - name type: object + Name: + description: Model for testing model name same as property name properties: name: - type: integer format: int32 - snake_case: type: integer + snake_case: format: int32 readOnly: true + type: integer property: type: string 123Number: - type: integer readOnly: true - description: Model for testing model name same as property name + type: integer + required: + - name + type: object xml: name: Name EnumClass: - type: string default: -efg enum: - _abc - -efg - (xyz) + type: string List: - type: object + example: + 123-list: 123-list properties: 123-list: type: string - example: - 123-list: 123-list - NumberOnly: type: object + NumberOnly: properties: JustNumber: type: number - 200_response: type: object + 200_response: + description: Model for testing model name starting with number properties: name: - type: integer format: int32 + type: integer class: type: string - description: Model for testing model name starting with number + type: object xml: name: Name Client: - type: object + example: + client: client properties: client: type: string - example: - client: client + type: object Dog: allOf: - $ref: '#/components/schemas/Animal' - - type: object - properties: + - properties: breed: type: string + type: object Enum_Test: - required: - - enum_string_required - type: object properties: enum_string: - type: string enum: - UPPER - lower - "" - enum_string_required: type: string + enum_string_required: enum: - UPPER - lower - "" + type: string enum_integer: - type: integer - format: int32 enum: - 1 - -1 + format: int32 + type: integer enum_number: - type: number - format: double enum: - 1.1 - -1.2 + format: double + type: number outerEnum: $ref: '#/components/schemas/OuterEnum' - Order: + required: + - enum_string_required type: object + Order: + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed properties: id: - type: integer format: int64 - petId: type: integer + petId: format: int64 - quantity: type: integer + quantity: format: int32 + type: integer shipDate: - type: string format: date-time - status: type: string + status: description: Order Status enum: - placed - approved - delivered + type: string complete: - type: boolean default: false - example: - petId: 6 - quantity: 1 - id: 0 - shipDate: 2000-01-23T04:56:07.000+00:00 - complete: false - status: placed + type: boolean + type: object xml: name: Order AdditionalPropertiesClass: - type: object properties: map_property: - type: object additionalProperties: type: string - map_of_map_property: type: object + map_of_map_property: additionalProperties: - type: object additionalProperties: type: string - $special[model.name]: + type: object + type: object type: object + $special[model.name]: properties: $special[property.name]: - type: integer format: int64 + type: integer + type: object xml: name: $special[model.name] Return: - type: object + description: Model for testing reserved words properties: return: - type: integer format: int32 - description: Model for testing reserved words + type: integer + type: object xml: name: Return ReadOnlyFirst: - type: object properties: bar: - type: string readOnly: true + type: string baz: type: string - ArrayOfArrayOfNumberOnly: type: object + ArrayOfArrayOfNumberOnly: properties: ArrayArrayNumber: - type: array items: - type: array items: type: number + type: array + type: array + type: object OuterEnum: - type: string enum: - placed - approved - delivered + type: string ArrayTest: - type: object properties: array_of_string: - type: array items: type: string - array_array_of_integer: type: array + array_array_of_integer: items: - type: array items: - type: integer format: int64 - array_array_of_model: + type: integer + type: array type: array + array_array_of_model: items: - type: array items: $ref: '#/components/schemas/ReadOnlyFirst' - OuterComposite: + type: array + type: array type: object + OuterComposite: + example: {} properties: my_number: $ref: '#/components/schemas/OuterNumber' @@ -1334,222 +1339,222 @@ components: $ref: '#/components/schemas/OuterString' my_boolean: $ref: '#/components/schemas/OuterBoolean' - example: {} - format_test: - required: - - byte - - date - - number - - password type: object + format_test: properties: integer: maximum: 1E+2 minimum: 1E+1 type: integer int32: + format: int32 maximum: 2E+2 minimum: 2E+1 type: integer - format: int32 int64: - type: integer format: int64 + type: integer number: maximum: 543.2 minimum: 32.1 type: number float: + format: float maximum: 987.6 minimum: 54.3 type: number - format: float double: + format: double maximum: 123.4 minimum: 67.8 type: number - format: double string: pattern: /[a-z]/i type: string byte: + format: byte pattern: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ type: string - format: byte binary: - type: string format: binary - date: type: string + date: format: date - dateTime: type: string + dateTime: format: date-time - uuid: type: string + uuid: format: uuid + type: string password: + format: password maxLength: 64 minLength: 10 type: string - format: password - EnumArrays: + required: + - byte + - date + - number + - password type: object + EnumArrays: properties: just_symbol: - type: string enum: - '>=' - $ + type: string array_enum: - type: array items: - type: string enum: - fish - crab + type: string + type: array + type: object OuterString: type: string ClassModel: - type: object + description: Model for testing model with "_class" property properties: _class: type: string - description: Model for testing model with "_class" property + type: object OuterBoolean: type: boolean x-codegen-body-parameter-name: boolean_post_body Animal: - required: - - className - type: object + discriminator: + propertyName: className properties: className: type: string color: - type: string default: red - discriminator: - propertyName: className + type: string + required: + - className + type: object Cat: allOf: - $ref: '#/components/schemas/Animal' - - type: object - properties: + - properties: declawed: type: boolean + type: object MapTest: - type: object properties: map_map_of_string: - type: object additionalProperties: - type: object additionalProperties: type: string - map_of_enum_string: + type: object type: object + map_of_enum_string: additionalProperties: - type: string enum: - UPPER - lower - Tag: + type: string + type: object type: object + Tag: + example: + name: name + id: 1 properties: id: - type: integer format: int64 + type: integer name: type: string - example: - name: name - id: 1 + type: object xml: name: Tag AnimalFarm: - type: array items: $ref: '#/components/schemas/Animal' + type: array Pet: - required: - - name - - photoUrls - type: object + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available properties: id: - type: integer format: int64 + type: integer x-is-unique: true category: $ref: '#/components/schemas/Category' name: - type: string example: doggie + type: string photoUrls: + items: + type: string type: array xml: name: photoUrl wrapped: true - items: - type: string tags: + items: + $ref: '#/components/schemas/Tag' type: array xml: name: tag wrapped: true - items: - $ref: '#/components/schemas/Tag' status: - type: string description: pet status in the store enum: - available - pending - sold - example: - photoUrls: - - photoUrls - - photoUrls - name: doggie - id: 0 - category: - name: name - id: 6 - tags: - - name: name - id: 1 - - name: name - id: 1 - status: available + type: string + required: + - name + - photoUrls + type: object xml: name: Pet hasOnlyReadOnly: - type: object properties: bar: - type: string readOnly: true - foo: type: string + foo: readOnly: true + type: string + type: object securitySchemes: petstore_auth: - type: oauth2 flows: implicit: authorizationUrl: http://petstore.swagger.io/api/oauth/dialog scopes: write:pets: modify pets in your account read:pets: read your pets + type: oauth2 http_basic_test: - type: http scheme: basic + type: http api_key: - type: apiKey - name: api_key in: header - api_key_query: + name: api_key type: apiKey - name: api_key_query + api_key_query: in: query + name: api_key_query + type: apiKey