Skip to content

OpenAPI ​

nestjs-endpoints needs no OpenAPI document: the generated clients come from the schemas directly. If your app builds one with @nestjs/swagger, its endpoints are in it beside your @Controller() classes, with a component schema for every schema they name.

ts
// src/main.ts
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module.js';

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

  const config = new DocumentBuilder().setTitle('Shop API').setOpenAPIVersion('3.1.1').build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

  await app.listen(3000);
}
void bootstrap();
  • Install @nestjs/swagger yourself. It is an optional peer. Without it, endpoints carry no OpenAPI metadata.
  • Set the version to 3.1, as the endpoints' schemas are.
  • A standardSchemaConverter of your own passed to createDocument must return undefined for a vendor it doesn't know. The endpoints' schemas have the vendor nestjs-endpoints.

What an endpoint contributes ​

In the documentFrom
The operation's idIts URL in PascalCase, without :param segments: UserCreate
Its request bodyinput, as the component UserCreateInput
Its query and path parametersOne per property of query and params
Its responsesoutput, as UserCreateOutput, or UserCreate400Output for another status
Its summary and tagssummary, and tags added to one tag from its router

The router's tag is its namespace, joined with /, such as shop/recipes. Without a namespace it is the URL up to the last segment, without :param segments: /recipes/1/view is tagged recipes.

A schema with a .meta({ id }) is a component under that id. See Transforms in output schemas for an output that uses .transform().

Your own generator ​

Most endpoints are POSTs, so the HTTP method doesn't say which are reads. For a generator run against the document, such as Kubb, orval or one for another language, each operation carries two extensions:

ExtensionValue
x-endpoint-kindquery for an endpoint.query(), mutation for an endpoint.mutation()
x-namespaceThe operation's namespace, when it has one

Released under the MIT License.