0

For an API server, I have a set of models, e.g.

Recording <-> Artist 

with ManyToMany relation in TypeORM. The relation needs to be defined in both sides models.

In certain routes I am displaying only Recording and in certain routes also Recordings with Artists, using leftJoinAndSelect. E.g. /api/artists and /api/artists_with_recording.

However, the generated documentation always shows Recordings in Artists.

Is there some easy way to modify the swagger output?

I could make different model objects with swagger markup but with more objects in more contexts that could become pretty messy.

Richard
  • 43
  • 2
  • 8

1 Answers1

0

After more searching, I found a solution. I can use the OmitType function from NestJS to create simple ad hoc classes for the documentation.

https://docs.nestjs.com/openapi/mapped-types#omit

So for the route /api/artists I do

@Entity()
class Artist {
 ...
}

class ArtistWithoutRecording extends OmitType(Artist, ['recording'] as const)

In the controller documentation, I include the ArtistWithoutRecording type.

  @Get('artists')
  @ApiOperation({
    summary: 'Get all artists',
    description: 'Some description'
  })
  @ApiOkResponse({ type: ArtistWithoutRecording })
  async getArtists() {
    return this.artistDao.findMany()
  }

Richard
  • 43
  • 2
  • 8