How do I set "Parameter content type" using Swashbuckle?
13,567
Use the [Produces]
and [Consumes]
attributes. Swashbuckle (and others, like NSwag) will convert them into the appropriate Swagger documentation.
The [Consumes]
attribute's constructor's first parameter is String contentType
:
public ConsumesAttribute ( string contentType, params string[] otherContentTypes );
Like so:
[ApiController]
public class MyController : ControllBase
{
[HttpPost( "/foo/bar" )]
[Consumes( MediaTypeNames.Application.Json )] // "application/json"
[Produces( typeof(MyResponseDto) ) ]
public async Task<IActionResult> Post( [FromBody] MyRequestDto dto )
{
//
}
}
Author by
lonix
Updated on June 14, 2022Comments
-
lonix almost 2 years
My swagger ui shows "Parameter content type" with various entries:
"application/json-patch+json"
,"text/json"
,"application/json"
, and"application/*+json"
.I only want
"application/json"
.There's a similar unsolved issue on the repo, which uses this visual (older ui, but same idea):
Is there some way to set this?
Swashbuckle.AspNetCore
version4.0.1
Swashbuckle.AspNetCore.Filters
version4.5.5