[ ] Regression
[ ] Bug report
[x ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Currently enums are not defined under components section
"components": {
"schemas": {
"Album": {
"type": "object",
"properties": {
"direction": {
"type": "string",
"enum": [
"Up",
"Down",
"Right",
"Left"
]
}
}
}
}
}
"components": {
"schemas": {
"direction": {
"type": "string",
"enum": [
"Up",
"Down",
"Right",
"Left"
]
},
"Album": {
"type": "object",
"properties": {
"direction": {
"schema": {
"$ref": "#/components/schemas/direction"
}
}
}
}
}
}
OpenApi 3 allows us to reference enums under components section to use them multiple times.
See the "Reusable Enums" section here https://swagger.io/docs/specification/data-models/enums/
It would allow us to get enums types on the front side too with classes, using a generator like ng-openapi-gen for example, which would be amazing.
Nest version: 4.0.0-next.2
For Tooling issues:
- Node version: XX
- Platform:
Others:
There is one caveat about this feature which is getting the Enum name at runtime. One possible solution without adding more property to ApiProperty is to have: enum: to accept a lazily-evaluated function as follow:
enum Status {
Inactive = 'inactive',
Active = 'active'
}
@ApiProperty({enum: () => Status})
status: Status;
This will allow us to grab the Status string as the enum name at runtime to be able to "reuse" it. Any suggestions?
It sounds good to me
PR #412 is in
@flogh are you open to pull my branch and give it some test runs?
Of course ! I'm doing it right now
Awesome. I'm kinda running on some tight timeline here but will test on my project as soon as I have some free time. That said, if you could post your feedback/bug reports/suggestions on the PR thread, that'd be awesome. Thanks again!
Added in 4.3.0. We're tracking PR to the docs here https://github.com/nestjs/docs.nestjs.com/pull/1024
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
There is one caveat about this feature which is getting the Enum name at runtime. One possible solution without adding more property to
ApiPropertyis to have:enum:to accept alazily-evaluated functionas follow:This will allow us to grab the
Statusstring as the enum name at runtime to be able to "reuse" it. Any suggestions?