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
This commit is contained in:
Max K 2017-12-13 04:59:45 +01:00 committed by William Cheng
parent 4dbb44b061
commit 1541d96b18
4 changed files with 11 additions and 21 deletions

View File

@ -32,8 +32,8 @@ namespace {{packageName}}.Controllers
[{{httpMethod}}] [{{httpMethod}}]
[Route("{{{basePathWithoutHost}}}{{{path}}}")] [Route("{{{basePathWithoutHost}}}{{{path}}}")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("{{operationId}}")]{{#responses}}{{#returnType}} [SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}}
[SwaggerResponse({{code}}, typeof({{&returnType}}), "{{message}}")]{{/returnType}}{{/responses}} [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}}) public virtual IActionResult {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{ {{#responses}} { {{#responses}}
{{#dataType}} {{#dataType}}

View File

@ -81,8 +81,7 @@ namespace IO.Swagger.Controllers
[Route("/v2/pet/findByStatus")] [Route("/v2/pet/findByStatus")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("FindPetsByStatus")] [SwaggerOperation("FindPetsByStatus")]
[SwaggerResponse(200, typeof(List<Pet>), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
[SwaggerResponse(400, typeof(List<Pet>), "Invalid status value")]
public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string> status) public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string> status)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //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")] [Route("/v2/pet/findByTags")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("FindPetsByTags")] [SwaggerOperation("FindPetsByTags")]
[SwaggerResponse(200, typeof(List<Pet>), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
[SwaggerResponse(400, typeof(List<Pet>), "Invalid tag value")]
public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string> tags) public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string> tags)
{ {
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //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}")] [Route("/v2/pet/{petId}")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetPetById")] [SwaggerOperation("GetPetById")]
[SwaggerResponse(200, typeof(Pet), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")]
[SwaggerResponse(400, typeof(Pet), "Invalid ID supplied")]
[SwaggerResponse(404, typeof(Pet), "Pet not found")]
public virtual IActionResult GetPetById([FromRoute][Required]long? petId) 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(..), ... //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")] [Route("/v2/pet/{petId}/uploadImage")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("UploadFile")] [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) 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(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...

View File

@ -63,7 +63,7 @@ namespace IO.Swagger.Controllers
[Route("/v2/store/inventory")] [Route("/v2/store/inventory")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetInventory")] [SwaggerOperation("GetInventory")]
[SwaggerResponse(200, typeof(Dictionary<string, int?>), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(Dictionary<string, int?>), description: "successful operation")]
public virtual IActionResult GetInventory() 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(..), ... //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}")] [Route("/v2/store/order/{orderId}")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetOrderById")] [SwaggerOperation("GetOrderById")]
[SwaggerResponse(200, typeof(Order), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")]
[SwaggerResponse(400, typeof(Order), "Invalid ID supplied")]
[SwaggerResponse(404, typeof(Order), "Order not found")]
public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]long? orderId) 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(..), ... //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")] [Route("/v2/store/order")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("PlaceOrder")] [SwaggerOperation("PlaceOrder")]
[SwaggerResponse(200, typeof(Order), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")]
[SwaggerResponse(400, typeof(Order), "Invalid Order")]
public virtual IActionResult PlaceOrder([FromBody]Order body) 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(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...

View File

@ -123,9 +123,7 @@ namespace IO.Swagger.Controllers
[Route("/v2/user/{username}")] [Route("/v2/user/{username}")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetUserByName")] [SwaggerOperation("GetUserByName")]
[SwaggerResponse(200, typeof(User), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(User), description: "successful operation")]
[SwaggerResponse(400, typeof(User), "Invalid username supplied")]
[SwaggerResponse(404, typeof(User), "User not found")]
public virtual IActionResult GetUserByName([FromRoute][Required]string username) 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(..), ... //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")] [Route("/v2/user/login")]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("LoginUser")] [SwaggerOperation("LoginUser")]
[SwaggerResponse(200, typeof(string), "successful operation")] [SwaggerResponse(statusCode: 200, type: typeof(string), description: "successful operation")]
[SwaggerResponse(400, typeof(string), "Invalid username/password supplied")]
public virtual IActionResult LoginUser([FromQuery][Required()]string username, [FromQuery][Required()]string password) 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(..), ... //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...