Skip to content

Commit c8352cb

Browse files
Merge pull request #3590 from pvdspek/fix-apiproperty-array-with-undefined-enum
fix: missing ApiProperty enum undefined on array handling
2 parents 4f2ddc8 + c0583ba commit c8352cb

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/decorators/api-property.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const isEnumArray = (
3636
enum: EnumAllowedTypes;
3737
type: any;
3838
items: any;
39-
} => opts.isArray && 'enum' in opts;
39+
} => opts.isArray && 'enum' in opts && opts.enum !== undefined;
4040

4141
/**
4242
* @publicApi

test/services/schema-object-factory.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,32 @@ describe('SchemaObjectFactory', () => {
664664
required: ['testString']
665665
});
666666
});
667+
668+
it('should not use undefined enum on array', () => {
669+
class TestDto {
670+
@ApiProperty({
671+
type: 'string',
672+
isArray: true,
673+
enum: undefined
674+
})
675+
testStringArray: string[];
676+
}
677+
678+
const schemas = {};
679+
schemaObjectFactory.exploreModelSchema(TestDto, schemas);
680+
expect(schemas[TestDto.name]).toEqual({
681+
type: 'object',
682+
properties: {
683+
testStringArray: {
684+
type: 'array',
685+
items: {
686+
type: 'string'
687+
}
688+
}
689+
},
690+
required: ['testStringArray']
691+
});
692+
});
667693
});
668694

669695
describe('createEnumSchemaType', () => {

0 commit comments

Comments
 (0)