From f52ee282155eeec6df51a0253f5484352c3d1273 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 5 Jun 2022 16:19:37 +0800 Subject: [PATCH] Fix NPE when generating examples for parameter (object) (#12538) * fix NPE when generating examples for parameter (object) * add new files --- bin/configs/aspnetcore-3.0.yaml | 2 +- bin/configs/aspnetcore-3.1.yaml | 2 +- bin/configs/aspnetcore-5.0.yaml | 2 +- bin/configs/aspnetcore-6.0.yaml | 2 +- .../languages/AbstractCSharpCodegen.java | 9 +- .../resources/3_0/aspnetcore/petstore.yaml | 754 ++++++++++++++++++ .../aspnetcore-3.0/.openapi-generator/FILES | 1 + .../Org.OpenAPITools/Controllers/FakeApi.cs | 49 ++ .../Org.OpenAPITools/Controllers/PetApi.cs | 40 +- .../Org.OpenAPITools/Controllers/StoreApi.cs | 5 +- .../Org.OpenAPITools/Controllers/UserApi.cs | 28 +- .../src/Org.OpenAPITools/Models/Category.cs | 1 + .../wwwroot/openapi-original.json | 312 +++++--- .../aspnetcore-3.1/.openapi-generator/FILES | 1 + .../Org.OpenAPITools/Controllers/FakeApi.cs | 49 ++ .../Org.OpenAPITools/Controllers/PetApi.cs | 40 +- .../Org.OpenAPITools/Controllers/StoreApi.cs | 5 +- .../Org.OpenAPITools/Controllers/UserApi.cs | 28 +- .../src/Org.OpenAPITools/Models/Category.cs | 1 + .../wwwroot/openapi-original.json | 312 +++++--- .../aspnetcore-5.0/.openapi-generator/FILES | 1 + .../Org.OpenAPITools/Controllers/FakeApi.cs | 49 ++ .../wwwroot/openapi-original.json | 23 + .../aspnetcore-6.0/.openapi-generator/FILES | 1 + .../Org.OpenAPITools/Controllers/FakeApi.cs | 49 ++ .../wwwroot/openapi-original.json | 23 + 26 files changed, 1512 insertions(+), 277 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml create mode 100644 samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs create mode 100644 samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs create mode 100644 samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs create mode 100644 samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs diff --git a/bin/configs/aspnetcore-3.0.yaml b/bin/configs/aspnetcore-3.0.yaml index 762013c1696..fcf9430d8b1 100644 --- a/bin/configs/aspnetcore-3.0.yaml +++ b/bin/configs/aspnetcore-3.0.yaml @@ -1,6 +1,6 @@ generatorName: aspnetcore outputDir: samples/server/petstore/aspnetcore-3.0 -inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0 additionalProperties: packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}' diff --git a/bin/configs/aspnetcore-3.1.yaml b/bin/configs/aspnetcore-3.1.yaml index 43d84ec3803..2859ae3629d 100644 --- a/bin/configs/aspnetcore-3.1.yaml +++ b/bin/configs/aspnetcore-3.1.yaml @@ -1,6 +1,6 @@ generatorName: aspnetcore outputDir: samples/server/petstore/aspnetcore-3.1 -inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0 additionalProperties: packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}' diff --git a/bin/configs/aspnetcore-5.0.yaml b/bin/configs/aspnetcore-5.0.yaml index b4dc00c5695..fd4e6d5fc2c 100644 --- a/bin/configs/aspnetcore-5.0.yaml +++ b/bin/configs/aspnetcore-5.0.yaml @@ -1,6 +1,6 @@ generatorName: aspnetcore outputDir: samples/server/petstore/aspnetcore-5.0 -inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0 additionalProperties: packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}' diff --git a/bin/configs/aspnetcore-6.0.yaml b/bin/configs/aspnetcore-6.0.yaml index 8207af4f8e5..a5cd2cc235b 100644 --- a/bin/configs/aspnetcore-6.0.yaml +++ b/bin/configs/aspnetcore-6.0.yaml @@ -1,6 +1,6 @@ generatorName: aspnetcore outputDir: samples/server/petstore/aspnetcore-6.0 -inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0 additionalProperties: packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}' diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index bc39b898fa8..dbc934e0bb0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -1410,8 +1410,15 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co } else { example = "new List<" + p.items.dataType + ">()"; } + } else if (Boolean.TRUE.equals(p.isModel)) { + example = "new " + p.dataType + "()"; } else if (Boolean.TRUE.equals(p.isMap)) { - example = "new Dictionary"; + if (p.items != null) { + example = "new Dictionary"; + } else { + // default to String if item is not defined + example = "new Dictionary"; + } } p.example = example; diff --git a/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml new file mode 100644 index 00000000000..183eccd90bb --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml @@ -0,0 +1,754 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /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 + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + 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 + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /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 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generated exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + 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: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + 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 + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + 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 + '404': + description: User not found + security: + - api_key: [] + /fake/parameter_example_test: + get: + tags: + - fake + summary: fake endpoint to test parameter example (object) + description: '' + operationId: fake_parameter_example_test + parameters: + - name: data + in: query + required: true + schema: + $ref: "#/components/schemas/Pet" + responses: + default: + description: successful operation +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + 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 + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string diff --git a/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES index 4dcf9d82895..8dc5fd25605 100644 --- a/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES @@ -5,6 +5,7 @@ build.sh src/Org.OpenAPITools/.gitignore src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs src/Org.OpenAPITools/Authentication/ApiAuthentication.cs +src/Org.OpenAPITools/Controllers/FakeApi.cs src/Org.OpenAPITools/Controllers/PetApi.cs src/Org.OpenAPITools/Controllers/StoreApi.cs src/Org.OpenAPITools/Controllers/UserApi.cs diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs new file mode 100644 index 00000000000..8e36c8d2be1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -0,0 +1,49 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class FakeApiController : ControllerBase + { + /// + /// fake endpoint to test parameter example (object) + /// + /// + /// successful operation + [HttpGet] + [Route("/v2/fake/parameter_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeParameterExampleTest")] + public virtual IActionResult FakeParameterExampleTest([FromQuery (Name = "data")][Required()]Pet data) + { + + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/PetApi.cs index bb9dd57afda..982c1a6011d 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/PetApi.cs @@ -31,20 +31,31 @@ namespace Org.OpenAPITools.Controllers /// /// Add a new pet to the store /// - /// Pet object that needs to be added to the store + /// Pet object that needs to be added to the store + /// successful operation /// Invalid input [HttpPost] [Route("/v2/pet")] [Consumes("application/json", "application/xml")] [ValidateModelState] [SwaggerOperation("AddPet")] - public virtual IActionResult AddPet([FromBody]Pet body) + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] + public virtual IActionResult AddPet([FromBody]Pet pet) { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Pet)); //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(405); - - throw new NotImplementedException(); + string exampleJson = null; + exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}"; + exampleJson = "\n 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Pet); + //TODO: Change the data returned + return new ObjectResult(example); } /// @@ -70,7 +81,7 @@ namespace Org.OpenAPITools.Controllers /// Finds Pets by status /// /// Multiple status values can be provided with comma separated strings - /// Status values that need to be considered for filter + /// Status values that need to be considered for filter (deprecated) /// successful operation /// Invalid status value [HttpGet] @@ -164,7 +175,8 @@ namespace Org.OpenAPITools.Controllers /// /// Update an existing pet /// - /// Pet object that needs to be added to the store + /// Pet object that needs to be added to the store + /// successful operation /// Invalid ID supplied /// Pet not found /// Validation exception @@ -173,17 +185,27 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json", "application/xml")] [ValidateModelState] [SwaggerOperation("UpdatePet")] - public virtual IActionResult UpdatePet([FromBody]Pet body) + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] + public virtual IActionResult UpdatePet([FromBody]Pet pet) { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Pet)); //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(400); //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(404); //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(405); - - throw new NotImplementedException(); + string exampleJson = null; + exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}"; + exampleJson = "\n 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Pet); + //TODO: Change the data returned + return new ObjectResult(example); } /// diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/StoreApi.cs index bbb05474e15..2077313f7dd 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/StoreApi.cs @@ -111,15 +111,16 @@ namespace Org.OpenAPITools.Controllers /// /// Place an order for a pet /// - /// order placed for purchasing the pet + /// order placed for purchasing the pet /// successful operation /// Invalid Order [HttpPost] [Route("/v2/store/order")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("PlaceOrder")] [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] - public virtual IActionResult PlaceOrder([FromBody]Order body) + public virtual IActionResult PlaceOrder([FromBody]Order order) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/UserApi.cs index 6e4c255f4a1..6d7094c81a9 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/UserApi.cs @@ -32,13 +32,15 @@ namespace Org.OpenAPITools.Controllers /// Create user /// /// This can only be done by the logged in user. - /// Created user object + /// Created user object /// successful operation [HttpPost] [Route("/v2/user")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUser")] - public virtual IActionResult CreateUser([FromBody]User body) + public virtual IActionResult CreateUser([FromBody]User user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -50,13 +52,15 @@ namespace Org.OpenAPITools.Controllers /// /// Creates list of users with given input array /// - /// List of user object + /// List of user object /// successful operation [HttpPost] [Route("/v2/user/createWithArray")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUsersWithArrayInput")] - public virtual IActionResult CreateUsersWithArrayInput([FromBody]List body) + public virtual IActionResult CreateUsersWithArrayInput([FromBody]List user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -68,13 +72,15 @@ namespace Org.OpenAPITools.Controllers /// /// Creates list of users with given input array /// - /// List of user object + /// List of user object /// successful operation [HttpPost] [Route("/v2/user/createWithList")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUsersWithListInput")] - public virtual IActionResult CreateUsersWithListInput([FromBody]List body) + public virtual IActionResult CreateUsersWithListInput([FromBody]List user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -92,6 +98,7 @@ namespace Org.OpenAPITools.Controllers /// User not found [HttpDelete] [Route("/v2/user/{username}")] + [Authorize(Policy = "api_key")] [ValidateModelState] [SwaggerOperation("DeleteUser")] public virtual IActionResult DeleteUser([FromRoute (Name = "username")][Required]string username) @@ -149,7 +156,7 @@ namespace Org.OpenAPITools.Controllers [ValidateModelState] [SwaggerOperation("LoginUser")] [SwaggerResponse(statusCode: 200, type: typeof(string), description: "successful operation")] - public virtual IActionResult LoginUser([FromQuery (Name = "username")][Required()]string username, [FromQuery (Name = "password")][Required()]string password) + public virtual IActionResult LoginUser([FromQuery (Name = "username")][Required()][RegularExpression("^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")]string username, [FromQuery (Name = "password")][Required()]string password) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -171,6 +178,7 @@ namespace Org.OpenAPITools.Controllers /// successful operation [HttpGet] [Route("/v2/user/logout")] + [Authorize(Policy = "api_key")] [ValidateModelState] [SwaggerOperation("LogoutUser")] public virtual IActionResult LogoutUser() @@ -187,14 +195,16 @@ namespace Org.OpenAPITools.Controllers /// /// This can only be done by the logged in user. /// name that need to be deleted - /// Updated user object + /// Updated user object /// Invalid user supplied /// User not found [HttpPut] [Route("/v2/user/{username}")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("UpdateUser")] - public virtual IActionResult UpdateUser([FromRoute (Name = "username")][Required]string username, [FromBody]User body) + public virtual IActionResult UpdateUser([FromRoute (Name = "username")][Required]string username, [FromBody]User user) { //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/Category.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/Category.cs index 810f5beacc2..0d63dc9d7e6 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/Category.cs +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/Category.cs @@ -35,6 +35,7 @@ namespace Org.OpenAPITools.Models /// /// Gets or Sets Name /// + [RegularExpression("^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")] [DataMember(Name="name", EmitDefaultValue=false)] public string Name { get; set; } diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index 323c86f1829..257358c0608 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -1,5 +1,5 @@ { - "openapi" : "3.0.1", + "openapi" : "3.0.0", "info" : { "description" : "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.", "license" : { @@ -9,6 +9,10 @@ "title" : "OpenAPI Petstore", "version" : "1.0.0" }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, "servers" : [ { "url" : "http://petstore.swagger.io/v2" } ], @@ -25,26 +29,28 @@ "paths" : { "/pet" : { "post" : { + "description" : "", "operationId" : "addPet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -52,38 +58,37 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Add a new pet to the store", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] }, "put" : { + "description" : "", "operationId" : "updatePet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" }, "405" : { - "content" : { }, "description" : "Validation exception" } }, @@ -91,8 +96,7 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Update an existing pet", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] } }, "/pet/findByStatus" : { @@ -100,6 +104,7 @@ "description" : "Multiple status values can be provided with comma separated strings", "operationId" : "findPetsByStatus", "parameters" : [ { + "deprecated" : true, "description" : "Status values that need to be considered for filter", "explode" : false, "in" : "query", @@ -138,12 +143,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid status value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by status", "tags" : [ "pet" ] @@ -191,12 +195,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid tag value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by tags", "tags" : [ "pet" ] @@ -204,26 +207,31 @@ }, "/pet/{petId}" : { "delete" : { + "description" : "", "operationId" : "deletePet", "parameters" : [ { + "explode" : false, "in" : "header", "name" : "api_key", + "required" : false, "schema" : { "type" : "string" - } + }, + "style" : "simple" }, { "description" : "Pet id to delete", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid pet value" } }, @@ -238,13 +246,15 @@ "operationId" : "getPetById", "parameters" : [ { "description" : "ID of pet to return", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -263,11 +273,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" } }, @@ -278,16 +286,19 @@ "tags" : [ "pet" ] }, "post" : { + "description" : "", "operationId" : "updatePetWithForm", "parameters" : [ { "description" : "ID of pet that needs to be updated", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { @@ -300,7 +311,6 @@ }, "responses" : { "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -313,16 +323,19 @@ }, "/pet/{petId}/uploadImage" : { "post" : { + "description" : "", "operationId" : "uploadFile", "parameters" : [ { "description" : "ID of pet to update", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { @@ -381,10 +394,11 @@ }, "/store/order" : { "post" : { + "description" : "", "operationId" : "placeOrder", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/Order" } @@ -410,13 +424,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid Order" } }, "summary" : "Place an order for a pet", - "tags" : [ "store" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "store" ] } }, "/store/order/{orderId}" : { @@ -425,20 +437,20 @@ "operationId" : "deleteOrder", "parameters" : [ { "description" : "ID of the order that needs to be deleted", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -450,6 +462,7 @@ "operationId" : "getOrderById", "parameters" : [ { "description" : "ID of pet that needs to be fetched", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, @@ -458,7 +471,8 @@ "maximum" : 5, "minimum" : 1, "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -477,11 +491,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -495,7 +507,7 @@ "operationId" : "createUser", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -506,90 +518,79 @@ }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Create user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithArray" : { "post" : { + "description" : "", "operationId" : "createUsersWithArrayInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithList" : { "post" : { + "description" : "", "operationId" : "createUsersWithListInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/login" : { "get" : { + "description" : "", "operationId" : "loginUser", "parameters" : [ { "description" : "The user name for login", + "explode" : true, "in" : "query", "name" : "username", "required" : true, "schema" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" - } + }, + "style" : "form" }, { "description" : "The password for login in clear text", + "explode" : true, "in" : "query", "name" : "password", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "form" } ], "responses" : { "200" : { @@ -607,24 +608,36 @@ }, "description" : "successful operation", "headers" : { + "Set-Cookie" : { + "description" : "Cookie authentication key for use with the `api_key` apiKey authentication.", + "explode" : false, + "schema" : { + "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", + "type" : "string" + }, + "style" : "simple" + }, "X-Rate-Limit" : { "description" : "calls per hour allowed by the user", + "explode" : false, "schema" : { "format" : "int32", "type" : "integer" - } + }, + "style" : "simple" }, "X-Expires-After" : { "description" : "date in UTC when token expires", + "explode" : false, "schema" : { "format" : "date-time", "type" : "string" - } + }, + "style" : "simple" } } }, "400" : { - "content" : { }, "description" : "Invalid username/password supplied" } }, @@ -634,13 +647,16 @@ }, "/user/logout" : { "get" : { + "description" : "", "operationId" : "logoutUser", "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Logs out current logged in user session", "tags" : [ "user" ] } @@ -651,36 +667,42 @@ "operationId" : "deleteUser", "parameters" : [ { "description" : "The name that needs to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Delete user", "tags" : [ "user" ] }, "get" : { + "description" : "", "operationId" : "getUserByName", "parameters" : [ { "description" : "The name that needs to be fetched. Use user1 for testing.", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -699,11 +721,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, @@ -715,16 +735,18 @@ "operationId" : "updateUser", "parameters" : [ { "description" : "name that need to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -735,21 +757,76 @@ }, "responses" : { "400" : { - "content" : { }, "description" : "Invalid user supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Updated user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] + } + }, + "/fake/parameter_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_parameter_example_test", + "parameters" : [ { + "explode" : true, + "in" : "query", + "name" : "data", + "required" : true, + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "style" : "form" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "summary" : "fake endpoint to test parameter example (object)", + "tags" : [ "fake" ] } } }, "components" : { + "requestBodies" : { + "UserArray" : { + "content" : { + "application/json" : { + "schema" : { + "items" : { + "$ref" : "#/components/schemas/User" + }, + "type" : "array" + } + } + }, + "description" : "List of user object", + "required" : true + }, + "Pet" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "Pet object that needs to be added to the store", + "required" : true + } + }, "schemas" : { "Order" : { "description" : "An order for a pets from the pet store", @@ -806,6 +883,7 @@ "type" : "integer" }, "name" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" } }, @@ -935,6 +1013,7 @@ } }, "status" : { + "deprecated" : true, "description" : "pet status in the store", "enum" : [ "available", "pending", "sold" ], "type" : "string" @@ -979,7 +1058,8 @@ "description" : "Updated status of the pet", "type" : "string" } - } + }, + "type" : "object" }, "uploadFile_request" : { "properties" : { @@ -992,7 +1072,8 @@ "format" : "binary", "type" : "string" } - } + }, + "type" : "object" } }, "securitySchemes" : { @@ -1014,6 +1095,5 @@ "type" : "apiKey" } } - }, - "x-original-swagger-version" : "2.0" + } } diff --git a/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES index 4dcf9d82895..8dc5fd25605 100644 --- a/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES @@ -5,6 +5,7 @@ build.sh src/Org.OpenAPITools/.gitignore src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs src/Org.OpenAPITools/Authentication/ApiAuthentication.cs +src/Org.OpenAPITools/Controllers/FakeApi.cs src/Org.OpenAPITools/Controllers/PetApi.cs src/Org.OpenAPITools/Controllers/StoreApi.cs src/Org.OpenAPITools/Controllers/UserApi.cs diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs new file mode 100644 index 00000000000..8e36c8d2be1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -0,0 +1,49 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class FakeApiController : ControllerBase + { + /// + /// fake endpoint to test parameter example (object) + /// + /// + /// successful operation + [HttpGet] + [Route("/v2/fake/parameter_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeParameterExampleTest")] + public virtual IActionResult FakeParameterExampleTest([FromQuery (Name = "data")][Required()]Pet data) + { + + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/PetApi.cs index bb9dd57afda..982c1a6011d 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/PetApi.cs @@ -31,20 +31,31 @@ namespace Org.OpenAPITools.Controllers /// /// Add a new pet to the store /// - /// Pet object that needs to be added to the store + /// Pet object that needs to be added to the store + /// successful operation /// Invalid input [HttpPost] [Route("/v2/pet")] [Consumes("application/json", "application/xml")] [ValidateModelState] [SwaggerOperation("AddPet")] - public virtual IActionResult AddPet([FromBody]Pet body) + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] + public virtual IActionResult AddPet([FromBody]Pet pet) { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Pet)); //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(405); - - throw new NotImplementedException(); + string exampleJson = null; + exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}"; + exampleJson = "\n 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Pet); + //TODO: Change the data returned + return new ObjectResult(example); } /// @@ -70,7 +81,7 @@ namespace Org.OpenAPITools.Controllers /// Finds Pets by status /// /// Multiple status values can be provided with comma separated strings - /// Status values that need to be considered for filter + /// Status values that need to be considered for filter (deprecated) /// successful operation /// Invalid status value [HttpGet] @@ -164,7 +175,8 @@ namespace Org.OpenAPITools.Controllers /// /// Update an existing pet /// - /// Pet object that needs to be added to the store + /// Pet object that needs to be added to the store + /// successful operation /// Invalid ID supplied /// Pet not found /// Validation exception @@ -173,17 +185,27 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json", "application/xml")] [ValidateModelState] [SwaggerOperation("UpdatePet")] - public virtual IActionResult UpdatePet([FromBody]Pet body) + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] + public virtual IActionResult UpdatePet([FromBody]Pet pet) { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Pet)); //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(400); //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(404); //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(405); - - throw new NotImplementedException(); + string exampleJson = null; + exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}"; + exampleJson = "\n 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Pet); + //TODO: Change the data returned + return new ObjectResult(example); } /// diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/StoreApi.cs index bbb05474e15..2077313f7dd 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/StoreApi.cs @@ -111,15 +111,16 @@ namespace Org.OpenAPITools.Controllers /// /// Place an order for a pet /// - /// order placed for purchasing the pet + /// order placed for purchasing the pet /// successful operation /// Invalid Order [HttpPost] [Route("/v2/store/order")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("PlaceOrder")] [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] - public virtual IActionResult PlaceOrder([FromBody]Order body) + public virtual IActionResult PlaceOrder([FromBody]Order order) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/UserApi.cs index 6e4c255f4a1..6d7094c81a9 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/UserApi.cs @@ -32,13 +32,15 @@ namespace Org.OpenAPITools.Controllers /// Create user /// /// This can only be done by the logged in user. - /// Created user object + /// Created user object /// successful operation [HttpPost] [Route("/v2/user")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUser")] - public virtual IActionResult CreateUser([FromBody]User body) + public virtual IActionResult CreateUser([FromBody]User user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -50,13 +52,15 @@ namespace Org.OpenAPITools.Controllers /// /// Creates list of users with given input array /// - /// List of user object + /// List of user object /// successful operation [HttpPost] [Route("/v2/user/createWithArray")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUsersWithArrayInput")] - public virtual IActionResult CreateUsersWithArrayInput([FromBody]List body) + public virtual IActionResult CreateUsersWithArrayInput([FromBody]List user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -68,13 +72,15 @@ namespace Org.OpenAPITools.Controllers /// /// Creates list of users with given input array /// - /// List of user object + /// List of user object /// successful operation [HttpPost] [Route("/v2/user/createWithList")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("CreateUsersWithListInput")] - public virtual IActionResult CreateUsersWithListInput([FromBody]List body) + public virtual IActionResult CreateUsersWithListInput([FromBody]List user) { //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -92,6 +98,7 @@ namespace Org.OpenAPITools.Controllers /// User not found [HttpDelete] [Route("/v2/user/{username}")] + [Authorize(Policy = "api_key")] [ValidateModelState] [SwaggerOperation("DeleteUser")] public virtual IActionResult DeleteUser([FromRoute (Name = "username")][Required]string username) @@ -149,7 +156,7 @@ namespace Org.OpenAPITools.Controllers [ValidateModelState] [SwaggerOperation("LoginUser")] [SwaggerResponse(statusCode: 200, type: typeof(string), description: "successful operation")] - public virtual IActionResult LoginUser([FromQuery (Name = "username")][Required()]string username, [FromQuery (Name = "password")][Required()]string password) + public virtual IActionResult LoginUser([FromQuery (Name = "username")][Required()][RegularExpression("^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")]string username, [FromQuery (Name = "password")][Required()]string password) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -171,6 +178,7 @@ namespace Org.OpenAPITools.Controllers /// successful operation [HttpGet] [Route("/v2/user/logout")] + [Authorize(Policy = "api_key")] [ValidateModelState] [SwaggerOperation("LogoutUser")] public virtual IActionResult LogoutUser() @@ -187,14 +195,16 @@ namespace Org.OpenAPITools.Controllers /// /// This can only be done by the logged in user. /// name that need to be deleted - /// Updated user object + /// Updated user object /// Invalid user supplied /// User not found [HttpPut] [Route("/v2/user/{username}")] + [Authorize(Policy = "api_key")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("UpdateUser")] - public virtual IActionResult UpdateUser([FromRoute (Name = "username")][Required]string username, [FromBody]User body) + public virtual IActionResult UpdateUser([FromRoute (Name = "username")][Required]string username, [FromBody]User user) { //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/Category.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/Category.cs index 810f5beacc2..0d63dc9d7e6 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/Category.cs +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/Category.cs @@ -35,6 +35,7 @@ namespace Org.OpenAPITools.Models /// /// Gets or Sets Name /// + [RegularExpression("^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")] [DataMember(Name="name", EmitDefaultValue=false)] public string Name { get; set; } diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json index 323c86f1829..257358c0608 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -1,5 +1,5 @@ { - "openapi" : "3.0.1", + "openapi" : "3.0.0", "info" : { "description" : "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.", "license" : { @@ -9,6 +9,10 @@ "title" : "OpenAPI Petstore", "version" : "1.0.0" }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, "servers" : [ { "url" : "http://petstore.swagger.io/v2" } ], @@ -25,26 +29,28 @@ "paths" : { "/pet" : { "post" : { + "description" : "", "operationId" : "addPet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -52,38 +58,37 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Add a new pet to the store", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] }, "put" : { + "description" : "", "operationId" : "updatePet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } - }, - "description" : "Pet object that needs to be added to the store", - "required" : true + "$ref" : "#/components/requestBodies/Pet" }, "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "successful operation" + }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" }, "405" : { - "content" : { }, "description" : "Validation exception" } }, @@ -91,8 +96,7 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Update an existing pet", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] } }, "/pet/findByStatus" : { @@ -100,6 +104,7 @@ "description" : "Multiple status values can be provided with comma separated strings", "operationId" : "findPetsByStatus", "parameters" : [ { + "deprecated" : true, "description" : "Status values that need to be considered for filter", "explode" : false, "in" : "query", @@ -138,12 +143,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid status value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by status", "tags" : [ "pet" ] @@ -191,12 +195,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid tag value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by tags", "tags" : [ "pet" ] @@ -204,26 +207,31 @@ }, "/pet/{petId}" : { "delete" : { + "description" : "", "operationId" : "deletePet", "parameters" : [ { + "explode" : false, "in" : "header", "name" : "api_key", + "required" : false, "schema" : { "type" : "string" - } + }, + "style" : "simple" }, { "description" : "Pet id to delete", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid pet value" } }, @@ -238,13 +246,15 @@ "operationId" : "getPetById", "parameters" : [ { "description" : "ID of pet to return", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -263,11 +273,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" } }, @@ -278,16 +286,19 @@ "tags" : [ "pet" ] }, "post" : { + "description" : "", "operationId" : "updatePetWithForm", "parameters" : [ { "description" : "ID of pet that needs to be updated", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { @@ -300,7 +311,6 @@ }, "responses" : { "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -313,16 +323,19 @@ }, "/pet/{petId}/uploadImage" : { "post" : { + "description" : "", "operationId" : "uploadFile", "parameters" : [ { "description" : "ID of pet to update", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { @@ -381,10 +394,11 @@ }, "/store/order" : { "post" : { + "description" : "", "operationId" : "placeOrder", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/Order" } @@ -410,13 +424,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid Order" } }, "summary" : "Place an order for a pet", - "tags" : [ "store" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "store" ] } }, "/store/order/{orderId}" : { @@ -425,20 +437,20 @@ "operationId" : "deleteOrder", "parameters" : [ { "description" : "ID of the order that needs to be deleted", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -450,6 +462,7 @@ "operationId" : "getOrderById", "parameters" : [ { "description" : "ID of pet that needs to be fetched", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, @@ -458,7 +471,8 @@ "maximum" : 5, "minimum" : 1, "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -477,11 +491,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -495,7 +507,7 @@ "operationId" : "createUser", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -506,90 +518,79 @@ }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Create user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithArray" : { "post" : { + "description" : "", "operationId" : "createUsersWithArrayInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithList" : { "post" : { + "description" : "", "operationId" : "createUsersWithListInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/login" : { "get" : { + "description" : "", "operationId" : "loginUser", "parameters" : [ { "description" : "The user name for login", + "explode" : true, "in" : "query", "name" : "username", "required" : true, "schema" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" - } + }, + "style" : "form" }, { "description" : "The password for login in clear text", + "explode" : true, "in" : "query", "name" : "password", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "form" } ], "responses" : { "200" : { @@ -607,24 +608,36 @@ }, "description" : "successful operation", "headers" : { + "Set-Cookie" : { + "description" : "Cookie authentication key for use with the `api_key` apiKey authentication.", + "explode" : false, + "schema" : { + "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", + "type" : "string" + }, + "style" : "simple" + }, "X-Rate-Limit" : { "description" : "calls per hour allowed by the user", + "explode" : false, "schema" : { "format" : "int32", "type" : "integer" - } + }, + "style" : "simple" }, "X-Expires-After" : { "description" : "date in UTC when token expires", + "explode" : false, "schema" : { "format" : "date-time", "type" : "string" - } + }, + "style" : "simple" } } }, "400" : { - "content" : { }, "description" : "Invalid username/password supplied" } }, @@ -634,13 +647,16 @@ }, "/user/logout" : { "get" : { + "description" : "", "operationId" : "logoutUser", "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Logs out current logged in user session", "tags" : [ "user" ] } @@ -651,36 +667,42 @@ "operationId" : "deleteUser", "parameters" : [ { "description" : "The name that needs to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Delete user", "tags" : [ "user" ] }, "get" : { + "description" : "", "operationId" : "getUserByName", "parameters" : [ { "description" : "The name that needs to be fetched. Use user1 for testing.", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -699,11 +721,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, @@ -715,16 +735,18 @@ "operationId" : "updateUser", "parameters" : [ { "description" : "name that need to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -735,21 +757,76 @@ }, "responses" : { "400" : { - "content" : { }, "description" : "Invalid user supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "api_key" : [ ] + } ], "summary" : "Updated user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] + } + }, + "/fake/parameter_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_parameter_example_test", + "parameters" : [ { + "explode" : true, + "in" : "query", + "name" : "data", + "required" : true, + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "style" : "form" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "summary" : "fake endpoint to test parameter example (object)", + "tags" : [ "fake" ] } } }, "components" : { + "requestBodies" : { + "UserArray" : { + "content" : { + "application/json" : { + "schema" : { + "items" : { + "$ref" : "#/components/schemas/User" + }, + "type" : "array" + } + } + }, + "description" : "List of user object", + "required" : true + }, + "Pet" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "Pet object that needs to be added to the store", + "required" : true + } + }, "schemas" : { "Order" : { "description" : "An order for a pets from the pet store", @@ -806,6 +883,7 @@ "type" : "integer" }, "name" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" } }, @@ -935,6 +1013,7 @@ } }, "status" : { + "deprecated" : true, "description" : "pet status in the store", "enum" : [ "available", "pending", "sold" ], "type" : "string" @@ -979,7 +1058,8 @@ "description" : "Updated status of the pet", "type" : "string" } - } + }, + "type" : "object" }, "uploadFile_request" : { "properties" : { @@ -992,7 +1072,8 @@ "format" : "binary", "type" : "string" } - } + }, + "type" : "object" } }, "securitySchemes" : { @@ -1014,6 +1095,5 @@ "type" : "apiKey" } } - }, - "x-original-swagger-version" : "2.0" + } } diff --git a/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES index 4dcf9d82895..8dc5fd25605 100644 --- a/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES @@ -5,6 +5,7 @@ build.sh src/Org.OpenAPITools/.gitignore src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs src/Org.OpenAPITools/Authentication/ApiAuthentication.cs +src/Org.OpenAPITools/Controllers/FakeApi.cs src/Org.OpenAPITools/Controllers/PetApi.cs src/Org.OpenAPITools/Controllers/StoreApi.cs src/Org.OpenAPITools/Controllers/UserApi.cs diff --git a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs new file mode 100644 index 00000000000..8e36c8d2be1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -0,0 +1,49 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class FakeApiController : ControllerBase + { + /// + /// fake endpoint to test parameter example (object) + /// + /// + /// successful operation + [HttpGet] + [Route("/v2/fake/parameter_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeParameterExampleTest")] + public virtual IActionResult FakeParameterExampleTest([FromQuery (Name = "data")][Required()]Pet data) + { + + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index 86077d64b02..257358c0608 100644 --- a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -769,6 +769,29 @@ "summary" : "Updated user", "tags" : [ "user" ] } + }, + "/fake/parameter_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_parameter_example_test", + "parameters" : [ { + "explode" : true, + "in" : "query", + "name" : "data", + "required" : true, + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "style" : "form" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "summary" : "fake endpoint to test parameter example (object)", + "tags" : [ "fake" ] + } } }, "components" : { diff --git a/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES index 4563db30a52..9e47b8916d5 100644 --- a/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES @@ -5,6 +5,7 @@ build.sh src/Org.OpenAPITools/.gitignore src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs src/Org.OpenAPITools/Authentication/ApiAuthentication.cs +src/Org.OpenAPITools/Controllers/FakeApi.cs src/Org.OpenAPITools/Controllers/PetApi.cs src/Org.OpenAPITools/Controllers/StoreApi.cs src/Org.OpenAPITools/Controllers/UserApi.cs diff --git a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs new file mode 100644 index 00000000000..8e36c8d2be1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -0,0 +1,49 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class FakeApiController : ControllerBase + { + /// + /// fake endpoint to test parameter example (object) + /// + /// + /// successful operation + [HttpGet] + [Route("/v2/fake/parameter_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeParameterExampleTest")] + public virtual IActionResult FakeParameterExampleTest([FromQuery (Name = "data")][Required()]Pet data) + { + + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index 86077d64b02..257358c0608 100644 --- a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -769,6 +769,29 @@ "summary" : "Updated user", "tags" : [ "user" ] } + }, + "/fake/parameter_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_parameter_example_test", + "parameters" : [ { + "explode" : true, + "in" : "query", + "name" : "data", + "required" : true, + "schema" : { + "$ref" : "#/components/schemas/Pet" + }, + "style" : "form" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "summary" : "fake endpoint to test parameter example (object)", + "tags" : [ "fake" ] + } } }, "components" : {