tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Not all examples are present in the swagger html

Open christiancp100 opened this issue 7 months ago • 4 comments

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

Sorting

  • [x] bug report

  • [ ] feature request

  • [ ] support request

  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

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

  • Confirm you were using yarn not npm: [x]

christiancp100 avatar Jul 02 '24 14:07 christiancp100