Skip to main content

BaseOpenAPIRoute

BaseOpenAPIRoute exposes the OpenAPI specification that service-core builds automatically from your @Route/@Get/@Post/etc. decorated classes and the @Summary/@Description/@Returns documentation decorators on them, as an interactive Swagger UI page, and as raw JSON or YAML.

import { BaseOpenAPIRoute, RouteDecorators } from "@rapidrest/service-core";
const { Route } = RouteDecorators;

@Route("/openapi")
export class OpenAPIRoute extends BaseOpenAPIRoute {}

The CLI scaffold generates exactly this at src/routes/OpenAPIRoute.ts, mounted at /openapi.

Endpoints​

FunctionHTTP Method + PathWhat it does
getHTMLGET /openapiSwagger UI, rendered from an inline HTML page that loads swagger-ui-dist from a CDN (no npm dependency required).
getJSONGET /openapi/jsonThe raw OpenAPI specification as JSON.
getYAMLGET /openapi/yamlThe raw OpenAPI specification as YAML.

None of the three endpoints requires authentication by default. Treat the specification as public unless your API itself is private, in which case apply @Auth or @Protect to the subclass the same way you would for any other route.

What ends up in the spec​

The specification is assembled from the same decorators you're already using to define routes. There's no separate schema to maintain:

  • @Route, @Get, @Post, @Put, @Delete, etc. determine the paths and HTTP methods.
  • @Summary and @Description populate each operation's summary and description.
  • @Returns documents the response shape.
  • @Model and your persistence-layer model classes (see Models & Persistence) contribute the request/response schemas.

Because generation happens from live code rather than hand-maintained annotations, the spec /openapi serves is always in sync with the routes actually registered on the running server.