Catalog npm
Back to packageRELEASE DETAILS

6.3.0

npm

@0x0c/nestjs-swagger

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

Published19 Apr 2023
Direct dependencies35
Transitive dependenciesNot calculated

README

Current package documentation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective

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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 41

Native requirements
35 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
lodash
Environment
{
  "local_name": "lodash",
  "alias": false,
  "peer_metadata": null
}
4.17.21runtime
js-yaml
Environment
{
  "local_name": "js-yaml",
  "alias": false,
  "peer_metadata": null
}
4.1.0runtime
path-to-regexp
Environment
{
  "local_name": "path-to-regexp",
  "alias": false,
  "peer_metadata": null
}
3.2.0runtime
swagger-ui-dist
Environment
{
  "local_name": "swagger-ui-dist",
  "alias": false,
  "peer_metadata": null
}
4.18.2runtime
@nestjs/mapped-types
Environment
{
  "local_name": "@nestjs/mapped-types",
  "alias": false,
  "peer_metadata": null
}
1.2.2runtime
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
29.5.0development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
8.0.3development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
8.38.0development
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
4.18.2development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
29.1.0development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
2.8.7development
supertest
Environment
{
  "local_name": "supertest",
  "alias": false,
  "peer_metadata": null
}
6.3.3development
release-it
Environment
{
  "local_name": "release-it",
  "alias": false,
  "peer_metadata": null
}
15.10.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
5.0.4development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
29.5.0development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
18.15.11development
lint-staged
Environment
{
  "local_name": "lint-staged",
  "alias": false,
  "peer_metadata": null
}
13.2.1development
@nestjs/core
Environment
{
  "local_name": "@nestjs/core",
  "alias": false,
  "peer_metadata": null
}
9.4.0development
@types/lodash
Environment
{
  "local_name": "@types/lodash",
  "alias": false,
  "peer_metadata": null
}
4.14.194development
openapi-types
Environment
{
  "local_name": "openapi-types",
  "alias": false,
  "peer_metadata": null
}
12.1.0development
@nestjs/common
Environment
{
  "local_name": "@nestjs/common",
  "alias": false,
  "peer_metadata": null
}
9.4.0development
@types/js-yaml
Environment
{
  "local_name": "@types/js-yaml",
  "alias": false,
  "peer_metadata": null
}
4.0.5development
swagger-parser
Environment
{
  "local_name": "swagger-parser",
  "alias": false,
  "peer_metadata": null
}
10.0.3development
@commitlint/cli
Environment
{
  "local_name": "@commitlint/cli",
  "alias": false,
  "peer_metadata": null
}
17.6.1development
@fastify/static
Environment
{
  "local_name": "@fastify/static",
  "alias": false,
  "peer_metadata": null
}
6.10.1development
class-validator
Environment
{
  "local_name": "class-validator",
  "alias": false,
  "peer_metadata": null
}
0.14.0development
reflect-metadata
Environment
{
  "local_name": "reflect-metadata",
  "alias": false,
  "peer_metadata": null
}
0.1.13development
class-transformer
Environment
{
  "local_name": "class-transformer",
  "alias": false,
  "peer_metadata": null
}
0.5.1development
eslint-plugin-import
Environment
{
  "local_name": "eslint-plugin-import",
  "alias": false,
  "peer_metadata": null
}
2.27.5development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
8.8.0development
@nestjs/platform-express
Environment
{
  "local_name": "@nestjs/platform-express",
  "alias": false,
  "peer_metadata": null
}
9.4.0development
@nestjs/platform-fastify
Environment
{
  "local_name": "@nestjs/platform-fastify",
  "alias": false,
  "peer_metadata": null
}
9.4.0development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
5.59.0development
@commitlint/config-angular
Environment
{
  "local_name": "@commitlint/config-angular",
  "alias": false,
  "peer_metadata": null
}
17.6.1development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
5.59.0development
@nestjs/core
Environment
{
  "local_name": "@nestjs/core",
  "alias": false,
  "peer_metadata": null
}
^9.0.0peer
@nestjs/common
Environment
{
  "local_name": "@nestjs/common",
  "alias": false,
  "peer_metadata": null
}
^9.0.0peer
@fastify/static
Environment
{
  "local_name": "@fastify/static",
  "alias": false,
  "peer_metadata": {
    "optional": true
  }
}
^6.0.0peer
class-validator
Environment
{
  "local_name": "class-validator",
  "alias": false,
  "peer_metadata": {
    "optional": true
  }
}
*peer
reflect-metadata
Environment
{
  "local_name": "reflect-metadata",
  "alias": false,
  "peer_metadata": null
}
^0.1.12peer
class-transformer
Environment
{
  "local_name": "class-transformer",
  "alias": false,
  "peer_metadata": {
    "optional": true
  }
}
*peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "5b7af2279535c81562070eee4f746fa359b19600",
  "tarball": "https://registry.npmjs.org/@0x0c/nestjs-swagger/-/nestjs-swagger-6.3.0.tgz",
  "fileCount": 209,
  "integrity": "sha512-huOdWmu278Ts0J6mGPUZ5DcrznuQ+55oRYGGc5rp9HMepHmm46ciqpkW/ORYvSub3t4aFxEQWNuyoE8/BWdQcw==",
  "signatures": [
    {
      "sig": "MEUCIFunDtgq8gm9j6gqNB9ieX7xcKwajRCGDTlnJpwgfHGFAiEA+NyesbMXsdrBVTWuuCAKJx2sqUUz7ATDR40lWAXat9c=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 266365,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkP9zjACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmohZQ/+IsFTpk16kGdNGmtB0QD7qMPagbP96cmrtjcCLiDnTZgb8/ik\r\nZp+MweG8/+D6OFQCiDFiACo0t1AasEmP5OnQ7QMtJXwJgUKb+PqtkPWTMDdt\r\nmPSp0hcHImFufVOrzY0j7z/DfvJM5A8hkF+Bhdv2WSICNoqrHZmPuDGzD0Fi\r\n53msy7E+If3Ae/oqYgTuXiS8RRlvEEMdIc8rl3rtlkYzG1CyGa2xFmYhsf+6\r\nobEb9I15z5epyKTE86AguWBwUl93Z1ZlciaCoXBI8qkcJSISkCesHFebhtdm\r\n7vMSWY7uUheCGvmQLgyvu5JWeDNmo5YF05Ppk7WL148WhUI6TonFWmVH2xUs\r\n4b5ZLWTbAw9tlORWlDeDKZM6KIbEufsTWi9Z2QN/PUlTBM5FIGuyELxs9lpA\r\no+wFk2og4GhtudjQVWCAR/TH5qWR49rW9KGHF351Pwjy2BjtYbwmWNqzRo4C\r\n3V1Z80i6KJxSsupBJNP/QRfqt0ub7DFE+vdjfRCqm24NmAa3paHo96/ELc9i\r\n9H7uyztNkaIYuCbnTy7eaYXeOUdSc8Ij/RBiU8YGpEJwi+wJaoFpaZHMjk+S\r\nxu1uq0QcGk+q4+oqf5+T+2ANUMArF8ch6Oi9W//RBG5Qn92jEFhdT9qqGU64\r\n6pioQeorSpthyrB+FIQNGWZjrXOnphDX1W4=\r\n=GT58\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
keycat/nestjs-swagger

Shared repository data · GitHub

License detected in repository
Not collected

Repository

PENDING
nestjs/swagger

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:33 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:349e4d92ec6d71663ad5ec64c343b003733766d3c6a05d76d6149d45901cff6c

Other collected versions

7.4.020 Aug7.1.1113 Sept7.1.815 Aug7.1.74 Aug7.1.62 Aug7.1.429 JulView all collected versions →