Operation now returns StatusCode Stubs as well (#7098)

* Operation now returns StatusCode Stubs as well

* Updated mustache file to use comments

return StatusCode(..) is now commented out.

* Change default(..) to not escape the type

default(dataType) --> default(&dataType)

* Return IActionResult no matter what..

* Updated formatting

* Ran bin/aspnetcore-petstore-server.sh
This commit is contained in:
Max K 2017-12-05 15:14:00 +01:00 committed by William Cheng
parent 5f9f6e5c9b
commit 645d71ed3b
7 changed files with 167 additions and 31 deletions

View File

@ -33,11 +33,21 @@ namespace {{packageName}}.Controllers
[ValidateModelState]
[SwaggerOperation("{{operationId}}")]{{#responses}}{{#returnType}}
[SwaggerResponse({{code}}, typeof({{&returnType}}), "{{message}}")]{{/returnType}}{{/responses}}
public virtual {{#returnType}}IActionResult{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{ {{#returnType}}
public virtual IActionResult {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{ {{#responses}}
{{#dataType}}
//TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode({{code}}, default({{&dataType}}));
{{/dataType}}
{{^dataType}}
//TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode({{code}});
{{/dataType}}{{/responses}}
{{#returnType}}
string exampleJson = null;
{{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMapContainer}}{{>mapReturn}}{{/isMapContainer}}{{^isMapContainer}}{{>objectReturn}}{{/isMapContainer}}{{/isListCollection}}
{{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}}
//TODO: Change the data returned
return new ObjectResult(example);{{/returnType}}{{^returnType}}
throw new NotImplementedException();{{/returnType}}
}

View File

@ -33,22 +33,26 @@ namespace IO.Swagger.Controllers
/// <summary>
/// Add a new pet to the store
/// </summary>
/// <remarks></remarks>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <response code="405">Invalid input</response>
[HttpPost]
[Route("/v2/pet")]
[ValidateModelState]
[SwaggerOperation("AddPet")]
public virtual void AddPet([FromBody]Pet body)
public virtual IActionResult AddPet([FromBody]Pet body)
{
//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();
}
/// <summary>
/// Deletes a pet
/// </summary>
/// <remarks></remarks>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"></param>
/// <response code="400">Invalid pet value</response>
@ -56,8 +60,12 @@ namespace IO.Swagger.Controllers
[Route("/v2/pet/{petId}")]
[ValidateModelState]
[SwaggerOperation("DeletePet")]
public virtual void DeletePet([FromRoute]long? petId, [FromHeader]string apiKey)
public virtual IActionResult DeletePet([FromRoute]long? petId, [FromHeader]string apiKey)
{
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);
throw new NotImplementedException();
}
@ -76,11 +84,18 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(400, typeof(List<Pet>), "Invalid status value")]
public virtual IActionResult FindPetsByStatus([FromQuery]List<string> status)
{
//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(List<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);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
: default(List<Pet>);
//TODO: Change the data returned
return new ObjectResult(example);
}
@ -99,11 +114,18 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(400, typeof(List<Pet>), "Invalid tag value")]
public virtual IActionResult FindPetsByTags([FromQuery]List<string> tags)
{
//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(List<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);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
: default(List<Pet>);
//TODO: Change the data returned
return new ObjectResult(example);
}
@ -124,18 +146,28 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(404, typeof(Pet), "Pet not found")]
public virtual IActionResult GetPetById([FromRoute]long? petId)
{
//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);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<Pet>(exampleJson)
: default(Pet);
//TODO: Change the data returned
return new ObjectResult(example);
}
/// <summary>
/// Update an existing pet
/// </summary>
/// <remarks></remarks>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <response code="400">Invalid ID supplied</response>
/// <response code="404">Pet not found</response>
@ -144,15 +176,25 @@ namespace IO.Swagger.Controllers
[Route("/v2/pet")]
[ValidateModelState]
[SwaggerOperation("UpdatePet")]
public virtual void UpdatePet([FromBody]Pet body)
public virtual IActionResult UpdatePet([FromBody]Pet body)
{
//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();
}
/// <summary>
/// Updates a pet in the store with form data
/// </summary>
/// <remarks></remarks>
/// <param name="petId">ID of pet that needs to be updated</param>
/// <param name="name">Updated name of the pet</param>
/// <param name="status">Updated status of the pet</param>
@ -161,15 +203,19 @@ namespace IO.Swagger.Controllers
[Route("/v2/pet/{petId}")]
[ValidateModelState]
[SwaggerOperation("UpdatePetWithForm")]
public virtual void UpdatePetWithForm([FromRoute]long? petId, [FromForm]string name, [FromForm]string status)
public virtual IActionResult UpdatePetWithForm([FromRoute]long? petId, [FromForm]string name, [FromForm]string status)
{
//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();
}
/// <summary>
/// uploads an image
/// </summary>
/// <remarks></remarks>
/// <param name="petId">ID of pet to update</param>
/// <param name="additionalMetadata">Additional data to pass to server</param>
/// <param name="file">file to upload</param>
@ -181,11 +227,15 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(200, typeof(ApiResponse), "successful operation")]
public virtual IActionResult UploadFile([FromRoute]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(..), ...
// return StatusCode(200, default(ApiResponse));
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson)
: default(ApiResponse);
//TODO: Change the data returned
return new ObjectResult(example);
}
}

View File

@ -41,8 +41,15 @@ namespace IO.Swagger.Controllers
[Route("/v2/store/order/{orderId}")]
[ValidateModelState]
[SwaggerOperation("DeleteOrder")]
public virtual void DeleteOrder([FromRoute]string orderId)
public virtual IActionResult DeleteOrder([FromRoute]string orderId)
{
//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);
throw new NotImplementedException();
}
@ -58,11 +65,15 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(200, typeof(Dictionary<string, int?>), "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(..), ...
// return StatusCode(200, default(Dictionary<string, int?>));
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<Dictionary<string, int?>>(exampleJson)
: default(Dictionary<string, int?>);
//TODO: Change the data returned
return new ObjectResult(example);
}
@ -83,18 +94,28 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(404, typeof(Order), "Order not found")]
public virtual IActionResult GetOrderById([FromRoute]long? orderId)
{
//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(Order));
//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);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<Order>(exampleJson)
: default(Order);
//TODO: Change the data returned
return new ObjectResult(example);
}
/// <summary>
/// Place an order for a pet
/// </summary>
/// <remarks></remarks>
/// <param name="body">order placed for purchasing the pet</param>
/// <response code="200">successful operation</response>
/// <response code="400">Invalid Order</response>
@ -106,11 +127,18 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(400, typeof(Order), "Invalid Order")]
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(..), ...
// return StatusCode(200, default(Order));
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<Order>(exampleJson)
: default(Order);
//TODO: Change the data returned
return new ObjectResult(example);
}
}

View File

@ -40,38 +40,50 @@ namespace IO.Swagger.Controllers
[Route("/v2/user")]
[ValidateModelState]
[SwaggerOperation("CreateUser")]
public virtual void CreateUser([FromBody]User body)
public virtual IActionResult CreateUser([FromBody]User body)
{
//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();
}
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks></remarks>
/// <param name="body">List of user object</param>
/// <response code="0">successful operation</response>
[HttpPost]
[Route("/v2/user/createWithArray")]
[ValidateModelState]
[SwaggerOperation("CreateUsersWithArrayInput")]
public virtual void CreateUsersWithArrayInput([FromBody]List<User> body)
public virtual IActionResult CreateUsersWithArrayInput([FromBody]List<User> body)
{
//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();
}
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks></remarks>
/// <param name="body">List of user object</param>
/// <response code="0">successful operation</response>
[HttpPost]
[Route("/v2/user/createWithList")]
[ValidateModelState]
[SwaggerOperation("CreateUsersWithListInput")]
public virtual void CreateUsersWithListInput([FromBody]List<User> body)
public virtual IActionResult CreateUsersWithListInput([FromBody]List<User> body)
{
//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();
}
@ -86,15 +98,22 @@ namespace IO.Swagger.Controllers
[Route("/v2/user/{username}")]
[ValidateModelState]
[SwaggerOperation("DeleteUser")]
public virtual void DeleteUser([FromRoute]string username)
public virtual IActionResult DeleteUser([FromRoute]string username)
{
//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);
throw new NotImplementedException();
}
/// <summary>
/// Get user by user name
/// </summary>
/// <remarks></remarks>
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
/// <response code="200">successful operation</response>
/// <response code="400">Invalid username supplied</response>
@ -108,18 +127,28 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(404, typeof(User), "User not found")]
public virtual IActionResult GetUserByName([FromRoute]string username)
{
//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(User));
//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);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<User>(exampleJson)
: default(User);
//TODO: Change the data returned
return new ObjectResult(example);
}
/// <summary>
/// Logs user into the system
/// </summary>
/// <remarks></remarks>
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
/// <response code="200">successful operation</response>
@ -132,25 +161,36 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(400, typeof(string), "Invalid username/password supplied")]
public virtual IActionResult LoginUser([FromQuery]string username, [FromQuery]string password)
{
//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(string));
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);
string exampleJson = null;
var example = exampleJson != null
? JsonConvert.DeserializeObject<string>(exampleJson)
: default(string);
//TODO: Change the data returned
return new ObjectResult(example);
}
/// <summary>
/// Logs out current logged in user session
/// </summary>
/// <remarks></remarks>
/// <response code="0">successful operation</response>
[HttpGet]
[Route("/v2/user/logout")]
[ValidateModelState]
[SwaggerOperation("LogoutUser")]
public virtual void LogoutUser()
public virtual IActionResult LogoutUser()
{
//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();
}
@ -166,8 +206,15 @@ namespace IO.Swagger.Controllers
[Route("/v2/user/{username}")]
[ValidateModelState]
[SwaggerOperation("UpdateUser")]
public virtual void UpdateUser([FromRoute]string username, [FromBody]User body)
public virtual IActionResult UpdateUser([FromRoute]string username, [FromBody]User body)
{
//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);
throw new NotImplementedException();
}
}

