api

Type Aliases

AnyPaths

AnyPaths = object

Defined in: api.ts:11

Base type for OpenAPI paths - accepts any object structure.


DefineOperations

DefineOperations<T> = { [K in keyof T]: OperationEntry }

Defined in: api.ts:36

Define the operations structure for type-safe API bindings. Transforms an operations interface (from openapi-typescript) into a mapped type with proper index signature for TypeScript compatibility.

Type Parameters

T

T extends object = OperationMap

The operations interface from openapi-typescript


OperationBindings

OperationBindings<Paths, Operations> = Record<keyof Operations, { method: HttpMethod; path: Extract<keyof Paths, string>; }>

Defined in: api.ts:53

Maps operation names to their HTTP method and path. Used by plugins to define how friendly operation names map to OpenAPI paths.

Type Parameters

Paths

Paths

The paths interface from openapi-typescript

Operations

Operations extends OperationMap

The operations interface from openapi-typescript

Example

type MyBindings = OperationBindings<paths, operations>;
// { list_users: { method: 'get', path: '/users' }, ... }

OperationEntry

OperationEntry = object

Defined in: api.ts:17

Structure of an OpenAPI operation (endpoint). Matches the shape generated by openapi-typescript.

Properties

parameters?

optional parameters: Record<string, any>

Defined in: api.ts:18

requestBody?

optional requestBody: Record<string, any>

Defined in: api.ts:19

responses

responses: Record<string | number, any>

Defined in: api.ts:20


OperationMap

OperationMap<T> = T extends Record<string, OperationEntry> ? T : any

Defined in: api.ts:27

Type constraint for a map of operation names to their definitions. Used internally to validate operation structures.

Type Parameters

T

T = any

Functions

createOperationBindingsFactory()

createOperationBindingsFactory<Paths, Ops>(): <T>(ops) => T

Defined in: api.ts:75

Creates a type-safe factory for defining operation bindings. The factory validates that each operation's method and path are valid for the given OpenAPI spec.

Type Parameters

Paths

Paths extends object

The paths interface from openapi-typescript

Ops

Ops extends unknown

The operations interface from openapi-typescript

Returns

A factory function that validates and returns the operation bindings

<T>(ops): T

Type Parameters
T

T extends Record<keyof Ops, { method: HttpMethod; path: any; }>

Parameters
ops

T & { [K in string | number | symbol]: T[K] extends { method: M; path: P } ? M extends HttpMethod ? P extends PathsWithMethod<Paths, M<M>> ? { method: M<M>; path: P<P> } : never : never : never }

Returns

T

Example

const bindings = createOperationBindingsFactory<paths, operations>()({
  list_users: { method: 'get', path: '/users' },
  create_user: { method: 'post', path: '/users' },
});