NestJS decorators and functions
Signatures of every @Docs* decorator and every function exported by @orbitdocs/nestjs.
@orbitdocs/nestjs adds a few optional decorators on top of @nestjs/swagger, plus functions to build the document and serve the docs. The decorators only write OpenAPI extensions or Swagger responses. They never change routing, guards or behavior.
import { DocsContent, DocsErrors, DocsExtension, DocsHidden, DocsOperation, DocsSamples, mountOrbitDocs } from '@orbitdocs/nestjs';Every Swagger decorator (@ApiOperation, @ApiTags, @ApiResponse, @ApiProperty, @ApiBearerAuth, @ApiExcludeEndpoint, …) and the Swagger CLI plugin drive the docs as usual. With routes: 'all' you need none of the decorators below.
Decorators
| Decorator | Applies to | Writes |
|---|---|---|
@DocsOperation(options?) | Route method | x-orbitdocs |
@DocsHidden() | Route method | x-orbitdocs: { hidden: true } |
@DocsErrors(errors) | Route method | One Swagger @ApiResponse per status |
@DocsSamples(samples) | Route method | x-codeSamples |
@DocsExtension(key, value) | Route method | Any x- extension |
@DocsContent(markdown, position?) | Route method | x-orbitdocs-content |
@DocsOperation
function DocsOperation(options?: DocsOperationOptions)Puts a route in the public reference. With routes: 'opt-in' (the default) only routes with this decorator appear.
Prop
Type
@Post()
@DocsOperation({ group: 'Bookings', title: 'Create a booking', order: 1 })
create(@Body() dto: CreateBookingDto) {}When title is set and Swagger's summary differs, the summary becomes the description (unless one is given).
@DocsHidden
function DocsHidden()Keeps a route out of the reference even when it is marked or routes: 'all' is on. Same effect as Swagger's @ApiExcludeEndpoint() for the docs.
@DocsErrors
function DocsErrors(errors: Partial<Record<number, string>>)Documents the errors one route returns, and when. Generic codes are added automatically when standardErrors is on: 400 with input, 401 and 403 when secured, 404 with a path parameter, 500. List what this route adds or says more about.
@DocsErrors({ 404: 'No booking with this id.', 409: 'The flight is full.' })@DocsSamples
function DocsSamples(samples: CodeSample[])
interface CodeSample {
lang: string; // highlighting: typescript, python, go, shell…
label?: string; // tab label; defaults to lang
source: string;
}Hand-written samples, shown before the generated ones. A hand-written sample with the same label as a generated one replaces it.
@DocsExtension
function DocsExtension(key: `x-${string}`, value: unknown)Any OpenAPI x- extension on the operation, for plugins or your own tools.
@DocsContent
function DocsContent(markdown: string, position?: ContentPosition)
type ContentPosition = 'before-parameters' | 'after-description' | 'after-responses' | 'aside';| Parameter | Default | What it is |
|---|---|---|
markdown | required | Markdown shown in the operation's section. GitHub alerts (> [!WARNING]) render as callouts. |
position | 'after-description' | Where it appears. |
@DocsContent('> [!WARNING]\n> Cancelling within 24 h of departure is not refunded.', 'before-parameters')For longer content with components, use reference/<api>/<operation>.mdx. See Operation content.
mountOrbitDocs
function mountOrbitDocs(app: INestApplication, options: MountOrbitDocsOptions): voidServes the static docs build from the Nest app (Express adapter only). Call it in main.ts before app.listen(). Throws when root doesn't exist (OrbitDocs build not found at …) or the adapter isn't Express.
Prop
Type
See Inside your Nest app.
Document helpers
For building the document yourself, for example in a test or a custom script:
function createFullDocument(app: INestApplicationContext, base?: Omit<OpenAPIObject, 'paths'>): Document
function createOrbitDocument(app: INestApplicationContext, options?: OrbitDocumentOptions): DocumentcreateFullDocumentreturns everythingSwaggerModule.createDocumentproduces (withdeepScanRoutes).basedefaults to titleAPI, version1.0.0.createOrbitDocumentreturns the public document: marked routes only, readable operation ids, standard errors and unused schemas pruned.
Prop
Type
A schema that is referenced but never defined throws DanglingReferenceError. In NestJS, register it with @ApiExtraModels() or type the property.
extract
function extract(request: ExtractRequest): Promise<ExtractResult>The function behind orbitdocs extract. It boots a compiled module in preview mode and writes the filtered document. The CLI calls it through @orbitdocs/nestjs/extract-cli; you rarely need it directly. See Extraction.
Exported types
DocsOperationOptions, CodeSample, MountOrbitDocsOptions, OrbitDocumentOptions, ExtractRequest, ExtractResult, and from @orbitdocs/openapi: ORBIT_EXTENSION ('x-orbitdocs'), OrbitMarker, Stability.

