Skip to main content
The Openapi module generates incur command entries from OpenAPI 3.x specifications, allowing you to mount REST APIs as CLI commands.

Functions

generateCommands

Generates incur command entries from an OpenAPI spec. Resolves all $ref pointers.
spec
OpenAPISpec
required
OpenAPI 3.x specification object
fetch
FetchHandler
required
Fetch handler function that processes requests
options.basePath
string
Base path to prepend to all endpoint paths
return
Promise<Map<string, GeneratedCommand>>
Map of command names to generated command entries

Example

Types

OpenAPISpec

A minimal OpenAPI 3.x spec shape. Accepts both hand-written specs and generated ones (e.g., from @hono/zod-openapi).

FetchHandler

A fetch handler function.
req
Request
required
Standard Web API Request object
return
Response | Promise<Response>
Standard Web API Response object

GeneratedCommand

A generated command entry compatible with incur’s internal CommandEntry.
args
z.ZodObject<any>
Zod schema for path parameters
description
string
Command description from summary or description field
options
z.ZodObject<any>
Zod schema for query parameters and request body properties
run
(context: any) => any
required
Command handler function

How It Works

Schema Mapping

The generator maps OpenAPI parameters and request bodies to incur command schemas: Path parametersargs schema
Query parametersoptions schema
Request body → merged into options schema

Command Naming

Commands are named using operationId if present, otherwise generated from method and path:

Type Coercion

CLI arguments are always strings, so the generator adds coercion for numeric and boolean types:

Error Handling

The generated handler uses context.error() for non-2xx responses: