0

I am using routing-controllers-openapi to document an API and I am facing a problem to show the body from a request as parameter in the Swagger UI.

The controller is implemented this way:

@HttpCode(201)
  @OpenAPI({
    description: 'Create a new user'
  })
  @Post('/')
  async newUserAccess(@Body() user: UserAccessDto): Promise<void> {
    await this.service.newUserAccess(user);
  }
}

The Swagger UI shows the UserAccessDto in the example from the parameters but not in the parameter, as de body: enter image description here

I am trying to achieve something like this, in the Pet Store Swagger UI: enter image description here

Anyone knows if this is possible?

Christian Benseler
  • 7,907
  • 8
  • 40
  • 71
  • Try using @BodyParams() instead of @Body() – Dhruv Shah Jun 21 '21 at 11:59
  • I have tried, same behaviour in the Swagger UI. – Christian Benseler Jun 21 '21 at 12:12
  • 1
    Everything seems to be right. The difference in Swagger UI rendering is caused by OpenAPI version used for the API. Your API uses OpenAPI 3 where request bodies are defined as, well, request bodies. The second screenshot is for an OpenAPI 2.0 API where request bodies were defined as body parameters (but the idea is the same - it's the request body, just named differently). Compare that with the OpenAPI 3.0 Petstore version: https://petstore3.swagger.io/ - where request bodies are displayed just like in your API. – Helen Jun 21 '21 at 14:59
  • @Helen thanks for the explanation! I took a look at the link you sent and everything seems to be right! []s – Christian Benseler Jun 22 '21 at 11:54

0 Answers0