Standards-backed REST API design rules paired with a zero-dependency OpenAPI 3.0/3.1 JSON and YAML validator, breaking-change diff checker, GitHub Action, and CI violation reports.
Quick Start CLI | GitHub Action | Live Browser Validator | 44 Core Rules | Guides | FAQ
Most API design principles repositories (such as Haufe-Lexware API Style Guide) publish Markdown checklists for developers to read manually. Code reviewers still miss inconsistent error payloads, missing Idempotency-Key headers, and unbounded arrays under deadline pressure.
api-design-principles turns those conventions into checks you can run locally and in Pull Requests:
- Practical handbook with 44 rules (32 automated in OpenAPI lint + 12 architectural standards) mapped to
RFC 9110,RFC 9457(Problem Details),RFC 8594(Sunset),RFC 9111(Caching),RFC 9700(OAuth 2.1),RFC 9745(Deprecation),IETF Idempotency-Key,IETF RateLimit,Google AIP, and theOWASP API Security Top 10. - Zero-dependency OpenAPI 3.0/3.1 validator (
api_validator.py) supporting both JSON and YAML specs in standard library Python 3.9+, plus a browser-based validator. - Breaking-change detector (
--diff) to catch removed endpoints, changed property or parameter types, newly required parameters, and narrowed enums before merge. - GitHub Action (
action.yml) with five built-in industry presets (google-aip,stripe-style,owasp-api-top10,strict-public-api,zalando), Markdown Job Summaries, and SARIF 2.1.0 output for GitHub Code Scanning.
| Capability | Static Style Guides (Haufe-Lexware, docs) | Generic Linters (Spectral CLI) | api-design-tools/api-design-principles |
|---|---|---|---|
| Handbook with HTTP/JSON examples | Yes (read-only) | No (write your own rules) | 44 RFC-backed rules with bad/good examples |
| OpenAPI 3.0 / 3.1 CLI (JSON + YAML) | No | Requires Node.js + npm | Zero-dependency Python 3.9+ stdlib |
Built-in presets (google-aip, stripe-style, owasp) |
No | External rulesets | Included in presets/ |
Breaking-change diff (--diff) |
No | Separate tool needed | Built in |
| GitHub Action + SARIF 2.1.0 + Step Summary | No | Manual wiring | Built-in action.yml |
| Browser validator UI | No | No | Client-side GitHub Pages tool |
git clone https://github.com/api-design-tools/api-design-principles.git
cd api-design-principles
# Validate reference JSON and YAML specs (Score: 100/100)
python3 api_validator.py --spec examples/orders-api-good.openapi.json --fail-on warning
python3 api_validator.py --spec examples/orders-api-good.openapi.yaml --preset strict-public-api
# Inspect violations on the flawed example as Markdown
python3 api_validator.py --spec examples/orders-api-bad.openapi.json --format markdown --fail-on none
# Detect breaking contract changes between two revisions
python3 api_validator.py --diff base.openapi.yaml head.openapi.yaml --format markdown
# Export SARIF 2.1.0 for GitHub Code Scanning
python3 api_validator.py --spec openapi.json --format sarif --output api-design.sarifYou can also paste or upload any OpenAPI JSON or YAML file in the Interactive Browser Validator.
Add .github/workflows/api-design.yml to block breaking changes and rule errors in Pull Requests and publish a violation report in the workflow summary:
name: API Design Principles Check
on:
pull_request:
paths:
- "**/openapi*.*"
- ".api-rules.json"
jobs:
api-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate OpenAPI Specification
uses: api-design-tools/api-design-principles@v1
with:
spec: "services/**/openapi.yaml"
preset: "stripe-style"
config: ".api-rules.json"
fail-on: "error"
report-format: "markdown"
output-file: "api-design-report.md"
write-summary: "true"Inputs: spec, preset (google-aip, stripe-style, owasp-api-top10, strict-public-api, zalando), config, diff-base, fail-on (error, warning, none), report-format (markdown, json, sarif, text), output-file, write-summary. Outputs: score (0-100), errors, warnings, passed, report-path.
All 44 rules live in rules.json. The 32 rules marked Auto run against OpenAPI specs in api_validator.py, the browser validator, and the GitHub Action.
| ID | Mode | Severity | Principle & Standard | Bad Example | Good Example |
|---|---|---|---|---|---|
ADP-001 |
Auto | ERROR |
Plural resource nouns, no CRUD verbs (RFC 9110 §9) |
GET /v1/getOrders |
GET /v1/orders |
ADP-002 |
Auto | WARN |
Lowercase kebab-case URI segments (Google AIP-122) |
/v1/orderItems |
/v1/order-items |
ADP-003 |
Auto | WARN |
No trailing slashes (RFC 3986) |
GET /v1/orders/ |
GET /v1/orders |
ADP-004 |
Auto | ERROR |
Explicit major API versioning (AIP-185) |
GET /orders |
GET /v1/orders |
ADP-005 |
Auto | ERROR |
GET/HEAD must never declare requestBody (RFC 9110 §9.3.1) |
GET + JSON body |
GET ?status=paid |
ADP-006 |
Auto | WARN |
DELETE returns 204/202, no required body (RFC 9110 §9.3.5) |
DELETE + body -> 200 |
DELETE /v1/orders/{id} -> 204 |
ADP-007 |
Auto | ERROR |
POST creation returns 201 (Location) or 202 (RFC 9110) |
POST /v1/orders -> 200 |
201 Created + Location |
ADP-018 |
Auto | INFO |
Deprecation and Sunset headers (RFC 8594 / RFC 9745) |
deprecated: true only |
Sunset: Wed, 31 Dec 2026... |
ADP-020 |
Auto | WARN |
PATCH for partial updates + ETag/If-Match (RFC 7396) |
Unconditional PUT |
PATCH + If-Match |
| ID | Mode | Severity | Principle & Standard | Bad Example | Good Example |
|---|---|---|---|---|---|
ADP-008 |
Auto | ERROR |
Use application/problem+json for 4xx/5xx (RFC 9457) |
{ "msg": "bad" } |
{ "type": "...", "title": "...", "status": 400 } |
ADP-009 |
Auto | ERROR |
Explicit 4xx / default error responses (OpenAPI 3.1) |
Only 200 documented |
200, 400, 401, 404, 429 |
ADP-010 |
Auto | ERROR |
Collection GET must support pagination (OWASP API4) |
Unbounded array | ?cursor=...&limit=25 |
ADP-011 |
Auto | WARN |
Prefer keyset/cursor over offset pagination (AIP-158) |
?offset=50000 |
?cursor=ord_01J9Z&limit=25 |
ADP-012 |
Auto | ERROR |
Idempotency-Key on POST mutations (IETF Draft) |
POST /v1/orders raw |
Idempotency-Key: <uuid> |
ADP-013 |
Auto | WARN |
429 Too Many Requests + RateLimit-* headers (RFC 6585) |
Undocumented throttling | 429 + Retry-After + RateLimit-* |
| ID | Mode | Severity | Principle & Standard | Bad Example | Good Example |
|---|---|---|---|---|---|
ADP-014 |
Auto | ERROR |
Enforce https:// server URLs (OWASP API8:2023) |
http://api.example.com |
https://api.example.com/v1 |
ADP-015 |
Auto | ERROR |
Declare securitySchemes and operation auth (OWASP API2) |
Missing auth definitions | BearerAuth (OAuth2/JWT) |
ADP-016 |
Auto | WARN |
Never pass API keys or tokens in query strings (RFC 6750) |
?api_key=sk_live_... |
Authorization: Bearer ... |
ADP-017 |
Auto | WARN |
Unique operationId and concise summary (OpenAPI / MCP) |
Missing/duplicate IDs | operationId: listOrders |
ADP-019 |
Auto | WARN |
Concrete example on media types/schemas (OpenAPI 3.1) |
Schema without example | Concrete JSON example |
ADP-021 |
Auto | ERROR |
Bound strings (maxLength) and arrays (maxItems) (OWASP API4) |
Unbounded type: array |
maxItems: 50, maxLength: 128 |
ADP-022 |
Auto | INFO |
ISO 8601 UTC format: date-time timestamps (RFC 3339) |
created_at: { type: string } |
format: date-time |
ADP-028 |
Auto | INFO |
Explicit Cache-Control / ETag on GET 200 (RFC 9111) |
Missing cache headers | Cache-Control + ETag |
ADP-029 |
Auto | ERROR |
Integer minor units + ISO 4217 currency (ISO 4217) |
amount: { type: number } |
amount_minor: 1999, currency: "USD" |
ADP-030 |
Auto | INFO |
X-Request-Id / traceparent response correlation (W3C) |
Generic error without ID | X-Request-Id response header |
ADP-033 |
Auto | WARN |
info.contact, info.license, and operation tags (OpenAPI 3.1) |
Untyped untagged ops | info.contact + domain tags |
ADP-034 |
Auto | WARN |
minimum & maximum bounds on numbers (OWASP API4) |
Unbounded limit integer |
minimum: 1, maximum: 100 |
ADP-035 |
Auto | WARN |
additionalProperties: false on input DTOs (OWASP API3) |
Open input object | additionalProperties: false |
ADP-036 |
Auto | ERROR |
Declare every {var} as in: path, required: true (RFC 6570) |
Missing path param spec | { name: "id", in: "path", required: true } |
ADP-037 |
Auto | WARN |
Structured JSON media types (RFC 8259) |
*/* or text/plain |
application/json / problem+json |
ADP-038 |
Auto | INFO |
PascalCase schemas and single property case style (Zalando #118) |
Mixed order_id + createdAt |
Uniform snake_case + OrderPage |
ADP-039 |
Auto | WARN |
Cap :batch maxItems <= 100 and document 207 (AIP-231) |
Unbounded batch -> 200 |
maxItems: 100 + 207 Multi-Status |
ADP-023..027, 031..032, 040..044 |
Arch | MIXED |
BOLA/IDOR scoping, ULID/UUIDv7 IDs, signed webhooks, 202 async jobs, additive diffs, REST vs GraphQL vs gRPC, MCP tools, OpenAPI 3.1 webhooks, GraphQL limits, gRPC tags/deadlines, OAuth 2.1 PKCE, Sunset rollout |
Unsigned webhooks, unguarded GraphQL | HMAC-SHA256, OAuth 2.1 PKCE, reserved tags |
Running python3 api_validator.py --spec examples/orders-api-bad.openapi.json --format markdown produces a report listing detected errors and warnings:
## API Design Principles Validation Report
### `examples/orders-api-bad.openapi.json` (Legacy Anti-Pattern Orders API): FAIL, Score `0/100`
- OpenAPI Version: `3.0.3` | Operations Checked: `4`Platform teams can maintain one baseline config (see .api-rules.example.json) or choose a built-in preset from presets/:
python3 api_validator.py \
--spec "services/*/openapi.*" \
--preset google-aip \
--config .api-rules.example.json \
--format json \
--output reports/org-api-audit.jsonUse plural resource nouns and standard HTTP methods (RFC 9110), return RFC 9457 Problem Details (application/problem+json) on 4xx/5xx, enforce bounded cursor pagination on collection GET endpoints, accept Idempotency-Key headers on POST mutations, document 429 with RateLimit-* headers, and bound input strings and arrays (OWASP API4:2023).
Static style guides document rules for human reading. This repository ships both the reference handbook and an automated OpenAPI 3.0/3.1 validator (api_validator.py), a browser validator, breaking-change diffing, and a GitHub Action that reports violations directly in Pull Requests.
No. api_validator.py runs on Python 3.9+ standard library alone for both JSON and YAML OpenAPI specs (and uses PyYAML automatically if already installed).
RFC 9457 (published in 2023) obsoleted RFC 7807. It keeps the application/problem+json media type and type/title/status/detail/instance members while clarifying multiple problem types and extension fields.
Copy .api-rules.example.json as .api-rules.json (or pick a preset in presets/), customize disabled_rules, severity_overrides, and allowed_version_prefixes, and pass config: .api-rules.json to api-design-tools/api-design-principles@v1.
python3 -m unittest discover -s tests -vSee CONTRIBUTING.md before opening a Pull Request. Distributed under the MIT License (LICENSE).