Swashbuckle would not generate swagger.json with an output of "UserCreateResponse", how do you fix this?
[HttpPost]
public async Task<IActionResult> Update([FromBody]UserCreate Request)
{
UserCreateResponse response = new UserCreateResponse();
//do something here
// returns UserCreateResponse with http status code 200
return Ok(response);
}
You can't do this, because its not going to return the http status code, 200,400,401 etc
[HttpPost]
public async Task<UserCreateResponse> Update([FromBody]UserCreate Request)
{
UserCreateResponse response = new UserCreateResponse();
//do something here
// returns UserCreateResponse
return response;
}
From V6.0 onwards SwaggerResponse
isn't supported anymore, see here.
Another variant is the use of the SwaggerResponse
attribute, which also allows to provide an additional description:
[SwaggerResponse(HttpStatusCode.OK, "UserDTO", typeof(UserDTO))]
public async Task<IHttpActionResult> Get([FromODataUri] int key)
{
var result = await UserRepo.GetAsync(key);
...
return Ok(result);
}
which produces output as shown here:
It's also possible to omit the type to document other status codes which do not return an entity:
[SwaggerResponse(HttpStatusCode.NotFound, "no data found")]
[SwaggerResponse(HttpStatusCode.BadRequest, "requiered request headers not found")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With