@setu-ts/openapi-plugin — API documentation and Swagger UI
Add it: setu add openapi adds the dependency and inserts OpenApiPlugin() in recognized
scaffolds (already registered in REST projects). It provides CAPABILITIES.OPENAPI
(IOpenApiService).
Serve a spec with bearer-auth documentation
Configure the existing registration in setu.config.ts:
import { OpenApiPlugin } from "@setu-ts/openapi-plugin";
app.register(OpenApiPlugin({
title: "Orders API",
version: "1.0.0",
securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } },
security: [{ bearerAuth: [] }],
swagger: { assets: "cdn" },
}));
Document an explicitly public route
import type { IRouterApi } from "@setu-ts/common";
export function registerStatusRoutes(router: IRouterApi): void {
router.get("/status", {
schema: { summary: "Service status", tags: ["Status"], security: [] },
handler: (ctx) => ctx.response.json({ ok: true }),
});
}
Behaviour the types do not show
endpointdefaults to/docs,specEndpointto/openapi.json; served documentation and self-hosted asset routes are excluded from the generated document.swaggerdefaults totruewith self-hosted assets: this needsswagger-ui-distand a runtime filesystem. Missing assets fail registration. The CDN mode above avoids that filesystem need.titledefaults to"API"andversionto"1.0.0".securitydescribes requirements; it does not enforce authentication. Routesecurity: []overrides the document default. A required scheme absent fromsecuritySchemesrefuses startup.deriveRequestSchemasandderiveResponseStatusdefault totrue: validation metadata supplies request schemas and decorated handler metadata supplies response status.excludeOwnersdefaults to the health and metrics plugins;excludematches fully resolved route patterns, including group prefixes.
Other options
swagger: falsedisables the UI;swagger.assetsalso accepts a custombaseUrlobject.descriptionandserversdescribe the API;excludeOwners: []includes infrastructure routes.deriveSecurity: { scheme }derives requirements from branded guards; the scheme must be declared.IOpenApiService.getSpecreads the document andaddSchemacontributes a named schema.