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.
Questions tagged [nestjs-swagger]
152 questions
1
vote
1 answer
Nest/swagger not found
Error "@nestjs/swagger/plugin" plugin could not be found!
Have this error while starting my nestjs project. I don't know what am getting wrong. nestjs/swagger package is installed.

Chetachi
- 11
- 2
1
vote
0 answers
Generate nested objects with nest-swagger OpenApi
I want to generate an API file using nestjs/swagger, where one of the properties is an object.
In the result under the components/schemas section I see all schemas I created properly, but under the "paths" section I see that the nested properties…

B. Grossman
- 21
- 1
1
vote
0 answers
How can i get different request body schemas, depending on selected Media type in NestJs/Swagger?
I want to implement something like that:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/FaceEnrollmentRequest'
multipart/form-data:
schema:
…

Bruno Negreiros
- 11
- 2
1
vote
1 answer
How to make one of two fields required in Nestjs DTO with its proper API documentation?
For example:
{
phone: string
email: string
....
....
otherFields
....
....
}
Either phone or email should be required in request body. I found solution only for validation, here is:
export class MyDto {
@IsString()
…

Abdulla Qurbonov
- 11
- 1
- 3
1
vote
1 answer
Show recursivity in swagger docs
If I declare DepartmentDto type that recursively references itself:
export class DepartmentDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
id: string;
@IsNotEmpty()
@IsString()
@ApiProperty()
name: string;
@ApiProperty()
…

Ruslan Plastun
- 1,985
- 3
- 21
- 48
1
vote
0 answers
Typescript Parsing error: Expression expected
Please check out this code
class A {
@ApiProperty({ example: 'Success' })
message: string;
@ApiProperty({})
data: T;
}
export const SwaggerEssentials = (okRes?: apiOkResponse) => {
return applyDecorators(
ApiResponse({…

Ali Hussnain - alichampion
- 559
- 1
- 5
- 17
1
vote
0 answers
How to use generic class as type in typescript
I'm using AsyncApi decorator for my kafka nestjs microservice, but I do not know how to define type of message. This is how decorator looks like:
@AsyncApiSub({
channel: Topics.MESSAGE_CREATE,
description: "...",
message: {
name:…

michal pavlik
- 330
- 3
- 18
1
vote
1 answer
NestJS typeorm pagination type in @nestjs/swagger plugin
i have an endpoint which returns a list with pagination.
i'm trying to use nestjs/swagger plugin to automatically collect endpoints and DTOs and etc.
plugin works fine with all endpoints except the one which the return type is typeorm pagination.
…

ShayanJZ
- 61
- 4
1
vote
0 answers
How to describe response in swagger with different properties?
I return object with different properties, like this
export class ProductsDto {
[product: string]: ProductDto
}
export class ProductDto {
@ApiResponseProperty()
id: number;
@ApiResponseProperty()
price: number;
}
But, I don't see…

Vladimir Golub
- 523
- 1
- 8
- 22
1
vote
2 answers
How to make URI versioning optional in a nestjs REST application
NestJS URI Versioning for HTTP REST applications can be easily enabled when following the docs here.
The docs do however not explain how to make URI versioning optional.
Example:
/api/v1/users
/api/v2/users
/api/users -> should be mapped to v1 to…

MADforFUNandHappy
- 538
- 6
- 24
1
vote
0 answers
How to implement "additionalProperties": false, in nestjs/swagger
How can I implement the "additionalProperties": false, with nestjs/swagger
{
"properties": {
"name": {
"oneOf": [
{
"type": "string"
},
{
…

Alvanxl
- 150
- 1
- 6
1
vote
0 answers
NX+Nestjs typescript compiler plugin fails
We use the https://docs.nestjs.com/openapi/cli-plugin in a nrwl-nx nestjs project.
This basically works, but the build fails, when we use this import in a DTO:
import {Temporal} from "@js-temporal/polyfill";
import Instant =…

TmTron
- 17,012
- 10
- 94
- 142
1
vote
2 answers
validating an array of uuids in nestjs swagger body
It sounds like a quite simple question but I've been searching for a solution for a very long time now. I want to validate an array of UUIDs in an endpoint.
Like this:
["9322c384-fd8e-4a13-80cd-1cbd1ef95ba8",…

MOE
- 769
- 6
- 19
1
vote
1 answer
NestJS: How to handle custom directors errors
I am having a NestJS backend application.
my-controller.ts
import { Roles } from 'private-npm';
export class myController {
constructor(private readonly service: MyService) { }
---> @ClientRoles({ roles: ['test-role'] })
@Get()
…

The Rock
- 323
- 1
- 8
- 18
1
vote
0 answers
NestJs - CLI Plugin - enabling the Swagger plugin for npm dependencies
I created a npm DTO library used on different projects (front / back)
On the back side, I use NestJs and I would like to activate the Swagger CLI-Plugin of NestJs (https://docs.nestjs.com/openapi/cli-plugin) on the created library, any idea how to…

Ugo Evola
- 546
- 3
- 8
- 19