Skip to content

Commit

Permalink
Merge pull request #3164 from arabold/fix-apischema-inheritance
Browse files Browse the repository at this point in the history
fix: @ApiSchema inheritance
  • Loading branch information
kamilmysliwiec authored Nov 15, 2024
2 parents 7acedba + f8ba5ef commit 0d5354f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/get-schema-path.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
18 changes: 18 additions & 0 deletions test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, SchemasObject> = {};

schemaObjectFactory.exploreModelSchema(UpdateUserDto, schemas);

expect(Object.keys(schemas)).toContain('UpdateUser');
});

it('should include extension properties', () => {
@ApiExtension('x-test', 'value')
class CreatUserDto {
Expand Down

0 comments on commit 0d5354f

Please sign in to comment.