02-generated-repo-core/api-schema/SKILL.md
Defines request/response shapes, versioning, validation, and compatibility rules for API-first work. Trigger on 'design API', 'OpenAPI spec', 'REST schema', 'API versioning', 'generate client SDK'. DO NOT USE for GraphQL schemas, gRPC/protobuf definitions (use stack-standards), auth endpoint logic (use auth-patterns), or external API client wrappers (use external-api-client).
npx skillsauth add chelch5/skilllibrary api-schemaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Design API schemas using OpenAPI 3.1 and JSON Schema for type-safe contracts between services. Define versioning strategy, distinguish breaking from non-breaking changes, and enable code generation from specs. The schema IS the contract—disagreement about the schema means disagreement about the API.
Use when:
Do NOT use when:
Create OpenAPI 3.1 specification:
openapi: 3.1.0
info:
title: User Service API
version: 1.0.0
description: API for user management
servers:
- url: https://api.example.com/v1
description: Production
- url: https://staging-api.example.com/v1
description: Staging
paths:
/users/{userId}:
get:
operationId: getUser
summary: Get user by ID
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: User found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
Define reusable schemas in components:
components:
schemas:
User:
type: object
required:
- id
- email
- createdAt
properties:
id:
type: string
format: uuid
description: Unique user identifier
email:
type: string
format: email
displayName:
type: string
maxLength: 100
createdAt:
type: string
format: date-time
additionalProperties: false # Strict schema
Error:
type: object
required:
- code
- message
properties:
code:
type: string
enum: [NOT_FOUND, VALIDATION_ERROR, INTERNAL_ERROR]
message:
type: string
details:
type: object
Classify changes as breaking or non-breaking:
BREAKING (requires major version bump):
─────────────────────────────────────
- Removing endpoint or method
- Removing required request field
- Adding required request field without default
- Changing field type
- Removing response field clients depend on
- Changing error response structure
NON-BREAKING (minor or patch version):
─────────────────────────────────────
- Adding new endpoint
- Adding optional request field
- Adding response field
- Adding new enum value (if clients ignore unknown)
- Relaxing validation (wider accepted range)
Choose versioning strategy:
# URL path versioning (most common, clearest)
servers:
- url: https://api.example.com/v1
- url: https://api.example.com/v2
# Header versioning (cleaner URLs)
# Client sends: Accept: application/vnd.api+json;version=1
# Query parameter (easy for debugging)
# GET /users?api-version=2024-01-15
Generate code from spec:
# Generate TypeScript client
npx openapi-typescript openapi.yaml -o types.ts
# Generate Python FastAPI server stub
pip install fastapi-code-generator
fastapi-codegen --input openapi.yaml --output app/
# Validate spec
npx @redocly/cli lint openapi.yaml
Add request validation:
# FastAPI automatically validates against OpenAPI schema
from pydantic import BaseModel, EmailStr
from uuid import UUID
class CreateUserRequest(BaseModel):
email: EmailStr
display_name: str | None = None
class Config:
extra = 'forbid' # Reject unknown fields
@app.post("/users")
async def create_user(request: CreateUserRequest) -> User:
# Request already validated against schema
...
# openapi.yaml
openapi: 3.1.0
info:
title: [Service Name] API
version: 1.0.0
description: |
[Description]
## Versioning
URL path versioning: /v1/, /v2/
## Authentication
Bearer token in Authorization header
servers:
- url: https://api.example.com/v1
paths:
/[resource]:
get:
# ...
post:
# ...
components:
schemas:
# Reusable types
securitySchemes:
bearerAuth:
type: http
scheme: bearer
oasdiff can compare specsadditionalProperties: true in response schemas$ref to external filestesting
Manages context window budgets, loading strategies, and compaction techniques for AI-assisted coding sessions. Trigger on 'context window', 'what to load', 'context management', 'context overflow', 'token budget'. DO NOT USE for loading specific project docs into agent context (use project-context) or prompt wording and optimization (use prompt-crafting).
development
Implements authentication, session, token, and authorization patterns for the current stack. Trigger on 'add auth', 'JWT', 'OAuth', 'login endpoint', 'session management', 'API key auth'. DO NOT USE for OWASP hardening checklists (use security-hardening), threat modeling (use security-threat-model), or secret rotation/storage (use security-best-practices).
development
Create a repo-local ticket system with an index, machine-readable manifest, board, and individual ticket files. Use when a repo needs task decomposition that autonomous agents can follow without re-planning the whole project each session. Do not use for executing tickets (use ticket-execution) or quick fixes that don't warrant formal tickets.
development
Detect a project's language, framework, runtime, testing setup, and deployment target from repository contents and produce a structured STACK-PROFILE.md. Use when scaffolding a new project and need to determine stack from code evidence, onboarding to an existing repo with unknown stack, or generating stack-specific skills. Do not use when stack is already documented in STACK-PROFILE.md or for repos with no code (infer from specs instead).