chowbea-axios
Commands

fetch

Fetch OpenAPI spec from remote endpoint and generate types.

The fetch command downloads your OpenAPI specification, caches it locally, and generates TypeScript types and operation functions.

Usage

chowbea-axios fetch [flags]

What It Does

  1. Downloads the OpenAPI spec from your configured endpoint (or loads from local file)
  2. Caches the spec with hash for change detection
  3. Compares with previous version to detect changes
  4. Generates api.types.ts and api.operations.ts
  5. Creates client files if they don't exist

Flags

FlagShortDescriptionDefault
--config-cPath to api.config.tomlAuto-detected
--endpoint-eOverride API endpoint URLFrom config
--spec-file-sUse local spec file instead of remote-
--force-fForce regeneration even if unchangedfalse
--dry-run-nPreview without writing filesfalse
--types-only-Generate only TypeScript typesfalse
--operations-only-Generate only operationsfalse
--quiet-qSuppress non-error outputfalse
--verbose-vShow detailed outputfalse

Examples

Basic Fetch

chowbea-axios fetch

Force Regeneration

# Regenerate even if spec hasn't changed
chowbea-axios fetch --force

Use Local Spec File

chowbea-axios fetch --spec-file ./openapi.json

Override Endpoint

chowbea-axios fetch --endpoint https://api.example.com/docs/swagger.json

Dry Run (Preview)

chowbea-axios fetch --dry-run

Output:

Dry run complete - no files written
Operations found (operations=42)
Would update: app/services/api/_generated/api.types.ts
Would update: app/services/api/_generated/api.operations.ts (156 lines)

Generate Only Types

# Skip operations, only generate api.types.ts
chowbea-axios fetch --types-only

Caching Behavior

The fetch command uses smart caching to avoid unnecessary regeneration:

  1. SHA256 hash of spec content is computed
  2. Compared with cached hash from previous fetch
  3. Skips generation if hashes match (unless --force)

Cache files are stored in _internal/:

  • .api-cache.json - Hash and metadata
  • openapi.json - Cached spec content

Network Retry Logic

If the endpoint is unreachable, fetch will:

  1. Retry 3 times with exponential backoff (1s, 2s, 4s delays)
  2. Fall back to cached spec if available
  3. Report error if no cache exists
│ ⚠ Fetch failed, retrying... (attempt=1, maxAttempts=3, delayMs=1000)
│ ⚠ Fetch failed, retrying... (attempt=2, maxAttempts=3, delayMs=2000)
│ ⚠ All fetch attempts failed, checking for cached spec...
│ ✓ Using cached OpenAPI spec due to network failure

Authentication

For protected spec endpoints, add headers in your config:

api.config.toml
[fetch]
headers = { Authorization = "Bearer $API_TOKEN" }

Headers support environment variable interpolation with $VAR or ${VAR} syntax.

Generated Files

After a successful fetch:

.api-cache.json
openapi.json
api.types.ts
api.operations.ts

Files in _internal/ and _generated/ are overwritten on each fetch. Don't edit them.

When to Use fetch vs generate

Use fetch when...Use generate when...
Your API spec changedYou have a local spec file
First time setupRegenerating from cache
CI/CD pipelinesQuick iteration
Remote endpoint availableWorking offline

Next Steps

On this page