swagger
swagger copied to clipboard
Incorrent enum with 'x-enumNames' generation
Is there an existing issue for this?
- [x] 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
- npm i
- npm start
- 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
- [x] Windows
- [x] Linux
Other
No response
@kamilmysliwiec I’ve submitted the fix for this issue in PR #3307 targeting the latest version, and it solves the problem correctly.
This issue still occurs in version 8.x (e.g., @nestjs/[email protected]).
Would you like me to apply this fix to that version as well?