Api decorators

A lot is automated for us, but still some manual work is necessary.

Notice that the login() route in the Swagger UI lacks information. This is because we could not use the @Body() decorator in this route, and so Swagger cannot infer we are using the LoginDto here. Neither does it infer the JWT cookie returned.

We should then go to the AuthController and, over the login() route, use the @ApiBody() decorator to define the expected body.

@ApiBody({ type: LoginDto })

For the cookie part, we have to use the @ApiResponse() decorator for the OK status, and then state that it will have the header Set-Cookie, while defining a proper type and description for the cookie. We can then first define this header in the file auth -> swagger -> jwt-cookie.header.

export const JwtCookieHeader: HeadersObject = {
  'Set-Cookie': { description: 'JWT cookie', schema: { type: 'string' } },
};

And then, use it in the decorator as mentioned.

@ApiOkResponse({ headers: JwtCookieHeader })

We have then manually corrected these flaws, and can see the changes now.

Commit - Using swagger decorators to document manually

Last updated