openapi-expert
Formal specification of REST APIs with OpenAPI 3.x: endpoint design, request/response schemas, versioning, pagination (cursor/offset), RFC 7807 error handling, stub generation, contract validation, and interactive documentation with Swagger UI/Redoc. Use when designing REST API contracts, writing OpenAPI specs, generating API stubs, configuring spectral linting, or documenting APIs with Swagger UI. Trigger: OpenAPI spec, REST API design, spectral linting, RFC 7807, cursor pagination, Swagger UI, API security, OWASP API. Do NOT trigger for: gRPC/Protobuf API design, internal service-to-service RPC contracts, GraphQL schema design.
- License 许可
- MIT
- 最近更新
- 2026-08-27
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- openapi-expert
- license
- MIT
- metadata
- { "author": "Community", "status": "stable", "version": "1.0", "category": "backend" }
- description
- Formal specification of REST APIs with OpenAPI 3.x: endpoint design, request/response schemas, versioning, pagination (cursor/offset), RFC 7807 error handling, stub generation, contract validation, and interactive documentation with Swagger UI/Redoc. Use when designing REST API contracts, writing OpenAPI specs, generating API stubs, configuring spectral linting, or documenting APIs with Swagger UI. Trigger: OpenAPI spec, REST API design, spectral linting, RFC 7807, cursor pagination, Swagger UI, API security, OWASP API. Do NOT trigger for: gRPC/Protobuf API design, internal service-to-service RPC contracts, GraphQL schema design.
02 资源文件 3
- 参考文档evals/evals.json2.5 KB
- 参考文档references/error-format.md785 B
- 参考文档references/pagination.md547 B
03 SKILL.md 正文
OpenAPI Expert
REST API design with OpenAPI 3.x: contracts, versioning and validation.
Core Stack
- Spec: OpenAPI 3.1 (YAML/JSON)
- Docs: Swagger UI / Redoc / Scalar
- Generation: OpenAPI Generator (server stubs, client SDKs)
- Validation: spectral linting, contract testing
API Design Principles
- Resources over RPC:
/resources/{id}/itemsnot/getItems?customer=id - HTTP methods: GET(read), POST(create), PUT(replace), PATCH(partial update), DELETE(remove)
- Status codes: 200/201(success), 400(validation), 401(auth), 403(forbidden), 404(not found), 409(conflict), 422(unprocessable), 429(rate limit), 500(server error)
- Versioning: URL path (
/v1/,/v2/) orAcceptheader
Idempotency
POST /v1/items
Idempotency-Key: key_abc123
- Idempotent operations: GET, PUT, DELETE (by spec)
- POST with
Idempotency-Keyheader for item creation - Return stored response for duplicate keys within window (24h)
Pagination
# Cursor-based (preferred for large datasets)
GET /v1/items?cursor=abc123&limit=50
Response: { data: [...], next_cursor: "def456", has_more: true }
# Offset-based (simple, small datasets only)
GET /v1/items?offset=20&limit=10
Response: { data: [...], total: 100, offset: 20, limit: 10 }
- Cursor-based for datasets > 1000 items or frequently-inserted data
- Offset-based for admin UIs where jumping pages is needed
Error Format (RFC 7807)
{
"type": "https://api.example.com/errors/validation-error",
"title": "Validation failed",
"status": 422,
"detail": "The request of 1000 units exceeds available value of 500 units",
"instance": "/v1/items/req_abc123",
"request_id": "req_xyz789",
"code": "VALIDATION_ERROR"
}
type: URL to error documentation.code: machine-readable enum.- NEVER expose stack traces or internal errors in
detail.
OpenAPI Spec Example
openapi: 3.1.0
info:
title: team Items API
version: 1.0.0
paths:
/v1/items:
post:
summary: Create an item
parameters:
- in: header
name: Idempotency-Key
schema: { type: string }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [quantity, type]
properties:
quantity: { type: integer, minimum: 1, description: "Quantity" }
type: { type: string, enum: [standard, premium, enterprise] }
responses:
"201":
description: Item created
content:
application/json:
schema:
$ref: "#/components/schemas/ItemResponse"
Constraints
- NEVER use GET for state-changing operations (create/update/delete)
- NEVER use 200 for creation errors (400/422, not 200 with
error: true) - NEVER include secrets, tokens, or PII in error messages
- ALWAYS use
application/jsonfor request/response bodies - ALWAYS include
request_idin error responses for debugging - ALWAYS version APIs (never change contract without version bump)
- NEVER remove or rename fields in active API versions (additive only)
Security
OWASP API Security Top 10 (2023)
- API1 Broken Object Level Authorization (BOLA)
- API2 Broken Authentication
- API3 Broken Property Level Authorization (BOPLA)
- API4 Unrestricted Resource Consumption
- API5 Broken Function Level Authorization (BFLA)
- API6 Unrestricted Access to Sensitive Business Flows
- API7 Server Side Request Forgery (SSRF)
- API8 Security Misconfiguration
- API9 Improper Inventory Management
- API10 Unsafe Consumption of APIs
Contract Security
- ALWAYS define
securitySchemes(OAuth2 or JWT bearer) and apply to every path - ALWAYS return 429 with
Retry-Afterheader for rate-limited responses (API4) - NEVER document or expose endpoints without auth requirements (API5, API9)
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []
Overview
OpenAPI 3.x defines REST API contracts for cloud-native services with resource-oriented design, cursor-based pagination, RFC 7807 errors, and idempotency patterns. This skill covers spec design, versioning, validation with spectral, and stub generation.
Quick Reference
| Pattern | Implementation | Purpose |
|---|---|---|
| Idempotency | Idempotency-Key header on POST |
Safe retry for item creation |
| Pagination | Cursor-based (cursor + limit) |
Scale for large datasets |
| Errors | RFC 7807 Problem Details |
Structured error responses |
| Versioning | URL path (/v1/, /v2/) |
Backward-incompatible changes |
Workflow
- Identify resource boundaries and define paths using nouns over verbs
- Choose appropriate HTTP methods: GET (read), POST (create), PUT (replace), DELETE (remove)
- Define request/response schemas with
$reffor reusable components - Add
Idempotency-Keyheader on mutating POST endpoints - Implement RFC 7807 error responses with
type,title,status,detail,code - Add pagination parameters — cursor-based for large datasets, offset for admin UIs
- Validate spec with
spectral lintand run contract tests before deployment - Never remove or rename fields in active versions — additive changes only
Anti-patterns
FAIL: Using GET for state-changing operations PASS: Use POST for creates, PUT for replacements, DELETE for removals
# FAIL:
GET /deleteItem?id=123
# PASS:
DELETE /v1/items/123
FAIL: Returning 200 with {"error": true} for validation failures
PASS: Use proper 4xx status codes
// FAIL:
HTTP 200
{"error": true, "message": "validation failed"}
// PASS:
HTTP 422
{"type": "https://api.example.com/errors/validation-error", "title": "Validation failed", "status": 422, "detail": "Value: 500 units, required: 1000 units"}
FAIL: Exposing internal stack traces in error responses PASS: Always return sanitized, user-facing messages
// FAIL:
{"error": "java.lang.NullPointerException at com.example.items.ItemService.process(ItemService.java:42)"}
// PASS:
{"type": "https://api.example.com/errors/internal-error", "title": "Internal server error", "status": 500, "request_id": "req_abc123"}
References
-
OpenAPI Specification 3.1 (last_verified: 2026-05-25)
-
RFC 7807 Problem Details for HTTP APIs (last_verified: 2026-05-25)
-
Spectral API Linting (last_verified: 2026-05-25)
Verification Checklist
- [ ] Paths use nouns over verbs (
/resources/{id}/itemsnot/getItems) - [ ]
Idempotency-Keyheader defined on all mutating POST endpoints - [ ] RFC 7807 error responses used with
type,title,status,detail,code - [ ] Pagination strategy chosen: cursor-based for large datasets, offset for admin UIs
- [ ] API versions in URL path (
/v1/,/v2/) — additive changes only in active versions - [ ] Spec passes
spectral lintwith no errors - [ ] GET requests never cause state changes
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Client gets 415 Unsupported Media Type |
Content-Type not declared in requestBody schema |
Add application/json to request body content type list in spec |
| Generated stub missing endpoints | OpenAPI spec had syntax errors before generation | Run spectral lint and openapi-generator validate before code generation |
Idempotency-Key header ignored by server |
Parameter declared in spec but not read by handler | Add middleware to extract Idempotency-Key from request headers |
Known issue: openapi-generator produces invalid client SDK for oneOf discriminator mappings |
Generated code uses incorrect type mapping for polymorphic schemas with oneOf + discriminator |
Prefer allOf composition over oneOf discriminator for spec-first codegen; verify generated types against manual test |
| [WARN] openapi-generator generates wrong enum names for values with hyphens | Code generator converts hyphens to underscores inconsistently; enum constant naming is fragile | Use x-enum-varnames extension to pin enum constant names; avoid hyphens in enum values |
04 同仓库更多 Skills
web-browsing-agent-expert
Web browsing for AI agents: driving a headless browser (Playwright, Puppeteer) from agent tooling, navigation and page-state grounding, DOM extraction and structured data capture, form interaction, session and cookie management, anti-bot mitigation awareness, and safe browsing rules (no PII exfiltration, respect robots and terms). Use when building a browsing tool or MCP server for an agent, teaching an agent to navigate and read web pages, extracting structured content from dynamic sites, or handling login walls and pagination in agent workflows. Trigger: web browsing agent, headless browser, Playwright MCP, Puppeteer, browser automation for agents, DOM extraction, page navigation, session management. Do NOT trigger for: end-to-end UI testing of an application (use playwright-expert); writing standalone scraping scripts for data pipelines (use python-expert); fetching a single public URL (use the fetch tool).
vector-databases
Design and operate vector databases for cloud-native AI features. Use when selecting between pgvector, Pinecone, or Weaviate for AI context layer or integration-hub; designing embedding schemas and index parameters; implementing ANN search with metadata filtering; managing embedding model versions; optimizing query latency; or debugging low retrieval quality. Pairs with rag-architecture for pipeline design and postgres-database-expert for pgvector specifics. Trigger: vector database, pgvector, Pinecone, Weaviate, embedding, ANN search, HNSW, cosine similarity. Do NOT trigger for: relational SQL optimization, standard PostgreSQL schema design, Redis caching.
typescript-expert
Full-stack TypeScript stack for modern projects: frontend SSR/CSR with Next.js 14 App Router and React, backend APIs with Node.js (Express/Fastify), state management with Zustand/Redux Toolkit, unit and integration testing with Vitest/Jest + React Testing Library + MSW, and static analysis with ESLint/Prettier/tsc. Use when building React components or hooks, implementing Next.js App Router or Server Components, writing Node.js REST API handlers, implementing middleware (auth, rate-limit, logging), managing client state (Zustand/RTK), writing frontend/backend tests, or running TypeScript linting/type checks. Trigger: TypeScript, Next.js, React, Zustand, Node.js, Express, Fastify, MSW, Vitest. Do NOT trigger for: Python backend development, Go microservices, iOS/mobile development.
tool-usage
Guide correct tool selection, design, and orchestration for AI agents. Use when choosing between dedicated vs Bash tools, designing MCP tool interfaces, naming tool parameters, handling tool response limits, orchestrating parallel vs sequential calls, evaluating tool accuracy, applying ACI design principles, selecting workflow patterns, or reading/filtering/transforming/generating structured data (JSON, YAML, CSV, TOML, XML). Trigger: tool selection, MCP tool design, orchestration, ACI, parallel execution, composite tool, structured data, jq, yq, dasel, mlr, csvkit. Do NOT trigger for: writing application business logic, domain-specific development (route to domain skill), database migrations.
token-efficiency
Enforce token-efficient output, compression, caching, and model routing. Use when calibrating response verbosity, applying compression strategies to logs or RAG chunks, routing tasks to the right model tier, setting thinking budgets, enforcing word limits, compressing context before reinitiation, applying KV-cache ordering, masking tool output observations, or applying clarification-first protocol before irreversible actions. Trigger: token efficiency, compression, model routing, thinking budget, KV-cache, clarification protocol. Do NOT trigger for: non-agent tooling, CI/CD pipeline scripting, infrastructure provisioning.
time-series-db
Time-series database patterns for cloud-native metrics and analytics: TimescaleDB, InfluxDB, and Amazon Timestream selection; continuous aggregates, retention policies, downsampling, and integration with Prometheus/Grafana. Use when storing business metrics over time, building custom business dashboards, designing high-frequency event storage, or querying time-bucketed aggregations. Trigger: time-series, TimescaleDB, InfluxDB, Prometheus, Grafana, hypertable, continuous aggregate, retention policy. Do NOT trigger for: relational PostgreSQL schema design, NoSQL document stores, Kafka event streaming.