AGENT SKILL

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

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}/items not /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/) or Accept header

Idempotency

POST /v1/items
Idempotency-Key: key_abc123
  • Idempotent operations: GET, PUT, DELETE (by spec)
  • POST with Idempotency-Key header 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/json for request/response bodies
  • ALWAYS include request_id in 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-After header 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

  1. Identify resource boundaries and define paths using nouns over verbs
  2. Choose appropriate HTTP methods: GET (read), POST (create), PUT (replace), DELETE (remove)
  3. Define request/response schemas with $ref for reusable components
  4. Add Idempotency-Key header on mutating POST endpoints
  5. Implement RFC 7807 error responses with type, title, status, detail, code
  6. Add pagination parameters — cursor-based for large datasets, offset for admin UIs
  7. Validate spec with spectral lint and run contract tests before deployment
  8. 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

Verification Checklist

  • [ ] Paths use nouns over verbs (/resources/{id}/items not /getItems)
  • [ ] Idempotency-Key header 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 lint with 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

ronsilver
ronsilver/agent-covenant

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).

★ 1
ronsilver
ronsilver/agent-covenant

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.

★ 1
ronsilver
ronsilver/agent-covenant

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.

★ 1
ronsilver
ronsilver/agent-covenant

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.

★ 1
ronsilver
ronsilver/agent-covenant

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.

★ 1
ronsilver
ronsilver/agent-covenant

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.

★ 1