I'm using Nest's CLI Plugin to automatically annotate stuff for my documentation.
The issue is that Instead of loading only the entity imported by my module, the plugin also loads all the entities referenced in relations into Swagger UI.
For example my Cidades Module uses the following entity which has 3 relations:
@Index('cidades_pkey', ['idCidade'], { unique: true })
@Entity('cidades', { schema: 'public' })
export class Cidades {
@PrimaryGeneratedColumn({ type: 'bigint', name: 'id_cidade' })
idCidade: string
@Column('text', { name: 'nome' })
nome: string
// Entities from these relations are displayed in the Schemas of Swagger UI
@OneToMany(() => Grupos, (grupos) => grupos.idCidade)
grupos: Grupos[]
@OneToMany(() => Instituicoes, (instituicoes) => instituicoes.idCidade)
instituicoes: Instituicoes[]
@OneToMany(() => Usuarios, (usuarios) => usuarios.idCidade)
usuarios: Usuarios[]
}
The entities from those relations are also displayed on my Schemas.
I want to only display Cidades, the entity imported by my module. I tried to use @ApiHideProperty() decorator to hide the relations but didn't work. Is the any workaround for this behaviour?
EDIT: I found a stop-gap solution. My CRUD methods were returning the entity, for example, createCidade(): Promise<Cidade> {}
I implemented a ResponseDto (based on JSend standards). One of it's properties holds data like the created resource Cidade.
Instead of returning an entity my methods return this DTO. This removed all unwanted entities from Swagger UI's Schemas and replaced them with ResponseDTO.
I found a better solution. You can use the @ApiHideProperty() decorator on all relations of your TypeORM entity, that way it won't be loaded into Swagger-UI schemas.
Example: stopping Swagger from loading Password relation when I'm working with a method that return Users entity.
@Entity('users', { schema: 'public' })
export class Users {
...
@ApiHideProperty()
@OneToOne(() => Passwords, (passwords) => passwords.idUser)
passwords: Passwords
}