Files
brunoandClaude Sonnet 4.5 0a91cb0677 feat(openspec): integrate OpenSpec 0.17.2 for API-first development
Integrate OpenSpec with complete OpenAPI-first development workflow:

**Configuration Files:**
- Add package.json with npm scripts for spec validation
- Add .openspec.yaml for validation rules (strict mode)
- Add .spectral.yaml for OpenAPI linting (100+ rules)
- Add openapi.yaml with initial API specification

**Automation:**
- Add scripts/generate-openapi-spec.py to auto-generate spec from FastAPI
- Add .claude/hooks/pre-commit-openspec.sh for pre-commit validation
- Add .github/workflows/openspec-validation.yml for CI/CD validation

**Documentation:**
- Add docs/workflows/openspec-development-workflow.md (500+ lines workflow guide)
- Add OPENSPEC-SETUP.md (quick start guide)
- Add README-OPENSPEC-INTEGRATION.md (integration summary)
- Update .claude/CLAUDE.md with OpenSpec commands and 9-step workflow

**Features Enabled:**
- OpenAPI-first development (design before code)
- Automatic spec validation on commit
- Breaking change detection in PRs
- Bidirectional sync between spec and code
- Spectral linting with 100+ best practice rules
- Auto-generated API documentation

**Validation Rules:**
- Require operationId, tags, descriptions on all operations
- Require 4xx and 5xx error responses
- Enforce naming conventions (kebab-case paths, PascalCase schemas)
- Require /health and /metrics endpoints (observability)

**Commands Available:**
- npm run spec:validate - Validate OpenAPI spec
- npm run spec:lint - Lint with Spectral
- npm run spec:generate - Generate from FastAPI
- npm run spec:sync - Generate + validate
- npm run spec:diff - Detect breaking changes
- npm run spec:watch - Auto-regenerate on changes

**Breaking Changes:** None (new feature)

**Next Steps:**
1. Run: npm install
2. Run: npm run spec:generate
3. Run: npm run spec:validate
4. Enable pre-commit hook: ln -sf ../../.claude/hooks/pre-commit-openspec.sh .git/hooks/pre-commit

Closes #7 (partially - Claude Configuration optimization)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
2025-12-31 23:25:52 +08:00

175 lines
3.0 KiB
YAML

# OpenSpec Configuration
# https://openspec.dev/docs/configuration
# Validation rules
validation:
# Strictness level: strict, normal, relaxed
level: strict
# OpenAPI version
openapi-version: "3.0.3"
# Require specific fields
require:
- info.title
- info.version
- info.description
- info.contact
- paths
# Path rules
paths:
# Enforce RESTful naming
kebab-case: true
no-trailing-slash: true
# Version in path (optional)
version-in-path: false
# HTTP methods
allowed-methods:
- get
- post
- put
- patch
- delete
- options
- head
# Schema rules
schemas:
# Naming conventions
pascal-case: true
# Required fields
require-description: true
require-example: false
# Type validation
strict-types: true
# Security
security:
# Require security schemes
require-security: true
# Allowed schemes
allowed-schemes:
- bearer
- apiKey
- oauth2
- http
# Response rules
responses:
# Require response descriptions
require-description: true
# Require error responses
require-4xx: true
require-5xx: true
# Standard error responses
standard-errors:
- 400 # Bad Request
- 401 # Unauthorized
- 403 # Forbidden
- 404 # Not Found
- 422 # Unprocessable Entity
- 500 # Internal Server Error
# Tags
tags:
# Require tags on operations
require-tags: true
# Tag naming
kebab-case: false
pascal-case: true
# Linting rules (using Spectral)
spectral:
extends:
- spectral:oas
- spectral:asyncapi
rules:
# Info
info-contact: error
info-description: error
info-license: warn
# Operations
operation-description: error
operation-operationId: error
operation-summary: error
operation-tags: error
# Parameters
parameter-description: warn
# Paths
path-keys-no-trailing-slash: error
# Responses
operation-success-response: error
# Schemas
schema-properties-descriptions: warn
# Generation settings
generation:
# Output format
format: yaml
# Output file
output: openapi.yaml
# Include examples
include-examples: true
# Server configuration
servers:
- url: http://localhost:8000
description: Development server
- url: https://api.example.com
description: Production server
# Breaking change detection
breaking-changes:
# Enabled
enabled: true
# What constitutes a breaking change
rules:
# Removed endpoints
removed-path: error
# Removed operations
removed-operation: error
# Required parameters
added-required-parameter: error
removed-parameter: error
# Request/response changes
changed-request-body: warn
changed-response-body: warn
# Type changes
changed-type: error
# Documentation
documentation:
# Generate markdown docs
markdown: true
# Output directory
output-dir: docs/api
# Include examples
include-examples: true
# Include schemas
include-schemas: true