I'm trying to create a controller in an AspNetCore 3.1 API. c #, with the help of "NSwag.AspNetCore" 13.1.3. The purpose of this controller is to receive and return plain text (not json).
The controller code looks like this:
[HttpPost]
[Route("api/BodyTypes/JsonPlainBody")]
[Consumes("text/plain")]
[Produces("text/plain")]
public string PlainStringBody([FromBody] string content)
{
return content;
}
Excerpt from the "swagger.json" file that describes this service:
...
"/api/BodyTypes/JsonPlainBody": {
"post": {
"tags": [
"Acessórios - Operações diversas"
],
"operationId": "Acessorios_PlainStringBody",
"requestBody": {
"x-name": "content",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
...
The representation of this controller in SwaggerUI, does not allow me to select the content type "text / plain", consequently, generating the http request in the wrong format, causing the server to return an error related to the data format (415 - Error: Unsupported Media Type):
When testing this same controller in Postman, editing using the content type for "text / plain", everything works as expected:
Any help is most welcome.