Skip to content

Commit

Permalink
Merge pull request #3232 from nxht/fix/3229
Browse files Browse the repository at this point in the history
fix: missing ApiProperty enum undefined handling
  • Loading branch information
kamilmysliwiec authored Jan 10, 2025
2 parents 81e1d02 + 218dfbe commit 8c9cd39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/decorators/api-property.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 8c9cd39

Please sign in to comment.