0

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,

Helen
  • 87,344
  • 17
  • 243
  • 314
Julio Pereira
  • 70
  • 1
  • 7
  • 1
    [Does `[Consumes( MediaTypeNames.Application.Json )]` useful to you?](https://stackoverflow.com/questions/55978068/how-do-i-set-parameter-content-type-using-swashbuckle) – Jason Pan Mar 18 '22 at 04:30
  • Hello Json, many thanks for your suggestion. At first I thought the content-types were wrong, while they were just a fallback list of formats. That attribute setting narrows down the content-types to the ones specified. – Julio Pereira Mar 18 '22 at 08:25

1 Answers1

1

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()
{
     
}
Jason Pan
  • 15,263
  • 1
  • 14
  • 29