Skip to content

Commit 1f5e971

Browse files
authored
Merge pull request #24 from JackCme/feature/swagger-decorator-relation-type
Fix/swagger decorator relation type
2 parents 045dd60 + 141de62 commit 1f5e971

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ export const getSwaggerDecoratorByFieldType = (field: PrismaDMMF.Field) => {
200200
args.push(`enum: Object.values(${field.type})`);
201201
}
202202

203+
if (field.relationName) {
204+
args.push(`type: () => ${field.type}`);
205+
}
206+
203207
return {
204208
name: 'ApiProperty',
205209
arguments: args.length > 0 ? [`{ ${args.join(', ')} }`] : [],

tests/relation-splitting.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ describe('Relation Splitting Generation', () => {
8080
expect(userRelations).toContain('import { Post } from "./"');
8181

8282
// Should have decorators for relations
83-
expect(userRelations).toContain('@ApiProperty({ isArray: true })');
83+
expect(userRelations).toContain(
84+
'@ApiProperty({ isArray: true, type: () => Post })',
85+
);
8486
});
8587

8688
it('should generate combined User class extending base', () => {

tests/swagger-generation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Swagger Generation', () => {
3232
expect(userModel).toContain('type: "string"');
3333
expect(userModel).toContain('required: false');
3434
expect(userModel).toContain('isArray: true');
35+
expect(userModel).toContain('type: () => Post');
3536
});
3637

3738
it('should generate Post model with correct Swagger decorators', () => {

0 commit comments

Comments
 (0)