domaindrivendev / Swashbuckle.WebApi

Seamlessly adds a swagger to WebApi projects!
BSD 3-Clause "New" or "Revised" License
3.07k stars 679 forks source link

Missing charset=utf-8 in the produces definition #1245

Open xlegalles opened 6 years ago

xlegalles commented 6 years ago

VERSION:

2.3.0 and ASP.NET Core 2.1

STEPS TO REPRODUCE:

We describe an API using attributes. For example

[HttpGet("{fieldId:guid}", Name = "FieldById")]
[ProducesResponseType(typeof(FieldDtoWithHierarchy), (int)HttpStatusCode.OK)]
public Task<IActionResult> GetField(Guid fieldId){...}

Which provides the typical result in the swagger.json file:

"produces": [
          "text/plain",
          "application/json",
          "text/json"
        ]

But there is no way to specify a response of type "application/json; charset=utf-8" which is btw exactly what a browser will receive from the previous method. So there is a slight difference between a real answer and the swagger description.

I've tried adding a [Produces("application/json;charset=utf-8")] at the controller level or at the method level but it does not change anything. I don't find any way to add the charset definition into the swagger file.

You may think that this is a detail but it is not when we test the API using PACT:

Thank you for your help

Kiechlus commented 10 months ago

Is there any news on this? This produces big problems on our side because the Openapi Generator v6 packages check the content type exactly:

Update We got our problem fixed by simply allowing both content types: [Produces(System.Net.Mime.MediaTypeNames.Application.Json, "application/json; charset=utf-8")]