Questions tagged [nestjs-swagger]

The OpenAPI specification is a language-agnostic definition format used to describe RESTful APIs. Nest provides a dedicated module that allows generating such a specification by leveraging decorators.

Resources

152 questions
22
votes
4 answers

How to add summary and body manually in swagger nestjs

I am trying to add summary in my swagger documentation routes but I am not able to find the appropriate decorator for defining the summary. There are some routes in which I have not specified any DTO's. So, I would like to manually add request body…
Istiyak Tailor
  • 1,570
  • 3
  • 14
  • 29
19
votes
6 answers

Request body not showing in Nest.js + Swagger

My controller code is something like this. @Controller('customer') export class CustomerController{ constructor(private readonly customerService: CustomerService){} @Post('lookup') async someMethod(@Body() body:any){ …
p0tta
  • 1,461
  • 6
  • 28
  • 49
18
votes
6 answers

File uploading along with other data in Swagger NestJs

I want to send file along with JSON { "comment" : "string", "outletId" : 1 } The help I got from Documentation is requestBody: content: multipart/form-data: schema: type: object properties: …
Jamshaid Tariq
  • 551
  • 1
  • 8
  • 31
14
votes
3 answers

how to set the response to be an array in the swagger response using DTOs

some-dto.ts export class CreateCatDto { @ApiProperty() name: string; @ApiProperty() age: number; @ApiProperty() breed: string; } I don't want response something like this: @ApiOkResponse( …
har17bar
  • 728
  • 1
  • 8
  • 22
13
votes
3 answers

Why are types in dto not visible in swagger?

I'm setting up swagger document in my small Nest.js app according to this documentation: https://docs.nestjs.com/recipes/swagger How do I setup dto to correctly show schema in swagger? To be more specific, nested types. It shows only top level keys.…
Peter
  • 321
  • 1
  • 4
  • 10
11
votes
2 answers

NestJS Alphabetize Endpoints in SwaggerUI

This SO answer shows that SwaggerUi will sort endpoints alphabetically if it is passed apisSorter : "alpha" when instantiated. In NestJS the config options are passed in the SwaggerModule.createDocument. I cannot see where in the config eg here I…
auerbachb
  • 857
  • 11
  • 25
9
votes
2 answers

@nestjs/swagger does not set authorization headers

Can't authorize in a route using @nestjs/swagger@5.0.9 because I dont know how to configure the Document` in a right way and I couldn't find a workable answer in authorization official docs / stackoverflow / github. I've stumbled upon a problem with…
wald3
  • 343
  • 1
  • 3
  • 13
9
votes
3 answers

NestJs/swagger: Define ref schemas without DTO classes

I have an app where I define the API response schemas as plain javascript objects according to the open-api spec. Currently I am passing that to the ApiResponse decorator in @nestjs/swagger as follows: class CatsController { @Get() …
Pubudu Dodangoda
  • 2,742
  • 2
  • 22
  • 38
9
votes
2 answers

Does nestjs/swagger support documentation of query params, if they are not used separately?

I define a route to get a paginated result of orders in my controller. @Get() async find( @Query(new ValidationPipe({ whitelist: true })) query: OrderQueryDto & PaginatedQueryDto, ) { const builder = this.orderRepository …
ILCAI
  • 1,164
  • 2
  • 15
  • 35
9
votes
1 answer

Nestjs Config access to config in bootstrap level

According to this documentation you import your config in AppModule. I'm trying to access to config in bootstrap level in my main.ts file. Something like this: const app = await NestFactory.create(AppModule); if (config.get('swagger.enabled')) …
cheziHoyzer
  • 4,803
  • 12
  • 54
  • 81
7
votes
1 answer

How do I add a description for a schema (dto) in Swagger for Nestjs?

I would like to add a description field to my dto (also to satisfy no_schema_description in OpenAPI linting), but find no way to do so. Which decorator to use? At the point of defining the dto or in the response? Update (clarify): I am looking to…
Gerriet
  • 1,302
  • 14
  • 20
7
votes
1 answer

Nestjs IsEnum dto validation and swagger

This is working fine: import { IsIn } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; export class createEventDto { @IsIn([0, 1, 2, 3, 4, 5]) @ApiProperty({ description: 'description of the…
7
votes
2 answers

NestjS - Swagger ui css resource not found in production mode

I am working on a nestjs project, I've added swagger to display my endpoints, It's working great in dev mode, but once deployed in production using https://zeit.co/ (now), the endpoints page is not displayed correctly (the css is missing), I got in…
Youness Houdass
  • 204
  • 4
  • 15
6
votes
5 answers

How to avoid to write `@ApiProperty()` in each dto for NestJs-swagger

I'm researching the way on how to avoid to specify @ApiProperty() in each dto. I know there is exist a way to create file nest-cli.json, and if you specify Promise in your controller in nest-swagger it will produce the output dto from the…
Daniil Sinelnik
  • 244
  • 1
  • 5
  • 13
6
votes
0 answers

How to use Swagger with DTOs shared between a Nest.js API and a SPA?

I have a project with a Nest.js API and an Angular SPA. The DTOs used by the SPA to communicate with the API are in a separate project called Models and I'm using it as a dependency. In that way, I only need to change the DTO in one place, and can…
1
2 3
10 11