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.
OpenAPISpec
required
OpenAPI 3.x specification object
FetchHandler
required
Fetch handler function that processes requests
string
Base path to prepend to all endpoint paths
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.Request
required
Standard Web API Request object
Response | Promise<Response>
Standard Web API Response object
GeneratedCommand
A generated command entry compatible with incur’s internal CommandEntry.z.ZodObject<any>
Zod schema for path parameters
string
Command description from
summary or description fieldz.ZodObject<any>
Zod schema for query parameters and request body properties
(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 parameters →args schema
options schema
options schema
Command Naming
Commands are named usingoperationId 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 usescontext.error() for non-2xx responses:
Related
- Fetch - Low-level fetch utilities
- Mounting APIs - Guide to mounting REST APIs
- OpenAPI Integration - Advanced OpenAPI usage

