azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Reuse enum definition multiple times
Enum 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.
Hello, I'm not sure if it's the answer, but there's a way to reuse it, so I'm attaching a link. https://swagger.io/docs/specification/data-models/enums/
Hello, I'm not sure if it's the answer, but there's a way to reuse it, so I'm attaching a link. https://swagger.io/docs/specification/data-models/enums/
Thanks for the info! Let's find a way to reuse the enum through this extension.
@changbokLee Would you mind taking a look at this issue?
okay sir i will try , our project are supporting that swagger version 2.0 3.0? , documention that it is explainning only 2.0 3.0 version .
@changbokLee Our extension currently relies on https://github.com/microsoft/OpenAPI.NET that supports both OpenAPI v2 and v3.0.1. But your codebase should focus on v3.0.1. The rest will be automatically done for you.
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
{
"name": "pruefungszeitpunkt",
"in": "query",
"description": "Prüfungszeitpunkt",
"schema": {
"enum": [
"beiKodierung",
"zurAbrechnung",
"waehlbar"
],
"type": "string",
"default": "beiKodierung"
},
"x-ms-visibility": "important"
}
But I would like to see
{
"name": "pruefungszeitpunkt",
"in": "query",
"description": "Prüfungszeitpunkt",
"schema": {
"$ref": "#/components/schemas/Pruefungszeitpunkt",
"type": "string"
},
"x-ms-visibility": "important"
},
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.)
@justinyoo Could you assign this to me?
@level120 Let’s wait for @changbokLee ‘s answer.
@justinyoo i m trying if i cant , i will can entrust wait for 2weeks only @level120
Unfortunately I was not able to follow up with the latest discussion on this. Can you confirm that my comment above refers to the same issue? Otherwise, I'd happily open a separate issue.
I think this issue can't start before solving https://github.com/Azure/azure-functions-openapi-extension/issues/248 Because enum type may have many definitions having different namespaces.
namespace Some.Alpha
{
public enum Status { ... }
}
namespace Any.Alpha
{
public enum Status { ... }
}
@level120 Having this work as long as enum names are unique would already add a lot of value...
Has there been any progress here?
its already so many months and there isnt anything new about it ?
What is the status on this, it currently gives us lots of hassle when the enums aren't placed in the schema.
Bump, fix this pls :)
#610 has addressed this issue. The next v2-preview release will contain this fix.