Default swagger content-type for Response
See original GitHub issueSince latest 2-3 releases (I don’t know exactly which one) I notice that the default content-type selected on the swagger HTML dropdown menu for the method reponse, is not "application/json"
but "text/plain"
.
If I don’t change it everytime before clicking on Try button, I get an error because no content-type negotiation for responses is allowed in my application.
I think that "application/json"
should be the right default value, but anyway is it possible to set the default content-type for response in Swagger configuration to avoid changing it everytime?
This is my actual configuration
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(config =>
{
// HTTP 406 when not supported format is requested by client
config.ReturnHttpNotAcceptable = true;
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
// Add FluentValidation
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<MachineCreateModelValidator>());
// Add API versioning
services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ReportApiVersions = true;
});
}
The HTML result
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Describing Responses
Response Media Types · HTTP Status Codes · Response Body · Response That Returns a File · anyOf, oneOf · Empty Response Body...
Read more >How do I set or remove the Default Response Content ...
The default response content type when using SwashBuckle is text/plain . How can I change the default to be application/json or even remove ......
Read more >Swashbuckle Pro Tips for ASP.NET Web API – Content Types
And those four content types are the default response ones – application/json , text/json , application/xml and text/xml .
Read more >Custom Response - HTML, Stream, File, others - FastAPI
If you want to override the response from inside of the function but at the same time document the "media type" in OpenAPI,...
Read more >Solved: Swagger compliance assertion with content type dif...
The swagger compliance assertion has a too strict validation on the content type. Currently only the content type application/xml and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I temporary solved the problem by simply putting the
Produces
attribute on the top of all of my controllers, like this:UPDATE 2019/07/23
I forgot to mention that if you are using a common base class for all your Controllers, you can just put the
Produces
attribute only on the base class.@RSuter But I don’t know if it is really necessary, since you said that should come automatically. Any news?
@js-lee0624
Just a note for users reading the suggestion, from NSwag v13, there was a refactoring, so the method is called
AddOpenApiDocument
instead ofAddSwaggerDocument
.