From 5628e8c5231cad92aec39722c23aa447a90ddf7b Mon Sep 17 00:00:00 2001 From: nxht Date: Fri, 10 Jan 2025 13:31:24 +0900 Subject: [PATCH 1/2] fix: missing ApiProperty enum undefined handling --- lib/decorators/api-property.decorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/decorators/api-property.decorator.ts b/lib/decorators/api-property.decorator.ts index c701ca860..36b75b73c 100644 --- a/lib/decorators/api-property.decorator.ts +++ b/lib/decorators/api-property.decorator.ts @@ -64,7 +64,7 @@ export function createApiPropertyDecorator( enum: enumValues }; delete options.enum; - } else if ('enum' in options) { + } else if ('enum' in options && options.enum !== undefined) { const enumValues = getEnumValues(options.enum); options.enum = enumValues; From 218dfbe3eccd79d5d379c05eb0897e3e15e1c528 Mon Sep 17 00:00:00 2001 From: nxht Date: Fri, 10 Jan 2025 13:40:26 +0900 Subject: [PATCH 2/2] test: add undefined enum test --- test/services/schema-object-factory.spec.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/services/schema-object-factory.spec.ts b/test/services/schema-object-factory.spec.ts index 7db75e122..1c4427a15 100644 --- a/test/services/schema-object-factory.spec.ts +++ b/test/services/schema-object-factory.spec.ts @@ -551,6 +551,28 @@ describe('SchemaObjectFactory', () => { required: ['arrayOfObjects'] }); }); + + it('should not use undefined enum', () => { + class TestDto { + @ApiProperty({ + type: 'string', + enum: undefined + }) + testString: string; + } + + const schemas = {}; + schemaObjectFactory.exploreModelSchema(TestDto, schemas); + expect(schemas[TestDto.name]).toEqual({ + type: 'object', + properties: { + testString: { + type: 'string' + } + }, + required: ['testString'] + }); + }); }); describe('createEnumSchemaType', () => {