npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@globalart/nestjs-swagger

v1.2.6

Published

A simple documentation builder for NestJS Swagger Module

Downloads

11,821,507

Readme

@globalart/nestjs-swagger

A simple documentation builder for NestJS Swagger module that simplifies creating OpenAPI documentation for your REST APIs.

Installation

npm install @globalart/nestjs-swagger

or

yarn add @globalart/nestjs-swagger

Description

This package provides a convenient SwaggerDocumentation decorator for automatic Swagger documentation generation in NestJS applications. It significantly simplifies the process of adding documentation to your endpoints by providing a unified interface for describing operations and possible errors.

Key Features

  • 📝 Simple decorator for endpoint documentation
  • 🔧 Pre-configured descriptions for standard HTTP errors
  • 📊 Support for paginated responses
  • 🎯 Support for arrays in responses
  • 📋 Automatic schema generation for DTOs
  • 🛡️ Full TypeScript typing

Quick Start

import { Controller, Get } from '@nestjs/common';
import { SwaggerDocumentation, ERROR_DESCRIPTIONS } from '@globalart/nestjs-swagger';

@Controller('users')
export class UsersController {
  @Get()
  @SwaggerDocumentation({
    endpointDescription: 'Get list of all users',
    endpointSummary: 'List users',
    error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
    error401Description: ERROR_DESCRIPTIONS.UNAUTHORIZED,
    error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
  })
  async getAllUsers() {
    return [];
  }
}

API Reference

SwaggerDocumentation

Decorator for automatic Swagger documentation generation.

Parameters

| Parameter | Type | Description | | --------------------- | ---------- | ------------------------------------ | | endpointDescription | string | Detailed endpoint description | | endpointSummary | string | Brief endpoint description | | responseDto | Function | DTO class for response | | isArray | boolean | Indicates that response is an array | | isPaginated | boolean | Indicates that response is paginated | | error400Description | string | 400 error description | | error401Description | string | 401 error description | | error403Description | string | 403 error description | | error404Description | string | 404 error description | | error409Description | string | 409 error description | | error422Description | string | 422 error description | | error429Description | string | 429 error description | | error500Description | string | 500 error description | | error503Description | string | 503 error description |

ERROR_DESCRIPTIONS

Object with pre-configured error descriptions:

export const ERROR_DESCRIPTIONS = {
  BAD_REQUEST: "Invalid request data or parameters",
  UNAUTHORIZED: "Authentication required", 
  FORBIDDEN: "Access denied",
  NOT_FOUND: "Resource not found",
  CONFLICT: "Resource already exists or conflict detected",
  UNPROCESSABLE_ENTITY: "Validation error",
  RATE_LIMIT_EXCEEDED: "Rate limit exceeded. Too many requests",
  INTERNAL_SERVER_ERROR: "Internal server error",
  SERVICE_UNAVAILABLE: "Service temporarily unavailable"
};

Usage Examples

Basic Usage

import { Controller, Get } from '@nestjs/common';
import { SwaggerDocumentation, ERROR_DESCRIPTIONS } from '@globalart/nestjs-swagger';

@Controller()
export class AppController {
  @Get('hello')
  @SwaggerDocumentation({
    endpointDescription: 'Simple greeting endpoint',
    endpointSummary: 'Greeting',
    error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
    error401Description: ERROR_DESCRIPTIONS.UNAUTHORIZED,
    error403Description: ERROR_DESCRIPTIONS.FORBIDDEN,
    error404Description: ERROR_DESCRIPTIONS.NOT_FOUND,
    error429Description: ERROR_DESCRIPTIONS.RATE_LIMIT_EXCEEDED,
    error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
  })
  async hello() {
    return 'Hello World';
  }
}

Using with DTO

import { ApiProperty } from '@nestjs/swagger';

export class UserDto {
  @ApiProperty()
  id: number;

  @ApiProperty()
  name: string;

  @ApiProperty()
  email: string;
}

@Controller('users')
export class UsersController {
  @Get(':id')
  @SwaggerDocumentation({
    endpointDescription: 'Get user by ID',
    endpointSummary: 'Get user',
    responseDto: UserDto,
    error404Description: ERROR_DESCRIPTIONS.NOT_FOUND,
    error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
  })
  async getUserById(@Param('id') id: number) {
    // user retrieval logic
  }
}

Working with Arrays

@Controller('users')
export class UsersController {
  @Get()
  @SwaggerDocumentation({
    endpointDescription: 'Get list of all users',
    endpointSummary: 'List users',
    responseDto: UserDto,
    isArray: true,
    error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
  })
  async getAllUsers() {
    // user list retrieval logic
  }
}

Paginated Responses

@Controller('users')
export class UsersController {
  @Get()
  @SwaggerDocumentation({
    endpointDescription: 'Get paginated list of users',
    endpointSummary: 'Paginated user list',
    responseDto: UserDto,
    isPaginated: true,
    error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
    error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
  })
  async getPaginatedUsers(@Query() query: PaginationDto) {
    // pagination logic
  }
}

Paginated Response Structure

When using isPaginated: true, the response is automatically wrapped in the structure:

{
  data: T[],        // array of objects of the specified DTO
  totalCount: number,  // total number of records
  offset: number,      // offset
  limit: number        // limit of records per page
}