diff --git a/src/helpers.ts b/src/helpers.ts index f6ce8b3..0130b0e 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -200,6 +200,10 @@ export const getSwaggerDecoratorByFieldType = (field: PrismaDMMF.Field) => { args.push(`enum: Object.values(${field.type})`); } + if (field.relationName) { + args.push(`type: () => ${field.type}`); + } + return { name: 'ApiProperty', arguments: args.length > 0 ? [`{ ${args.join(', ')} }`] : [], diff --git a/tests/relation-splitting.test.ts b/tests/relation-splitting.test.ts index 8594afd..d0dcd1b 100644 --- a/tests/relation-splitting.test.ts +++ b/tests/relation-splitting.test.ts @@ -80,7 +80,9 @@ describe('Relation Splitting Generation', () => { expect(userRelations).toContain('import { Post } from "./"'); // Should have decorators for relations - expect(userRelations).toContain('@ApiProperty({ isArray: true })'); + expect(userRelations).toContain( + '@ApiProperty({ isArray: true, type: () => Post })', + ); }); it('should generate combined User class extending base', () => { diff --git a/tests/swagger-generation.test.ts b/tests/swagger-generation.test.ts index 0d08d8b..b1c9ec3 100644 --- a/tests/swagger-generation.test.ts +++ b/tests/swagger-generation.test.ts @@ -32,6 +32,7 @@ describe('Swagger Generation', () => { expect(userModel).toContain('type: "string"'); expect(userModel).toContain('required: false'); expect(userModel).toContain('isArray: true'); + expect(userModel).toContain('type: () => Post'); }); it('should generate Post model with correct Swagger decorators', () => {