The description of the ApiProperty decorator that declared enumName overwrites each other.
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
I declared dto as below.
enum TestEnum {
A = "A",
B = "B"
}
class EnumTest {
@ApiProperty({
enum: TestEnum,
enumName: 'TestEnum',
isArray: true,
description: 'testEnum of EnumTest'
default: [],
})
readonly testEnum: TestEnum[] = [];
}
class AnotherEnumTest {
@ApiProperty({
enum: TestEnum,
enumName: 'TestEnum',
isArray: true,
description: 'testEnum of AnotherEnumTest'
})
readonly testEnum: TestEnum[] = []
}
But I got the yaml as below.
components:
schemas:
TestEnum:
type: string
default: [] # It cause error on openAPI specification.
description: testEnum of AnotherEnumTest
enum:
- A
- B
# .....
EnumTest
type: object
properties:
testEnum:
type: array
items:
$ref: "#/components/schemas/TestEnum"
AnotherEnumTest
type: object
properties:
testEnum:
type: array
items:
$ref: "#/components/schemas/TestEnum"
I know that ['description', 'deprecated', 'default'] can be declared as a field of specific properties. I think that It does not seem appropriate to omit these three fields on EnumTest definition and declare metadata of EnumTest's property on TestEnum's schema.
Minimum reproduction code
https://gist.github.com/0816i/67866e4c94fe0825282b53cde8de3d16
Steps to reproduce
- Declare ApiProperty with the same enumName in different classes.
- Inside the decorator, we use additionalProperties such as description, default, etc. that go from openAPI schema to enum's.
- Values such as description or default that you want to apply to the field of the class to which the API property decorator is applied are applied as the field of the top schema, and if multiple additional fields are attached to the same enumName, this is overwritten.
- You'd expect the options in Api Property to be basically a description of the field in that class, but unfortunately it doesn't work that way.
Expected behavior
A class called EnumTest has a property called testEnum, which expects TestEnum to enter the form of an array. If so, I want the yaml as below.
components:
schemas:
TestEnum:
type: string
enum:
- A
- B
# .....
EnumTest
type: object
properties:
testEnum:
type: array
default: [],
description: testEnum of EnumTest
items:
$ref: "#/components/schemas/TestEnum"
AnotherEnumTest
type: object
properties:
testEnum:
type: array
default: []
description: testEnum of AnotherEnumTest
items:
$ref: "#/components/schemas/TestEnum"
In my opinion, if we want to field description and default for enum, it looks good to create another field that is isolated from property.
Package version
7.4.2
NestJS version
10.4.1
Node.js version
20.12.0
In which operating systems have you tested?
- [X] macOS
- [ ] Windows
- [X] Linux
Other
It relate on https://github.com/nestjs/swagger/pull/2816
Please reconsider your decision on using the additional field for enum.