Skip to main content

@rtorcato/api-ts-rest-express v1.0.0

Interfaces

OpenApiConfig

Defined in: index.ts:12

Properties

info

info: object

Defined in: index.ts:13

title

title: string

version

version: string

description?

optional description?: string

options?

optional options?: object

Defined in: index.ts:15

Extra generateOpenApi options, e.g. { setOperationId: true }.

mount?

optional mount?: Omit<MountOpenAPIOptions, "doc">

Defined in: index.ts:17

Overrides for the docs mount (paths, UI, theme) — doc is supplied for you.


MountTsRestOptions

Defined in: index.ts:20

Properties

contract

contract: AppRouter

Defined in: index.ts:21

router

router: unknown

Defined in: index.ts:27

The implemented router from initServer().router(contract, handlers) — that call already type-checks the handlers against the contract, so it's accepted loosely here.

endpointOptions?

optional endpointOptions?: TsRestExpressOptions<AppRouter>

Defined in: index.ts:29

Passed to createExpressEndpoints (globalMiddleware, responseValidation, …).

openapi?

optional openapi?: OpenApiConfig

Defined in: index.ts:31

Generate an OpenAPI 3.1 doc from the contract and serve it (Scalar by default).

Functions

mountTsRest()

mountTsRest(app, options): void

Defined in: index.ts:47

Mount a ts-rest contract on an Express app/router and, optionally, serve its OpenAPI docs — one call wiring @ts-rest/express + @ts-rest/open-api into the api-common Scalar docs (@rtorcato/api-openapi-express).

Parameters

app

IRouter

options

MountTsRestOptions

Returns

void

Example

const s = initServer()
const router = s.router(contract, { getUser: async ({ params }) => ({ status: 200, body:}) })
mountTsRest(app, { contract, router, openapi: { info: { title: 'My API', version: '1.0.0' } } })
// → contract routes are live; GET /openapi.json + GET /docs (Scalar)