how to display a relationship is swagger, typeorm and nestjs

129 views Asked by At

using @nestjs/swagger and @nestjs/typeorm, how to properly display a relationship field in swagger UI.

for example:

@Entity()
class MyEntity{
  @ManyToOne(() => StoreEntity, (store) => store.checkouts)
  @ApiProperty({ type: 'string', format: 'uuid', name: 'storeId' })
  store: StoreEntity;

}

I want that field to be displayed in swagger as a string to enter only the store's id, but in typeORM to be s storeEntity object. so, req.body.store can be just a string, but response.store is the full object

without separating them like that ...

  @ManyToOne(() => StoreEntity, (store) => store.checkouts)
  @ApiHideProperty()
  store: StoreEntity;

  @ApiProperty({ type: 'string', format: 'uuid' })
  storeId: string;
0

There are 0 answers