nswag v13 can't handle text\plain and string response
See original GitHub issueThis is very old issue and it was fixed in v12, but appears again in v13: #701
Controller’s attributes:
[Produces("text/plain")]
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseMessage), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(ErrorResponseMessage), (int)HttpStatusCode.NotFound)]
Swagger:
"get": {
"tags": [ "Binary" ],
"summary": "Download binary as base64 string.",
"operationId": "DownloadBinaryAsBase64",
"consumes": [],
"produces": [ "text/plain" ],
"parameters": [
{
"name": "binaryId",
"in": "path",
"description": "Id of binary to fetch.",
"required": true,
"type": "string",
"format": "guid"
}
],
"responses": {
"200": {
"description": "Content downloaded.",
"schema": { "type": "string" }
},
"400": {
"description": "Request contains wrong data.",
"schema": { "$ref": "#/definitions/ErrorResponseMessage" }
},
"404": {
"description": "Not Found",
"schema": { "$ref": "#/definitions/ErrorResponseMessage" }
}
}
Produced code (part):
var status_ = ((int)response_.StatusCode).ToString();
if (status_ == "200")
{
var objectResponse_ = await ReadObjectResponseAsync<string>(response_, headers_).ConfigureAwait(false);
return objectResponse_.Object;
}
ReadObjectResponseAsync always try to deserialize the string and of course it will fail.
Revert to v12.2.5 fix the issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:62 (17 by maintainers)
Top Results From Across the Web
nswag v13 can't handle text\plain and string response -
This is very old issue and it was fixed in v12, but appears again in v13: #701. Controller's attributes: [Produces("text/plain")] ...
Read more >NSwag generated client still serializes string for text/plain ...
I'm using NSwag to generate a c# client based on a swagger.json. My main problem is that the generated client's function for calling...
Read more >OpenAPI/Swagger not deserializing strings correctly
This works fine in SwaggerUI and lists several media types for the response: text/plain, application/json, and text/json.
Read more >Get started with NSwag and ASP.NET Core
Learn how to use NSwag to generate documentation and help pages for an ASP.NET Core web API.
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & ...
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
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
Any idea when this patch will be released?
Done.
Yes, tested with 13.16.1.