swagger
swagger copied to clipboard
fix(core): isArray always false for enum arrays in plugin metadata
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
Enum arrays in plugin-generated metadata never have 'isArray' to true
.
Issue Number: 1676
What is the new behavior?
Enum arrays in plugin-generated metadata always have 'isArray' to true
.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
@kamilmysliwiec is an enum array with 1 value supposed to have isArray
to true? Seems like the test disagrees. In my mind, this means the API is expecting an array so isArray
should be true.
Oh, I ran into this.... @kamilmysliwiec Can we please plan to get this merged? @ArielPrevu3D is there any work around to get this going while we wait for the release?
Oh, I ran into this.... @kamilmysliwiec Can we please plan to get this merged? @ArielPrevu3D is there any work around to get this going while we wait for the release?
This is the workaround we're using. This fixes the schema after generating the schema document.
// Workaround for enum arrays
// https://github.com/nestjs/swagger/issues/1676
if (document?.components?.schemas) {
for (const schemaKey in document.components.schemas) {
const schema = document.components.schemas[schemaKey];
if (
'type' in schema &&
schema.type === 'object' &&
schema.properties
) {
for (const schemaPropKey in schema.properties) {
const property = schema.properties[schemaPropKey];
if ('items' in property && 'enum' in property) {
delete property.enum;
}
}
}
}
}
Thank you @ArielPrevu3D !