Skip to content

Incorrent enum with 'x-enumNames' generation #3391

@menelai

Description

@menelai

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

export enum XEnumTest {
  APPROVED = 1,
  PENDING,
  REJECTED
}

export class Cat {
  @ApiProperty({
    description: 'The x-enumNames test',
    enum: XEnumTest,
    enumName: 'XEnumTest',
    'x-enumNames': ['APPROVED', 'PENDING', 'REJECTED']
  })
  xEnumTest: XEnumTest;

}

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @ApiResponse({
    description: 'The record has been successfully created.',
    type: () => Cat
  })
  @Get()

  getHello(): string {
    return this.appService.getHello();
  }
}

creates JSON schema:

"schemas": {
      "XEnumTest": {
        "type": "number",
        "enum": [
          1,
          2,
          3
        ]
      },
      "Cat": {
        "type": "object",
        "properties": {
          "xEnumTest": {
            "description": "The x-enumNames test",
            "x-enumNames": [
              "APPROVED",
              "PENDING",
              "REJECTED"
            ],
            "allOf": [
              {
                "$ref": "#/components/schemas/XEnumTest"
              }
            ]
          }
        },
        "required": [
          "xEnumTest"
        ]
      }
    }

x-enumNames is in CreateCatDto

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-lmhdf2fg

Steps to reproduce

  1. npm i
  2. npm start
  3. open /api-docs-json

Expected behavior

"schemas": {
      "XEnumTest": {
        "type": "number",
        "enum": [
          1,
          2,
          3
        ],
        "x-enumNames": [
          "APPROVED",
          "PENDING",
          "REJECTED"
        ]
      },
      "Cat": {
        "type": "object",
        "properties": {
          "xEnumTest": {
            "description": "The x-enumNames test",
            "allOf": [
              {
                "$ref": "#/components/schemas/XEnumTest"
              }
            ]
          }
        },
        "required": [
          "xEnumTest"
        ]
      }
    }

x-enumNames array must be in XEnumTest

Package version

8.1.1

NestJS version

10.4.15

Node.js version

22.10.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions