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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@0x0c/nestjs-swagger

v7.4.0

Published

Nest - modern, fast, powerful node.js web framework (@swagger)

Downloads

23

Readme

Description

OpenAPI (Swagger) module for Nest.

What's this fork?

tl;dr see https://github.com/nestjs/swagger/issues/723

The fork is 1:1 to the original project, but it adds a single feature: ApiModel({ name: string }) decorator to allow renaming of Swagger schemas.

This is useful for namespacing purposes, and as an escape hatch (when you simply can't avoid naming collisions between your classes, for any reason).

For example, you may prefer to use TypeScript namespaces to organize your typings and DTOs:

export namespace EntityV1HttpNS {
  export namespace FooMethod {
    export namespace Response {
      export class Body {
        @ApiProperty()
        status: number;
      }
    }
  }
}

export namespace ThingV1HttpNS {
  export namespace BarMethod {
    export namespace Response {
      export class Body {
        @ApiProperty()
        message: string;
      }
    }
  }
}

If you use both Body classes as a return type for your controller methods, @nestjs/swagger will generate an invalid Swagger spec due to a schema pathing collision.

And since TypeScript namespaces are a compile-time feature, it is not possible (or even preferable) for @nestjs/swagger to use namespace names to construct schema names during runtime.

@ApiModel() allows you to rename Body in a generated Swagger spec:

export namespace EntityV1HttpNS {
  export namespace FooMethod {
    export namespace Response {
      @ApiModel({ name: 'EntityV1HttpNS.FooMethod.Response.Body' })
      export class Body {
        @ApiProperty()
        status: number;
      }
    }
  }
}

export namespace ThingV1HttpNS {
  export namespace BarMethod {
    export namespace Response {
      @ApiModel({ name: 'ThingV1HttpNS.BarMethod.Response.Body' })
      export class Body {
        @ApiProperty()
        message: string;
      }
    }
  }
}

Now, @nestjs/swagger will generate two Swagger schemas EntityV1HttpNS.FooMethod.Response.Body and ThingV1HttpNS.BarMethod.Response.Body.

Installation

$ npm i --save @0x0c/nestjs-swagger 

Quick Start

Overview & Tutorial

Migration from v3

If you're currently using @nestjs/swagger@3.*, note the following breaking/API changes in version 4.0.

The following decorators have been changed/renamed:

  • @ApiModelProperty is now @ApiProperty
  • @ApiModelPropertyOptional is now @ApiPropertyOptional
  • @ApiResponseModelProperty is now @ApiResponseProperty
  • @ApiImplicitQuery is now @ApiQuery
  • @ApiImplicitParam is now @ApiParam
  • @ApiImplicitBody is now @ApiBody
  • @ApiImplicitHeader is now @ApiHeader
  • @ApiOperation({ title: 'test' }) is now @ApiOperation({ summary: 'test' })
  • @ApiUseTags is now @ApiTags

DocumentBuilder breaking changes (updated method signatures):

  • addTag
  • addBearerAuth
  • addOAuth2
  • setContactEmail is now setContact
  • setHost has been removed
  • setSchemes has been removed (use the addServer instead, e.g., addServer('http://'))

The following methods have been added:

  • addServer
  • addApiKey
  • addBasicAuth
  • addSecurity
  • addSecurityRequirements

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.