Reusable enums support
See original GitHub issueI’m submitting a…
[ ] 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.
Current behavior
Currently enums are not defined under components section
"components": {
"schemas": {
"Album": {
"type": "object",
"properties": {
"direction": {
"type": "string",
"enum": [
"Up",
"Down",
"Right",
"Left"
]
}
}
}
}
}
Expected behavior
"components": {
"schemas": {
"direction": {
"type": "string",
"enum": [
"Up",
"Down",
"Right",
"Left"
]
},
"Album": {
"type": "object",
"properties": {
"direction": {
"schema": {
"$ref": "#/components/schemas/direction"
}
}
}
}
}
}
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
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.
Environment
Nest version: 4.0.0-next.2
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Enums - Swagger
Reusable enums. In OpenAPI 3.0, both operation parameters and data models use a schema , making it easy to reuse the data types....
Read more >How do I create reusable enums in Swagger specification ...
I have a problem with Enums. Say, I have two methods returning the very same Enum. In OpenAPI specification, I would like to...
Read more >Reusable enums in Absinth : r/elixir - Reddit
Actually, dynamic Enum values support was added to absinthe v1.6.0 (https://github.com/absinthe-graphql/absinthe/pull/1023, ...
Read more >Extensible Enums - Business Central - Microsoft Learn
Enums can be extended in order to add more values to the enumeration list in which case the Extensible property must be set...
Read more >Build Enumerations of Constants With Python's Enum
This module provides the Enum class for supporting ... need to build a hierarchy of enum classes to reuse functionality through inheritance.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 alazily-evaluated function
as follow:This will allow us to grab the
Status
string as the enum name at runtime to be able to “reuse” it. Any suggestions?Added in 4.3.0. We’re tracking PR to the docs here https://github.com/nestjs/docs.nestjs.com/pull/1024