Julio Pereira
Julio Pereira

Reputation: 100

Why is SwaggerGen generating content type named as "application/*+json"

I have an application that uses Swashbuckle.AspNetCore" Version="5.6.3".

The implementation in startup is straight forward, the services inject the generator: services.AddSwaggerGen();

And the app builder activates swagger in standard manner: app.UseSwagger();

Why is it then that I find "application/*+json" as content type for certain post operations in the definition?. This is an issue as it breaks certain services that re-use the openapi definition.

Is there any known way of avoiding this and using plain "application/json" content type in the definition?.

Thanks,

Upvotes: 1

Views: 882

Answers (1)

Jason Pan
Jason Pan

Reputation: 22029

If we just want use plain application/json content type, you can add attribute like : [Consumes( MediaTypeNames.Application.Json )]. If we want to use other plain, we can click the drop-down box.

Sample code:

[HttpGet]
[Consumes(MediaTypeNames.Application.Json )]
public async Task<IActionResult> Post()
{
     
}

Upvotes: 1

Related Questions