From 1541d96b185d0a1097594c3269aa956199e3609d Mon Sep 17 00:00:00 2001 From: Max K Date: Wed, 13 Dec 2017 04:59:45 +0100 Subject: [PATCH] Updated SwaggerResponse Attributes so they use the actual dataType instead of the common returnType (#7096) * Moved SwaggerResponse Attributes to use the respective dataType instead of the common returnType. * Updated examples --- .../main/resources/aspnetcore/controller.mustache | 4 ++-- .../aspnetcore/src/IO.Swagger/Controllers/PetApi.cs | 12 ++++-------- .../src/IO.Swagger/Controllers/StoreApi.cs | 9 +++------ .../aspnetcore/src/IO.Swagger/Controllers/UserApi.cs | 7 ++----- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache index ea447e946f9..55e64d7cacf 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache @@ -32,8 +32,8 @@ namespace {{packageName}}.Controllers [{{httpMethod}}] [Route("{{{basePathWithoutHost}}}{{{path}}}")] [ValidateModelState] - [SwaggerOperation("{{operationId}}")]{{#responses}}{{#returnType}} - [SwaggerResponse({{code}}, typeof({{&returnType}}), "{{message}}")]{{/returnType}}{{/responses}} + [SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}} + [SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{^dataType}}{{/dataType}}{{/responses}} public virtual IActionResult {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#responses}} {{#dataType}} diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs index 8752b12ca55..918c99987ca 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs @@ -81,8 +81,7 @@ namespace IO.Swagger.Controllers [Route("/v2/pet/findByStatus")] [ValidateModelState] [SwaggerOperation("FindPetsByStatus")] - [SwaggerResponse(200, typeof(List), "successful operation")] - [SwaggerResponse(400, typeof(List), "Invalid status value")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "successful operation")] public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List status) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -113,8 +112,7 @@ namespace IO.Swagger.Controllers [Route("/v2/pet/findByTags")] [ValidateModelState] [SwaggerOperation("FindPetsByTags")] - [SwaggerResponse(200, typeof(List), "successful operation")] - [SwaggerResponse(400, typeof(List), "Invalid tag value")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "successful operation")] public virtual IActionResult FindPetsByTags([FromQuery][Required()]List tags) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -146,9 +144,7 @@ namespace IO.Swagger.Controllers [Route("/v2/pet/{petId}")] [ValidateModelState] [SwaggerOperation("GetPetById")] - [SwaggerResponse(200, typeof(Pet), "successful operation")] - [SwaggerResponse(400, typeof(Pet), "Invalid ID supplied")] - [SwaggerResponse(404, typeof(Pet), "Pet not found")] + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] public virtual IActionResult GetPetById([FromRoute][Required]long? petId) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -231,7 +227,7 @@ namespace IO.Swagger.Controllers [Route("/v2/pet/{petId}/uploadImage")] [ValidateModelState] [SwaggerOperation("UploadFile")] - [SwaggerResponse(200, typeof(ApiResponse), "successful operation")] + [SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")] public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file) { //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/src/IO.Swagger/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs index b65e65e8c72..178f7397c5c 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs @@ -63,7 +63,7 @@ namespace IO.Swagger.Controllers [Route("/v2/store/inventory")] [ValidateModelState] [SwaggerOperation("GetInventory")] - [SwaggerResponse(200, typeof(Dictionary), "successful operation")] + [SwaggerResponse(statusCode: 200, type: typeof(Dictionary), description: "successful operation")] public virtual IActionResult GetInventory() { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -91,9 +91,7 @@ namespace IO.Swagger.Controllers [Route("/v2/store/order/{orderId}")] [ValidateModelState] [SwaggerOperation("GetOrderById")] - [SwaggerResponse(200, typeof(Order), "successful operation")] - [SwaggerResponse(400, typeof(Order), "Invalid ID supplied")] - [SwaggerResponse(404, typeof(Order), "Order not found")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]long? orderId) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -127,8 +125,7 @@ namespace IO.Swagger.Controllers [Route("/v2/store/order")] [ValidateModelState] [SwaggerOperation("PlaceOrder")] - [SwaggerResponse(200, typeof(Order), "successful operation")] - [SwaggerResponse(400, typeof(Order), "Invalid Order")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] public virtual IActionResult PlaceOrder([FromBody]Order body) { //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/src/IO.Swagger/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs index b8415fcc9a2..0b3d4dc374f 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs @@ -123,9 +123,7 @@ namespace IO.Swagger.Controllers [Route("/v2/user/{username}")] [ValidateModelState] [SwaggerOperation("GetUserByName")] - [SwaggerResponse(200, typeof(User), "successful operation")] - [SwaggerResponse(400, typeof(User), "Invalid username supplied")] - [SwaggerResponse(404, typeof(User), "User not found")] + [SwaggerResponse(statusCode: 200, type: typeof(User), description: "successful operation")] public virtual IActionResult GetUserByName([FromRoute][Required]string username) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... @@ -160,8 +158,7 @@ namespace IO.Swagger.Controllers [Route("/v2/user/login")] [ValidateModelState] [SwaggerOperation("LoginUser")] - [SwaggerResponse(200, typeof(string), "successful operation")] - [SwaggerResponse(400, typeof(string), "Invalid username/password supplied")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "successful operation")] public virtual IActionResult LoginUser([FromQuery][Required()]string username, [FromQuery][Required()]string password) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...