Skip to main content

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

Interfaces

OpenApiConfig

Defined in: index.ts:14

Properties

info

info: object

Defined in: index.ts:15

title

title: string

version

version: string

description?

optional description?: string

options?

optional options?: object

Defined in: index.ts:17

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

mount?

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

Defined in: index.ts:19

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


MountTsRestOptions

Defined in: index.ts:22

Properties

contract

contract: AppRouter

Defined in: index.ts:23

router

router: unknown

Defined in: index.ts:29

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:31

Passed to createExpressEndpoints (globalMiddleware, responseValidation, …).

openapi?

optional openapi?: OpenApiConfig

Defined in: index.ts:33

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

Type Aliases

RestRequest

RestRequest<T> = ServerInferRequest<T>

Defined in: index.ts:72

Server-side inferred request shape (params, query, body, headers) for a contract or route.

Type Parameters

T

T extends AppRouter | AppRoute


RestResponse

RestResponse<T> = ServerInferResponses<T>

Defined in: index.ts:74

Server-side inferred { status, body } union for a contract or route's responses.

Type Parameters

T

T extends AppRouter | AppRoute

Variables

defaultErrorSchema

const defaultErrorSchema: any

Defined in: index.ts:81

Zod schema for api-common's error envelope ({ error, code, message, stack? }), the exact body emitted by @rtorcato/api-errors-express. Re-exported so contracts and handlers reference one source of truth.

Functions

mountTsRest()

mountTsRest(app, options): void

Defined in: index.ts:49

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).

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)

Parameters

app

IRouter

options

MountTsRestOptions

Returns

void


withDefaultErrors()

withDefaultErrors<T>(responses): Omit<DefaultErrorResponses, keyof T> & T

Defined in: index.ts:103

Attach the standard 400/404/500 error responses to a ts-rest route's responses map, so every contract documents the shared error envelope without repeating it. Statuses you define yourself win — pass a 400 and it overrides the default.

Example

getUser: {
method: 'GET',
path: '/users/:id',
responses: withDefaultErrors({ 200: UserSchema }),
}

Type Parameters

T

T extends Record<number, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>

Parameters

responses

T

Returns

Omit<DefaultErrorResponses, keyof T> & T