-
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
base: main
Are you sure you want to change the base?
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"
]
}
}
}
} |
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.