View File

@ -60,19 +60,19 @@ namespace IO.Swagger.Models
/// Enum PlacedEnum for "placed"
/// </summary>
[EnumMember(Value = "placed")]
PlacedEnum,
PlacedEnum = 1,
/// <summary>
/// Enum ApprovedEnum for "approved"
/// </summary>
[EnumMember(Value = "approved")]
ApprovedEnum,
ApprovedEnum = 2,
/// <summary>
/// Enum DeliveredEnum for "delivered"
/// </summary>
[EnumMember(Value = "delivered")]
DeliveredEnum
DeliveredEnum = 3
}
/// <summary>

View File

@ -68,19 +68,19 @@ namespace IO.Swagger.Models
/// Enum AvailableEnum for "available"
/// </summary>
[EnumMember(Value = "available")]
AvailableEnum,
AvailableEnum = 1,
/// <summary>
/// Enum PendingEnum for "pending"
/// </summary>
[EnumMember(Value = "pending")]
PendingEnum,
PendingEnum = 2,
/// <summary>
/// Enum SoldEnum for "sold"
/// </summary>
[EnumMember(Value = "sold")]
SoldEnum
SoldEnum = 3
}
/// <summary>

View File

@ -22,7 +22,8 @@
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.EntityFrameworkCore": "1.0.0",
"Swashbuckle.AspNetCore": "1.0.0-rc3",
"Newtonsoft.Json": "9.0.1"
"Newtonsoft.Json": "10.0.3",
"JsonSubTypes": "1.1.3"
},
"tools": {