![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
nest-openapi-tools
Advanced tools
A collection of tools to make building and deploying AWS serverless Nest applications AWESOME.
npm install --save nest-openapi-tools @nestjs/swagger swagger-ui-express
This library's goal is to make it as easy as possible to use NestJS with Swagger, also known as OpenAPI. NestJS's Swagger package does not currently generate specification file - rather, it generates the web server with the specification.
This package leverages that tooling to generate a YAML or JSON specification file as well as @openapitools/openapi-generator-cli
to then generate a client. By using this as part of our development experience, we can build our APIs with NestJS's npm run start:dev
running and have a new, fully-setup API client ready to go for our consuming layer (whether this is a SPA app or another API service).
The NestJS OpenAPI docs for @NestJS/Swagger are a fantastic guide to defining your API in code. There are two routes:
These must be complete in order for Nest OpenAPI Tools to function - this package leverages the NestJS Swagger library to generate the server and specification file.
The OpenApiNestFactory simplifies the process of:
To leverage this functionality, add a call to OpenApiNestFactory.configure()
call as demonstrated below.
// main.ts - BEFORE
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
// main.ts - AFTER
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { OpenApiNestFactory } from 'nest-openapi-tools';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await OpenApiNestFactory.configure(
app,
new DocumentBuilder().setTitle('My API'),
);
await app.listen(3000);
}
bootstrap();
This falls back to all defaults provided by Nest OpenAPI Tools to:
./openapi.yaml
../my-api-client
.Note that all of these values can be changed as demonstrated in the section below.
These are the default values when no options are passed in to OpenApiNestFactory. To override these, simply use the configuration object (the third argument in the configure()
call).
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { OpenApiNestFactory } from 'nest-openapi-tools';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await OpenApiNestFactory.configure(app,
new DocumentBuilder()
.setTitle('My API')
.setDescription('An API to do awesome things')
.addBearerAuth(),
{
webServerOptions: {
enabled: true,
path: 'api-docs',
},
fileGeneratorOptions: {
enabled: true,
outputFilePath: './openapi.yaml', // or ./openapi.json
},
clientGeneratorOptions: {
enabled: true,
type: 'typescript-axios',
outputFolderPath: '../typescript-api-client/src',
additionalProperties:
'apiPackage=clients,modelPackage=models,withoutPrefixEnums=true,withSeparateModelsAndApi=true',
openApiFilePath: './openapi.yaml', // or ./openapi.json
skipValidation: true, // optional, false by default
},
}, {
operationIdFactory: (c: string, method: string) => method,
});
await app.listen(3000);
}
bootstrap();
NOTICE! File generation and client generation should be disabled in production as they are costly to startup time.
This project leverages the OpenAPITools/openapi-generator project via the npm package, @openapitools/openapi-generator-cli
which is required to be installed globally. Accordingly, any client generators and configuration supported by this project are usable via Nest OpenAPI Tools.
To help with getting started, Nest OpenAPI Tools provides some classes with helpful defaults.
AxiosClientGeneratorOptions
Author - Kerry Ritter, BeerMoneyDev
Website - https://www.kerryritter.com/, https://www.beermoney.dev/
FAQs
A collection of tools to make building and deploying AWS serverless Nest applications AWESOME.
We found that nest-openapi-tools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.