Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,6 @@
2,
3
],
"description": "The x-enumNames test",
"x-enumNames": [
"APPROVED",
"PENDING",
Expand Down
1 change: 0 additions & 1 deletion lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ export class SchemaObjectFactory {
metadata.isArray && metadata.items
? metadata.items['enum']
: metadata.enum,
description: metadata.description ?? undefined,
'x-enumNames': metadata['x-enumNames'] ?? undefined
};
} else {
Expand Down
77 changes: 77 additions & 0 deletions test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,83 @@ describe('SchemaObjectFactory', () => {

expect(schemas).toEqual({ MyEnum: { enum: [1, 2, 3], type: 'number' } });
});

it('should place x-enumNames on the enum schema, not on the DTO property (issue #3391)', () => {
const metadata = {
type: 'number',
enum: [1, 2, 3],
enumName: 'XEnumTest',
isArray: false,
description: 'The x-enumNames test',
'x-enumNames': ['APPROVED', 'PENDING', 'REJECTED']
} as any;
const schemas = {};

const result = schemaObjectFactory.createEnumSchemaType(
'xEnumTest',
metadata,
schemas
);

// x-enumNames must be on the enum schema
expect(schemas['XEnumTest']['x-enumNames']).toEqual([
'APPROVED',
'PENDING',
'REJECTED'
]);

// x-enumNames must NOT appear on the returned DTO property object
expect(result['x-enumNames']).toBeUndefined();
});

it('should not copy description from DTO property metadata to the enum schema', () => {
const metadata = {
type: 'number',
enum: [1, 2, 3],
enumName: 'XEnumTest',
isArray: false,
description: 'Property-level description'
} as any;
const schemas = {};

const result = schemaObjectFactory.createEnumSchemaType(
'xEnumTest',
metadata,
schemas
);

// description must NOT be copied to the enum schema
expect(schemas['XEnumTest']['description']).toBeUndefined();

// description must stay on the returned DTO property object
expect(result['description']).toBe('Property-level description');
});

it('should place x-enumNames on existing enum schema when schema already registered', () => {
const schemas = {
XEnumTest: { type: 'number', enum: [1, 2, 3] }
};
const metadata = {
type: 'number',
enum: [1, 2, 3],
enumName: 'XEnumTest',
isArray: false,
'x-enumNames': ['APPROVED', 'PENDING', 'REJECTED']
} as any;

const result = schemaObjectFactory.createEnumSchemaType(
'xEnumTest',
metadata,
schemas
);

expect(schemas['XEnumTest']['x-enumNames']).toEqual([
'APPROVED',
'PENDING',
'REJECTED'
]);
expect(result['x-enumNames']).toBeUndefined();
});
});

describe('createEnumParam', () => {
Expand Down