lukeautry / tsoa

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

jsdoc @example is used for union type but ignored for enum #1603

Closed miszczu-drako closed 2 months ago

miszczu-drako commented 3 months ago

Both union type and enum in typescript are generated to enum in swagger, which is fine and expected. However if I specify an @example in jsdoc for union type, it will be visible in generated swagger file. But it won't be for enum.

Sorting

Expected Behavior

I expect that @example is taken into account both for union type and enum

Source ts file

/** 
 * the enum type
 * @example "bbb"
 */
enum EnumType {
  AAA = 'aaa',
  BBB = 'bbb'
}

/** 
 * the union type
 * @example "bbb"
 */
type UnionType = 'aaa' | 'bbb';

Expected yaml file

components:
    schemas:
        EnumType:
            description: 'the enum type'
            enum:
                - aaa
                - bbb
            type: string
            example: bbb
        UnionType:
            type: string
            enum:
                - aaa
                - bbb
            example: bbb
            description: 'the union type'

Current Behavior

Currenlty EnumType is generated without an example

components:
    schemas:
        EnumType:
            description: 'the enum type'
            enum:
                - aaa
                - bbb
            type: string
        UnionType:
            type: string
            enum:
                - aaa
                - bbb
            example: bbb
            description: 'the union type'

Possible Solution

Steps to Reproduce

  1. add @example in jsdoc to any enum you have in your code
  2. run tsoa spec
  3. verify that swagger file doesn't contain provided example

Context (Environment)

Version of the library: 5.1.1 Version of NodeJS: v20.9.0

Detailed Description

Nothing to add.

Breaking change?

No

github-actions[bot] commented 3 months ago

Hello there miszczu-drako 👋

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

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

miszczu-drako commented 2 months ago

Hey guys, why there's no response? Is my issue missing some required fields? Do I need to do some additional action from my side?

miszczu-drako commented 2 months ago

I have just opened a PR https://github.com/lukeautry/tsoa/pull/1609 with a fix