[OpenApi 3] generated swagger.json doesn't respect InputFormatter
See original GitHub issueWhat I want to achieve:
Read a POST body into a raw string in my API method. For that, I’m using an InputFormatter that can transform text/plain request into a string parameter.
Observed results:
The API works fine, but the swagger.json generates a content-type of application/json, which makes swagger-ui send the request with this Content-Type header (which cannot be parsed).
When I set my SchemaType to Swagger2
, the Swagger UI can handle the API correctly.
Expected result:
Swagger UI should be able to read raw strings from the input, and the C# client should be able to pass a raw string as the POST request body.
Sample code :
https://github.com/jeremyVignelles/TestNSwagNetCoreApp/tree/feature/openapi-raw-inputformatter
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Open-generator-cli problems, or Swagger/OpenApi ...
So, I tried java -jar openapi-generator-cli-3.3.4.jar generate -g elm -i swagger.json. instead. The code is slightly different, for example, ...
Read more >Include format in swagger generated from C# web api
1 Answer 1 ... There is no such thing as string($int32) in the OpenAPI specification. It should be either string if it really...
Read more >OpenAPI Specification - Version 3.0.3
An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML...
Read more >ReadMe: OpenAPI and Swagger for API Documentation
In this guide, we explain Swagger and OpenAPI, how to create an OpenAPI ... Definition: The document, in either Swagger or OpenAPI format, ......
Read more >Get started with Swashbuckle and ASP.NET Core
By default, Swashbuckle generates and exposes Swagger JSON in version 3.0 of the specification—officially called the OpenAPI Specification.
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 think you need this: https://github.com/RicoSuter/NSwag/pull/2353
You can copy it into your proj and use it
I hope to merge/finish the pr soon
@RicoSuter - Thanks!
As an aside there seem to be some issues with
Microsoft.AspNetCore.Mvc.Versioning.Versioning 4.1.0
a switchback to4.0.0
resolved the issue - but tend to upgrade across the board when I can - albeit staying 3.0 compatible packages just now so avoiding 3.1 dependencies) Error:Whist using the
[OpenApiBodyParameter("text/plain")]
works…it would be more preferable (and ignorance on my part of the implications) if NSwag were somehow able to leverage theMicrosoft.AspNetCore.Mvc
version of the[Consumes("text/plain")]
for compatibly with other libraries - it at least then eases the migration?