Libraries
    Preparing search index...

    Class EndpointBuilder<TParams, TBody, TQuery, THeaders, TServices, TPrincipal, TRoles, TResponse, TResponses>

    Type Parameters

    • TParams = {}
    • TBody = undefined
    • TQuery = {}
    • THeaders = {}
    • TServices = {}
    • TPrincipal = undefined
    • TRoles extends string = string
    • TResponse = any
    • TResponses extends Record<number, any> = {}
    Index

    Constructors

    • Type Parameters

      • TParams = {}
      • TBody = undefined
      • TQuery = {}
      • THeaders = {}
      • TServices = {}
      • TPrincipal = undefined
      • TRoles extends string = string
      • TResponse = any
      • TResponses extends Record<number, any> = {}

      Parameters

      • method: string
      • basePath: string
      • pathTemplate: RoutePath
      • bodySchema: SchemaBuilder<any, any, any, any, any> | null
      • querySchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null
      • headerSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null
      • serviceSchemas: Record<string, SchemaBuilder<any, any, any, any, any>> | null = null
      • authRoles: readonly string[] | null = null
      • summary: string | null = null
      • description: string | null = null
      • tags: readonly string[] = []
      • operationId: string | null = null
      • deprecated: boolean = false
      • responseSchema: SchemaBuilder<any, any, any, any, any> | null = null
      • responsesSchemas: Record<number, SchemaBuilder<any, any, any, any, any> | null> | null = null
      • example: unknown = null
      • examples:
            | Record<
                string,
                { description?: string; summary?: string; value: unknown },
            >
            | null = null
      • producesFile: { contentType?: string; description?: string } | null = null
      • produces: Record<string, { schema?: SchemaBuilder<any, any, any, any, any> }> | null = null
      • responseHeaderSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null = null
      • externalDocs: { description?: string; url: string } | null = null
      • links: Record<string, LinkDefinition<any>> | null = null
      • callbacks: Record<string, CallbackDefinition<any>> | null = null

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          TResponses,
      >

    Methods

    • Declare that this endpoint can produce responses in multiple content types.

      Each key is a MIME type. Provide an optional schema to override the default response schema for that type; otherwise the schema from .returns() / .responses() is reused for every declared content type.

      When used alongside .producesFile(), the binary response takes precedence.

      Parameters

      • contentTypes: Record<string, { schema?: SchemaBuilder<any, any, any, any, any> }>

        Map of MIME type → optional schema override.

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          TResponses,
      >

      endpoint.get('/api/items')
      .returns(object({ id: number(), name: string() }))
      .produces({
      'text/csv': {},
      'application/xml': { schema: string() }
      })
    • Declare per-status-code response schemas for OpenAPI generation and handler return-type enforcement.

      Pass null as the schema for body-less codes (e.g. 204).

      Type Parameters

      • const T extends Record<number, SchemaBuilder<any, any, any, any, any> | null>

      Parameters

      • map: T

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          InferResponsesMap<T>,
      >

      const ep = endpoint
      .get('/api/todos/:id')
      .responses({
      200: object({ id: number(), title: string() }),
      404: object({ message: string() }),
      });

      const handler: Handler<typeof ep> = ({ params }) => {
      const todo = todos.get(params.id);
      if (!todo) return ActionResult.notFound({ message: 'Not found' });
      return todo; // plain object → 200
      };