How to use html markup in the "description" attribute of swagger.json file?

Viewed 1159

Environment:

NSwag.AspNetCore (12.2.5);

Microsoft.NETCore.App (3.0.0);

Language: C#

I am marking the header of some controllers, with the following expression:

///<summary>Controller description</summary>
/// <remarks>
/// <details>
///    <summary>Expand here</summary>
///    <p>Hidden content</p>
///</details>
/// </remarks>
[HttpGet]
[SwaggerTags("NF-e (Nota Fiscal Eletrônica)")]
[Route("api/testes/")]
public string tests()
{
    return "tests";
}

The intention would be to get the swagger specification file with the following content:

"paths": {
...
    "/api/testes": {
      "get": {
        "tags": [
          "NF-e (Nota Fiscal Eletrônica)"
        ],
        "summary": "Controller description",
        "description": "<details><summary>Expand here</summary><p>Hidden content</p></details>"
        "operationId": "NFe_tests",
        "parameters": [
          {
            "name": "token",
            "in": "header",
            "description": "Chave de acesso à API",
            "schema": {
              "type": "string"
            },
            "default": "980fb195fdecc68069deb67f987573837cf67e0e"
          }
        ],
        "responses": {
          "200": {
            "x-nullable": true,
            "description": "",
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
...

To have on the swagger GUI the following behavior:

enter image description here

However, what I get is as follows:

"paths": {
...
    "/api/testes": {
      "get": {
        "tags": [
          "NF-e (Nota Fiscal Eletrônica)"
        ],
        "summary": "Controller description",
        "description": "   Expand here\n   Hiden content\n            ",
        "operationId": "NFe_tests",
        "parameters": [
          {
            "name": "token",
            "in": "header",
            "description": "Chave de acesso à API",
            "schema": {
              "type": "string"
            },
            "default": "980fb195fdecc68069deb67f987573837cf67e0e"
          }
        ],
        "responses": {
          "200": {
            "x-nullable": true,
            "description": "",
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
...

Is there any way to prevent html tags from being suppressed by generating the "description" attribute in the swagger.json file?

My attempt was to wrap the content with the ![CDATA[html content here]] tag. But it still does not work as expected.

Any help will be most welcome.

0 Answers
Related