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.
// 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/swaggeryourself. It is an optional peer. Without it, endpoints carry no OpenAPI metadata. - Set the version to 3.1, as the endpoints' schemas are.
- A
standardSchemaConverterof your own passed tocreateDocumentmust returnundefinedfor a vendor it doesn't know. The endpoints' schemas have the vendornestjs-endpoints.
What an endpoint contributes
| In the document | From |
|---|---|
| The operation's id | Its URL in PascalCase, without :param segments: UserCreate |
| Its request body | input, as the component UserCreateInput |
| Its query and path parameters | One per property of query and params |
| Its responses | output, as UserCreateOutput, or UserCreate400Output for another status |
| Its summary and tags | summary, 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:
| Extension | Value |
|---|---|
x-endpoint-kind | query for an endpoint.query(), mutation for an endpoint.mutation() |
x-namespace | The operation's namespace, when it has one |