Consumes and Produces attributes are ignored in ASP .NET Core Web API
See original GitHub issueI’m using NSwag.AspNetCore v13.0.6 (latest version as of this writing), and NSwag seem to be ignoring the Consumes
and Produces
attributes.
Am I missing anything?
[HttpPost("/api/stuff")]
[Consumes("text/plain")]
[Produces("text/plain")]
public IActionResult PostStuff()
{
return Ok();
}
Relates to #420
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Unable to get ASP.NET web api to consume an ...
1 Answer. I was able to resolve this situation by creating a custom "Consume" attribute using the MVC code as a template and...
Read more >Format response data in ASP.NET Core Web API
Learn how to format response data in ASP.NET Core Web API. ... use a specified format, ignoring a client's request for a different...
Read more >Create web APIs with ASP.NET Core
Attributes. The Microsoft.AspNetCore.Mvc namespace provides attributes that can be used to configure the behavior of web API controllers and ...
Read more >Understanding Produces And Consumes Attribute In MVC 6
Produces and Consumes Attributes are newly introduced in MVC 6 (ASP.NET Core) to control the content negotiation.
Read more >Untitled
Consumes and Produces attributes are ignored in ASP .NET Core Web API ... AspNetCore.Docs/index.md at main - GitHub WebConsumesAttribute 类 (Microsoft.
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 am still having this issue. Since this issue claims that everything is correct, I investigated further.
I have an operation that is supposed to consume application/octet-stream, and I have a matching input processor.
I registered this input processor and the ASP.NET Core API explorer lists the operation correctly. Even NSwag seems to pick up the Consumes attribute. I created a Document Processor and put a breakpoint in the Process method.
Looking at
DocumentProcessorContext.Document.Operations[0].Operation
, I see that theActualConsumes
property contains “application/octect-stream”, but theRequestBody.Content
dictionary only contains an “application/json” content.So, in conclusion, NSwag does ignore the consumes attribute and seems to always assume application/json.
the same problem on my side, ConsumesAttribute completely ignored.