Getting Started¶
This guide walks you through installing api-style-spec and linting your first OpenAPI specification.
Installation¶
From Source (Go)¶
Verify Installation¶
Your First Lint¶
Create a simple OpenAPI specification:
# openapi.yaml
openapi: "3.1.0"
info:
title: My API
version: "1.0.0"
paths:
/user:
get:
responses:
"200":
description: OK
Run the linter:
You'll see output like:
API Style Lint Report
=====================
Status: FAIL
Errors: 1, Warnings: 2, Info: 0, Hints: 0
Errors:
- [URI-001] Use plural resource names
$.paths['/user']
Warnings:
- [operation-description] operation method `GET` is missing a description
$.paths['/user'].get
Understanding Violations¶
Each violation includes:
| Field | Description |
|---|---|
| Rule ID | Unique identifier (e.g., URI-001) |
| Message | Human-readable explanation |
| Path | JSON path to the violation location |
| Severity | error, warn, info, or hint |
Fixing Violations¶
Update your spec to fix the violations:
# openapi.yaml
openapi: "3.1.0"
info:
title: My API
version: "1.0.0"
description: A sample API
paths:
/users: # Changed from /user to /users (plural)
get:
summary: List users
description: Returns a list of all users
operationId: listUsers
responses:
"200":
description: OK
Run again:
API Style Lint Report
=====================
Status: PASS
Errors: 0, Warnings: 0, Info: 0, Hints: 0
No violations found.
Using Different Profiles¶
api-style-spec includes profiles based on industry guidelines:
# Use Azure/Microsoft guidelines
api-style lint openapi.yaml --profile azure
# Use Google API Design Guide
api-style lint openapi.yaml --profile google
# Use Zalando RESTful Guidelines
api-style lint openapi.yaml --profile zalando
See Using Profiles for details on each profile.
Output Formats¶
Text (default)¶
JSON¶
SARIF (for IDE integration)¶
Combined Analysis¶
For comprehensive review including LLM-based semantic analysis:
# Requires ANTHROPIC_API_KEY
export ANTHROPIC_API_KEY=sk-ant-...
api-style analyze openapi.yaml --profile azure
This combines:
- Deterministic linting (fast, CI-friendly)
- LLM evaluation (semantic analysis of design quality)
- GO/NO-GO decision for production readiness
Configuration File¶
Create .api-style.yaml in your project root to configure default options:
# .api-style.yaml
profile: azure
level: silver
include:
- "openapi.yaml"
- "**/api.yaml"
exclude:
- "**/generated/**"
exceptions:
- rule: URI-001
paths: ["/legacy/**"]
reason: "Legacy API cannot be changed"
CLI flags override config file settings. See the Configuration Reference for all options.
Multi-File Linting¶
Lint multiple files at once:
# Glob patterns
api-style lint api/*.yaml
# Recursive directory search
api-style lint . --recursive
# Multiple arguments
api-style lint openapi.yaml swagger.yaml
Watch Mode¶
Continuously lint as you edit:
The watcher:
- Runs initial lint on startup
- Re-lints when files change
- Shows timestamps for each run
- Exits cleanly with Ctrl+C
Git Pre-Commit Hook¶
Block commits with API style violations:
This installs a pre-commit hook that lints staged OpenAPI files. See Hooks Reference for details.
Next Steps¶
- Automated API Governance - Set up AI-first API design with 100% automated enforcement
- Using Profiles - Understand built-in style profiles
- Custom Rules - Create your own rules
- CLI Reference - Complete command documentation