Open munafk opened 6 years ago
Have you tried the new AspNetCoreToSwaggerGenerator (i.e. UseSwaggerUiWithApiExplorer()), I think this generator processes the [Consumes] attributes and adds more produces mime types?
I tried, but I am not getting any operations listed. Is there a concrete example you can point me to?
Hard luck. It does not handle Consumes attributes.
Just a nasty workaround in a case if you have to accept XML as a request body
.UseSwagger(config =>
{
config.PostProcess = (document, request) =>
{
foreach (SwaggerOperationDescription operationDescription in document.Operations)
{
string[] actualConsumes = operationDescription.Operation.ActualConsumes.ToArray();
const string xmlMediaType = "application/xml";
const string jsonMediaType = "application/json";
if (actualConsumes.Any(a => a.Equals(xmlMediaType, StringComparison.OrdinalIgnoreCase)))
{
SwaggerOperation operation = operationDescription.Operation;
IDictionary<string, OpenApiMediaType> content = operation.RequestBody.Content;
OpenApiMediaType openApiMediaType = content[jsonMediaType];
// content.Remove(jsonMediaType);
content.Add(xmlMediaType, openApiMediaType);
}
}
};
});
I still can't get the actualConsumes with xml, did I miss anything?
I'm currently facing the same issue. I use NSwag 13.15.5 version. any updates on the solution to this problem ?
I am using Swagger 11.17.15 version. I get only application/json as request and response types in Swagger UI. However I need application/xml instead. I tried adding [Consumes] on top of the controller, still no result. Please help!