Reuse enum definition multiple times
See original GitHub issueEnum in generated OpenAPI document is defined inline.
"schemas": {
"myRequest": {
(...)
"properties": {
"myEnumProperty": {
"enum": [
"value1",
"value2"
],
"type": "string",
(...)
When using an enum multiple times within the same API, Visual Studio ‘Connected Services’ (utilizing nswag) will generate multiple enum definitions on client-side for the same enum. This requires uneccessary type conversions in client code.
OpenAPI spec allows to define enum as reference, which results in only one enum definition on client-side:
"schemas": {
"myEnumType": {
"enum": [
"value1",
"value2"
],
"type": "string",
(...)
},
"myRequest": {
(...)
"properties": {
"myEnumProperty": {
"$ref": "#/components/schemas/myEnumType"
}
(...)
Is it possible to configure enum gerenation as reference?
Would be a great help.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Reusing enum values in separate enum types - c++
Is there a way to reuse the same enum value in separate types? I'd like to be able to something like the following:...
Read more >Why are two literals allowed to have the same values in ...
Enumerations are just named integer constants with a type, so you can have two constants with the same name. Notably this allows you...
Read more >Language Guide (proto 2) | Protocol Buffers Documentation
Combining Messages leads to bloat While multiple message types (such as message, enum, and service) can be defined in a single .proto file,...
Read more >Build Enumerations of Constants With Python's Enum
In this tutorial, you'll learn how to create and use enumerations of semantically related constants in Python. To do this, you'll use the ......
Read more >How to extend enums in TypeScript
The short answer is no, you can't extend enums because TypeScript offers no language feature to extend them. However, there are workarounds you ......
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
@level120 Having this work as long as enum names are unique would already add a lot of value…
I guess I’m facing the same issue. I have an azure function, for which the generated swagger.json looks similar as above, but I want to have the enums defined once and then referenced. Currently it reads
But I would like to see
Can you please tell me whether this will be resolved using the current issue? If not, I will happily open a separate issue. (My generated swagger.json says at the top of the file that it is targeting OpenApi 3.0.1.)