Closed MassimoC closed 5 years ago
Isn't there a built-in way to achieve this?
I'm wondering why a custom attribute has been created to achieve this instead of using the ConsumesAttribute
and ProducesAttribute
Having your operations decorated with these attributes should also affect the Swagger documentation.
You could for instance have this on the GetPlayer
method:
[SwaggerResponse((int)HttpStatusCode.OK, "Player data object")]
[SwaggerResponse((int)HttpStatusCode.NotFound, "Player not found")]
[SwaggerResponse((int)HttpStatusCode.InternalServerError, "API is not available")]
[Produces("application/json")]
public async Task<IActionResult> GetPlayer(int id) {}
or this on the CreatePlayer
method:
[SwaggerResponse((int)HttpStatusCode.Created, "Player has been created. New playes is returned along with the link to the new resource (Location header)")]
[SwaggerResponse((int)HttpStatusCode.BadRequest, "Invalid request")]
[SwaggerResponse((int)HttpStatusCode.InternalServerError, "API is not available")]
[Consumes("application/json", "text/json")]
[Produces("application/json")]
public async Task<IActionResult> Create(NewPlayerDto player) {}
Because I am completely missed the built-in attributes. Will drop the custom attribute and introduce these ones
content-negotiation moved to level 2
As part of #19 SwaggerConsumesProduces attribute introduced to have more control on the produced/consumed media types