-
Notifications
You must be signed in to change notification settings - Fork 66
fix: Handle arrays of enum strings correctly #6156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Without this change an array of enums will result in e.g.:
export type Model1 = {
values: 'A' | 'B' | 'C'[];
} & Record<string, any>;
which means the value can be either "A", "B", or "C"[], which is wrong.
|
I tested this with the following API json: {
"openapi": "3.0.3",
"info": {
"version": "1.0.0",
"title": "Api",
"description": "API"
},
"components": {
"schemas": {
"Model1": {
"type": "object",
"required": ["values"],
"properties": {
"values": {
"type": "array",
"items": {
"type": "string",
"uniqueItems": true,
"minItems": 0,
"enum": [
"A",
"B",
"C"
]
}
}
}
}
}
},
"paths": {
"/values": {
"get": {
"summary": "",
"operationId": "getValues",
"responses": {
"200": {
"description": "A list of all values",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Model1"
}
}
}
}
}
}
}
}
} |
|
Hi @daniel-kullmann , Thanks for your contribution! We really appreciate it. One thing is confusing me a bit. In your json object, I see Overall seems like a valid fix. @deekshas8 WDYT? |
|
Hi @ZhongpinWang I agree, but for some reason, the value of Regardless of that, if |
|
I have created a repo to reproduce the problem: https://github.com/daniel-kullmann/openapi-generator-bug |
|
Ah, "Model1": {
"type": "object",
"required": ["values"],
"properties": {
"values": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"minItems": 0,
"enum": [
"A",
"B",
"C"
]
}
}
}
} |
|
Any progress on this? |
deekshas8
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @daniel-kullmann. With the tests and changelog in place, this is now ready to be merged. 🚀
| enum: ["'One'", "'Two'"] | ||
| } | ||
| }) | ||
| ).toEqual("('One' | 'Two')[]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏽
|
Thanks for the contribution @daniel-kullmann! |
|
Hi @daniel-kullmann , We have released Cloud SDK v4.2.0 with your contribution! Thanks again for this PR. |
Without this change an array of enums will result in e.g.:
export type Model1 = {
values: 'A' | 'B' | 'C'[];
} & Record<string, any>;
which means the value can be either "A", "B", or "C"[], which is wrong.