Generate Tools from an OpenAPI Spec
You have an API spec and you want agent tools. Forge reads OpenAPI v3 (or Swagger 2.0) definitions, extracts the operations you pick, and generates type-safe TypeScript capabilities with auth handling baked in. This walkthrough uses a Zendesk Support API spec as the running example.Prerequisites
- A valid OpenAPI v3 or Swagger 2.0 spec file (JSON or YAML)
- The Svantic CLI installed (
npm install -g @svantic/cli)
Step 1: List Available Operations
Before generating anything, inspect what the spec offers:operationId when available, otherwise from the method and path.
Step 2: Generate Specific Tools
Pick the operations you need with--pick:
./tools/:
| File | Contents |
|---|---|
zendesk.capabilities.ts | One function per picked operation, with typed parameters and HTTP calls |
zendesk.triggers.ts | Webhook/schedule trigger stubs (only if the spec defines callbacks or x-webhooks) |
zendesk.tool-spec.yaml — the intermediate Tool Spec that you can inspect, edit, and regenerate from.
Step 3: Review the Generated Code
The capabilities file exports one function per tool:Step 4: Use the Tools in Your Agent
Register the generated capabilities with an agent:Programmatic Usage
Use the SDK directly instead of the CLI:Listing operations programmatically
Auth Detection
Forge reads thesecuritySchemes section of your OpenAPI spec and maps it to auth configuration automatically:
| OpenAPI Security Scheme | Generated Auth Config |
|---|---|
type: http, scheme: bearer | { type: 'bearer', env: '<DOMAIN>_API_TOKEN' } |
type: apiKey, in: header | { type: 'api_key', env: '<DOMAIN>_API_KEY', header: '<name>' } |
type: http, scheme: basic | { type: 'basic', env: '<DOMAIN>_USERNAME' } + <DOMAIN>_PASSWORD |
type: oauth2 | { type: 'oauth2', env: '<DOMAIN>_CLIENT_ID' } + related env vars |
env values are suggestions. Override them in the Tool Spec YAML or in the generated code.
Overriding auth at generation time
Swagger 2.0 Support
Forge accepts Swagger 2.0 specs. They are automatically converted to OpenAPI 3.0 internally before generation. The conversion handles:definitionstocomponents/schemasbasePath+hosttoservers[0].urlsecurityDefinitionstosecuritySchemes
swagger2openapi and pass the v3 file to Forge.
Filtering Operations
Beyond--pick, you can filter by tag or path prefix:
Regenerating After Spec Changes
If the upstream API spec changes, regenerate from the updated file. Forge overwrites the capabilities and Tool Spec YAML but preserves any file named*.custom.ts in the output directory, so you can keep manual overrides safe.
