question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[OpenApi 3] generated swagger.json doesn't respect InputFormatter

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Nov 13, 2019

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

0reactions
acdscommented, Dec 7, 2019

@RicoSuter - Thanks!

As an aside there seem to be some issues with Microsoft.AspNetCore.Mvc.Versioning.Versioning 4.1.0 a switchback to 4.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:

System.TypeLoadException: Method 'ApplyAsync' in type 'Microsoft.AspNetCore.Mvc.Routing.ApiVersionMatcherPolicy' from assembly 'Microsoft.AspNetCore.Mvc.Versioning, Version=4.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

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 the Microsoft.AspNetCore.Mvc version of the [Consumes("text/plain")] for compatibly with other libraries - it at least then eases the migration?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found