lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.32k stars 481 forks source link

Not all examples are present in the swagger html #1649

Open christiancp100 opened 5 days ago

christiancp100 commented 5 days ago

The html generation out of the swagger docs doesn't seem 100% correct, it randomly fails setting the examples.

Sorting

Expected Behavior

I would expect the whole swagger docs are generated in HTML, representing the swagger JSON schema.

Current Behavior

Considering the following code:

  /**
   * Creates a new name
   */
  @Post()
  public async createName(
    @Body() model: CreateNameModel,
  ): Promise<CreateItemResponse | MessageResponse> {
    // Does stuff
  }

And:

/**
 * @example {
 *    "id": "111111",
 *    "name": "test-name",
 * }
 */
export interface CreateNameModel {
  id: string;
  name: string;
}

I would expect to see an example here, but I see string: Screenshot 2024-07-02 at 16 16 34

However, you can see it in the example tab: Screenshot 2024-07-02 at 16 23 00

This is inconsistent, because sometimes (randomly) it gets generated, but there is at least one or two examples that are missing in the whole swagger docs, but the swagger docs seem well generated:

{
    "/names": {
            "post": {
                "operationId": "CreateName",
                "responses": {
                    "200": {
                        "description": "Ok",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "anyOf": [
                                        {
                                            "$ref": "#/components/schemas/CreateItemResponse"
                                        },
                                        {
                                            "$ref": "#/components/schemas/MessageResponse"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "description": "Creates a new Name",
                "tags": [
                    "Name"
                ],
                "security": [],
                "parameters": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/CreateNameModel"
                            }
                        }
                    }
                }
            }
        }
}
{
  "CreateNameModel": {
    "properties": {
      "id": {
        "type": "string"
      },
      "name": {
        "type": "string"
      }
    },
    "required": ["id", "name"],
    "type": "object",
    "additionalProperties": false,
    "example": {
      "id": "111111",
      "name": "BUILDING-API-TEST-NAME"
    }
  }
}

Possible Solution

No idea on this

Steps to Reproduce

I am not really sure, I just have a swagger schema defined as the code provided above, sometimes it works sometimes it doesn't but it's really random. I've checked for JSON errors on the examples but I can't see any

Context (Environment)

TSOA: 6.1.5 Node: v20.12.2

github-actions[bot] commented 5 days ago

Hello there christiancp100 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