Installation & Quickstart
ApiPatch is distributed as a self-contained, precompiled native executable with zero runtime dependencies. No Node.js, Python, or runtime prerequisites are required.
Installation Methods
1. macOS & Linux (Bash / Zsh)
Supports Apple Silicon (M1/M2/M3/M4), Intel macOS, and Linux x64/arm64:
curl -fsSL https://apipatch.fix2ship.dev/install.sh | bash
2. Windows PowerShell
Installs directly to ~/.apipatch/bin/apipatch.exe and registers into User PATH:
irm https://apipatch.fix2ship.dev/install.ps1 | iex
3. Windows Command Prompt (CMD)
curl -fsSL https://apipatch.fix2ship.dev/install.cmd -o install.cmd && install.cmd && del install.cmd
Run apipatch --version in your terminal. You should see apipatch v1.2.2.
Hexagonal Architecture & The 3-Step Lifecycle
ApiPatch separates pure business domain logic (contract diffing, AST symbol tracing, policy evaluation) from platform-specific adapters (filesystem, Git, network, GitHub API).
tsc --noEmit) and test gates; rolls back byte-for-byte if any check fails.Safety Invariants
- Zero Unverified Mutation: ApiPatch never modifies files unless
--yesis provided or run in--prmode. - Atomic Rollback: If a rewritten file introduces a TypeScript error or fails a test gate, the entire transaction is rolled back byte-for-byte and flagged for Manual Review.
- No Guess Application: When endpoints or fields map via fuzzy similarity rather than explicit annotations (e.g.
x-replaced-by), ApiPatch marks the change as aguessand leaves it for developer confirmation.
CLI Commands Reference
Full catalog of primary commands, flags, and usage patterns.
1. apipatch init
Scaffolds apipatch.manifest.json in an existing repository and configures declared upstream APIs.
# Initialize and declare an OpenAPI endpoint
apipatch init --declare-api backend=./schemas/openapi.yaml:openapi
# Initialize with a remote vendor contract
apipatch init --declare-api stripe=https://api.stripe.com/openapi.json:openapi
2. apipatch scan
Performs a read-only audit across package dependencies, API contracts, and security vulnerabilities without altering any files.
# Full scan across all families
apipatch scan --all
# Scan only security vulnerabilities against OSV
apipatch scan --security
# Output machine-readable JSON for CI pipelines
apipatch scan --format json --report-file report.json
3. apipatch plan
Produces an inspectable diff and migration plan showing exactly what package versions will be updated and what AST code edits will be performed.
apipatch plan --packages --strategy minor
apipatch plan --apis --format markdown
4. apipatch apply
Applies approved package bumps, vulnerability patches, or API codemod rewrites. Requires --yes (or --pr).
# Safe package dependency updates with automatic verification
apipatch apply --packages --yes --verify
# Apply breaking API contract rewrites
apipatch apply --apis --yes
# PR-First mode: creates branch, verifies in worktree, and opens GitHub PR
apipatch apply --all --pr --yes --pr-title "chore(deps): autonomous dependency & API updates"
5. apipatch contract
Direct contract-to-contract diffing and AST remediation between two explicit schema files.
apipatch contract \
--contract-old schemas/v1-openapi.json \
--contract-new schemas/v2-openapi.json \
--format json \
--dry-run
6. apipatch update
Self-updater that queries the signed release server, checks minisign signatures, and upgrades the binary in-place.
# Check for updates
apipatch update --dry-run
# Install latest release
apipatch update --yes
Package Dependency & Security Management
ApiPatch supports all major JavaScript/TypeScript package managers with native lockfile AST parsing and transitive vulnerability deduplication.
Supported Ecosystems
| Ecosystem | Manifest | Lockfile | Transitive Resolution |
|---|---|---|---|
| npm | package.json |
package-lock.json (v1, v2, v3) |
Full AST parse + deduplication |
| pnpm | package.json |
pnpm-lock.yaml (v5, v6, v9) |
Inline snapshot parsing |
| yarn | package.json |
yarn.lock (v1 Classic, Berry) |
Resolutions & scope tracking |
| bun | package.json |
bun.lock, bun.lockb |
Native text lockfile format |
Security Vulnerability Scanning
ApiPatch integrates directly with the Open Source Vulnerabilities (OSV) database and GHSA advisories. It inspects every installed package version across both direct dependencies and deep transitive sub-dependencies.
# Scan lockfile for vulnerabilities
apipatch scan --security
# Automatically remediate vulnerabilities by calculating the minimum non-breaking target version
apipatch apply --security --yes
Adding Vendors & Managing API Contracts
Configure upstream third-party APIs (Stripe, GitHub, Discord, Twilio, OpenAI, internal microservices) and track contract baselines across breaking changes.
apipatch.manifest.json Structure
The manifest declares upstream API dependencies, contract types, authentication headers, and explicit route migration mappings:
{
"$schema": "https://apipatch.dev/schemas/manifest.v1.json",
"apis": [
{
"name": "stripe",
"type": "openapi",
"source": "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json",
"headers": {
"Authorization": "Bearer ${STRIPE_API_KEY}"
},
"mappings": {
"POST /charges": "POST /payment_intents"
}
},
{
"name": "github",
"type": "openapi",
"source": "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json"
},
{
"name": "internal-billing",
"type": "openapi",
"source": "./schemas/billing-v2.yaml"
},
{
"name": "catalog",
"type": "graphql",
"source": "./schemas/schema.graphql"
}
]
}
How to Add a New Vendor API
-
Declare via CLI:
COMMAND
apipatch init --declare-api twilio=https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json:openapi -
Establish the Contract Baseline:
Save the current contract snapshot into
apipatch.lock. This establishes the baseline for all future diffs:COMMANDapipatch apply --apis --baseline --yes -
Detect Upstream Breaking Changes:
When the vendor publishes a new schema version, run scan to detect diffs:
COMMANDapipatch scan --apis -
Remediate Call Sites:
COMMAND
apipatch apply --apis --yes
OpenAPI 3.x vs GraphQL SDL Support
- OpenAPI 3.0 & 3.1: Full support for paths, operationIds, parameters (path, query, header), requestBody schemas, response schemas, status codes, and server base paths.
- GraphQL SDL & Introspection: Canonical AST normalization: directives, inputs, mutations, and field renames share one unified cryptographic fingerprint.
AST Data-Flow Remediation Engine
ApiPatch performs compiler-level Abstract Syntax Tree (AST) rewrites using TypeScript Compiler APIs. Code is transformed only where data flow proves the call site connects to the modified API.
1. N-Hop Transitive Wrapper Resolution
In enterprise architectures, applications rarely invoke fetch() directly. ApiPatch resolves up to 5 transitive hops of wrapper functions with cycle detection:
// Level 1: Low-level transport
const inner = (url: string, body: unknown) => fetch(url, { method: "POST", body: JSON.stringify(body) });
// Level 2: Middleware / header injector
const middle = (url: string, body: unknown) => inner(url, body);
// Level 3: Service-layer wrapper
const outer = (url: string, body: unknown) => middle(url, body);
// Business Logic Call-Site:
// Before migration:
outer("/users", { user_name: "alice" });
// Automatically rewritten by ApiPatch:
outer("/users", { userName: "alice" });
2. Fixed-URL Endpoint Wrappers
Helpers that encapsulate a specific URL path are analyzed by binding the target route template to caller parameters:
const postJson = (url: string, payload: unknown) => fetch(url, { method: "POST", body: JSON.stringify(payload) });
const createUser = (payload: unknown) => postJson("/users", payload);
// Before:
createUser({ user_name: "bob" });
// After:
createUser({ userName: "bob" });
3. Class & Object Methods
Class instances (this.post(), apiClient.createUser()) are inspected and resolved as local wrappers before defaulting to generic SDK heuristics.
4. MSW Handler Synchronization
Mock Service Worker (MSW) test handlers are updated alongside consumer code. Dynamic route parameters (:id ↔ {id}), response bodies, and HTTP status codes automatically follow the updated schema.
Enterprise CI/CD & PR Automation
Automate pull requests, prevent false-positive pipeline failures, and export SARIF findings to GitHub Security.
PR-First Mode (apply --pr)
In CI or local developer workflows, apply --pr executes mutations inside an isolated Git worktree, runs the verification gates, commits changes, and opens a Pull Request using gh or the GitHub API:
apipatch apply --all --pr --yes \
--pr-branch apipatch/weekly-dependency-sync \
--pr-title "chore(deps): autonomous dependency & API sync"
CI Exit Codes (ADR 0015)
| Exit Code | Status | Meaning |
|---|---|---|
0 |
SUCCESS | Operation completed cleanly. No findings at or above --fail-on remain. |
1 |
ERROR | Tool or usage error, network fetch timeout, or verification gate failure. |
2 |
FINDINGS | Findings detected at or above --fail-on threshold (e.g. breaking API diffs or CVEs). |
GitHub Code Scanning (SARIF 2.1.0)
Generate SARIF output to populate GitHub's Security tab with precise file locations, line numbers, and rule IDs:
- name: Run ApiPatch Security & Contract Audit
run: |
apipatch scan --all --format sarif --report-file apipatch-results.sarif --fail-on high
- name: Upload SARIF to GitHub Security Tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: apipatch-results.sarif
Air-Gapped & Offline Execution
For strictly air-gapped enterprise build agents, ApiPatch supports offline execution with zero network egress:
apipatch scan --all --offline --no-telemetry