diff --git a/lib/services/schema-object-factory.ts b/lib/services/schema-object-factory.ts index a44f89e9a..df1381549 100644 --- a/lib/services/schema-object-factory.ts +++ b/lib/services/schema-object-factory.ts @@ -292,7 +292,7 @@ export class SchemaObjectFactory { return type.name; } - const schemaName = customSchema[0].name; + const schemaName = customSchema[customSchema.length - 1].name; return schemaName ?? type.name; } diff --git a/lib/utils/get-schema-path.util.ts b/lib/utils/get-schema-path.util.ts index f248aa64c..d418aacca 100644 --- a/lib/utils/get-schema-path.util.ts +++ b/lib/utils/get-schema-path.util.ts @@ -21,7 +21,7 @@ function getSchemaNameByClass(target: Function): string { return target.name; } - return customSchema[0].name ?? target.name; + return customSchema[customSchema.length - 1].name ?? target.name; } export function refs(...models: Function[]) { diff --git a/test/services/schema-object-factory.spec.ts b/test/services/schema-object-factory.spec.ts index 767cc14bd..d09714b9a 100644 --- a/test/services/schema-object-factory.spec.ts +++ b/test/services/schema-object-factory.spec.ts @@ -412,6 +412,24 @@ describe('SchemaObjectFactory', () => { expect(Object.keys(schemas)).toContain('UpdateUserDto'); }); + it('should override the schema name of base class', () => { + @ApiSchema({ + name: 'CreateUser' + }) + class CreateUserDto {} + + @ApiSchema({ + name: 'UpdateUser' + }) + class UpdateUserDto extends CreateUserDto {} + + const schemas: Record = {}; + + schemaObjectFactory.exploreModelSchema(UpdateUserDto, schemas); + + expect(Object.keys(schemas)).toContain('UpdateUser'); + }); + it('should include extension properties', () => { @ApiExtension('x-test', 'value') class CreatUserDto {