@openapi-ui/nestjs-openapi-ui
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

NestJS-OpenAPI-UI Middleware

Version Downloads

Install

npm install @openapi-ui/nestjs-openapi-ui

pnpm install @openapi-ui/nestjs-openapi-ui

Usage

Set up NestJS and set up NestJS Swagger and pass an OpenAPI/Swagger spec to the openApiUIReference middleware:

import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"
import { openApiUIReference } from "@openapi-ui/nestjs-openapi-ui"

const app = await NestFactory.create(AppModule)

const config = new DocumentBuilder()
  .setTitle('Cats example')
  .setDescription('The cats API description')
  .setVersion('1.0')
  .addTag('cats')
  .build()

const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup("swagger", app, document, {
		jsonDocumentUrl: "/openapi.json",
	});

app.use(
  "/openapi",
  openApiUIReference({
    specPath: "/openapi.json",
  }),
)

try example

Themes

import { openApiUIReference } from '@openapi-ui/nestjs-openapi-ui'

app.use(
  "/openapi",
  openApiUIReference({
    specPath: "/openapi.json",
    theme: 'light', // light or dark
  }),
)

Custom CDN

You can use a custom CDN ,default is https://unpkg.com/openapi-ui-dist.

import { openApiUIReference } from '@openapi-ui/nestjs-openapi-ui'

app.use(
  "/openapi",
  openApiUIReference({
    specPath: "/openapi.json",
    cdn: 'https://registry.npmmirror.com/openapi-ui-dist/latest/files',
  }),
)

Readme

Keywords

none

Package Sidebar

Install

npm i @openapi-ui/nestjs-openapi-ui

Weekly Downloads

4

Version

0.1.0

License

none

Unpacked Size

8.5 kB

Total Files

7

Last publish

Collaborators

  • rookie-luochao