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

@new_superfi/nestjs-swagger-typescript-viewer

v1.0.3

Published

NestJS Swagger TypeScript interface viewer

Readme

@new_superfi/nestjs-swagger-typescript-viewer

npm version License: MIT Changelog

A library that adds TypeScript interface viewer functionality to NestJS Swagger UI. It automatically converts OpenAPI schemas to TypeScript interfaces, allowing you to view Request/Response types in TypeScript format within Swagger UI.

Installation

npm install @new_superfi/nestjs-swagger-typescript-viewer
# or
yarn add @new_superfi/nestjs-swagger-typescript-viewer
# or
pnpm add @new_superfi/nestjs-swagger-typescript-viewer

Peer Dependencies

This package requires the following packages as peer dependencies:

  • @nestjs/common: ^10.0.0 || ^11.0.0
  • @nestjs/core: ^10.0.0 || ^11.0.0
  • @nestjs/swagger: ^10.0.0 || ^11.0.0

Quick Start

import { NestFactory } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { setupSwaggerWithTypeScript } from "@new_superfi/nestjs-swagger-typescript-viewer";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle("My API")
    .setDescription("API description")
    .setVersion("1.0")
    .build();

  const document = SwaggerModule.createDocument(app, config);

  // Use setupSwaggerWithTypeScript instead of SwaggerModule.setup
  setupSwaggerWithTypeScript(app, "api", document);

  await app.listen(3000);
}
bootstrap();

Usage

Basic Setup

setupSwaggerWithTypeScript(
  app: INestApplication,
  path: string,
  document: OpenAPIObject,
  options?: SwaggerTypeScriptOptions
): void;

Options

interface SwaggerTypeScriptOptions {
  path?: string; // Swagger UI path (default: uses the path passed as the first argument)
  customCss?: string; // Custom CSS
  swaggerOptions?: any; // Additional Swagger UI options
}

Example: Using Custom Options

setupSwaggerWithTypeScript(app, "api", document, {
  customCss: ".swagger-ui { max-width: 1200px; }",
  swaggerOptions: {
    persistAuthorization: true,
    displayRequestDuration: true,
  },
});

Examples

DTO Example

// user.dto.ts
import { ApiProperty } from "@nestjs/swagger";

export class CreateUserDto {
  @ApiProperty({ description: "User name" })
  name: string;

  @ApiProperty({ description: "Email", required: false })
  email?: string;

  @ApiProperty({ description: "Age", type: Number })
  age: number;
}

export class UserResponseDto {
  @ApiProperty({ description: "User ID" })
  id: number;

  @ApiProperty({ description: "User name" })
  name: string;

  @ApiProperty({ description: "Email" })
  email: string;
}

When using DTOs like the above, TypeScript interfaces are automatically generated and displayed in Swagger UI:

interface CreateUserDto {
  name: string;
  email?: string;
  age: number;
}

interface UserResponseDto {
  id: number;
  name: string;
  email: string;
}

NestJS Swagger UI에 TypeScript 인터페이스 뷰어 기능을 추가하는 라이브러리입니다. OpenAPI 스키마를 자동으로 TypeScript 인터페이스로 변환하여 Swagger UI에서 Request/Response 타입을 TypeScript로 확인할 수 있습니다.

설치

npm install @new_superfi/nestjs-swagger-typescript-viewer
# 또는
yarn add @new_superfi/nestjs-swagger-typescript-viewer
# 또는
pnpm add @new_superfi/nestjs-swagger-typescript-viewer

Peer Dependencies

이 패키지는 다음 패키지들을 peer dependency로 요구합니다:

  • @nestjs/common: ^10.0.0 || ^11.0.0
  • @nestjs/core: ^10.0.0 || ^11.0.0
  • @nestjs/swagger: ^10.0.0 || ^11.0.0

빠른 시작

import { NestFactory } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { setupSwaggerWithTypeScript } from "@new_superfi/nestjs-swagger-typescript-viewer";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle("My API")
    .setDescription("API description")
    .setVersion("1.0")
    .build();

  const document = SwaggerModule.createDocument(app, config);

  // 기존 SwaggerModule.setup 대신 setupSwaggerWithTypeScript 사용
  setupSwaggerWithTypeScript(app, "api", document);

  await app.listen(3000);
}
bootstrap();

사용법

기본 설정

setupSwaggerWithTypeScript(
  app: INestApplication,
  path: string,
  document: OpenAPIObject,
  options?: SwaggerTypeScriptOptions
): void;

옵션

interface SwaggerTypeScriptOptions {
  path?: string; // Swagger UI 경로 (기본값: 첫 번째 인자로 전달된 path 사용)
  customCss?: string; // 커스텀 CSS
  swaggerOptions?: any; // Swagger UI 추가 옵션
}

예제: 커스텀 옵션 사용

setupSwaggerWithTypeScript(app, "api", document, {
  customCss: ".swagger-ui { max-width: 1200px; }",
  swaggerOptions: {
    persistAuthorization: true,
    displayRequestDuration: true,
  },
});

예제

DTO 예제

// user.dto.ts
import { ApiProperty } from "@nestjs/swagger";

export class CreateUserDto {
  @ApiProperty({ description: "사용자 이름" })
  name: string;

  @ApiProperty({ description: "이메일", required: false })
  email?: string;

  @ApiProperty({ description: "나이", type: Number })
  age: number;
}

export class UserResponseDto {
  @ApiProperty({ description: "사용자 ID" })
  id: number;

  @ApiProperty({ description: "사용자 이름" })
  name: string;

  @ApiProperty({ description: "이메일" })
  email: string;
}

위와 같은 DTO를 사용하면 Swagger UI에서 자동으로 TypeScript 인터페이스가 생성되어 표시됩니다:

interface CreateUserDto {
  name: string;
  email?: string;
  age: number;
}

interface UserResponseDto {
  id: number;
  name: string;
  email: string;
}

Contributing

Contributions are welcome! Please contribute through issue reports or Pull Requests.

License

MIT License

Copyright (c) 2025 new_superfi