Workflow Examples
This directory contains examples demonstrating common OpenAPI workflows using the oastools packages.
Available Workflows
| Workflow | Package | Description | Time |
|---|---|---|---|
| validate-and-fix | fixer | Parse, validate, auto-fix common errors | 3 min |
| version-conversion | converter | Convert OAS 2.0 (Swagger) → OAS 3.0.3 | 3 min |
| multi-api-merge | joiner | Merge multiple specs with collision resolution | 4 min |
| breaking-change-detection | differ | Detect breaking changes between API versions | 4 min |
| overlay-transformations | overlay | Apply environment-specific customizations | 3 min |
| http-validation | httpvalidator | Runtime HTTP request/response validation | 5 min |
Quick Start
Each example is a standalone Go module. To run any example:
Workflow Overview
Validate and Fix
The validate-and-fix workflow shows how to automatically repair common OpenAPI spec issues:
- Parse the specification
- Validate and identify errors
- Preview fixes with dry-run mode
- Apply fixes automatically
- Re-validate to confirm resolution
Use cases: CI/CD pre-commit hooks, spec cleanup automation
Version Conversion
The version-conversion workflow demonstrates OAS version migration:
- Parse OAS 2.0 (Swagger) specification
- Convert to OAS 3.0.3
- Track conversion issues and warnings
- Access the converted document
Use cases: Legacy API migration, spec modernization
Multi-API Merge
The multi-api-merge workflow shows how to combine microservice specs:
- Parse multiple OpenAPI specs
- Configure collision resolution strategies
- Merge with semantic deduplication
- Handle path and schema conflicts
Use cases: API gateway specs, unified documentation, monorepo builds
Breaking Change Detection
The breaking-change-detection workflow implements CI/CD quality gates:
- Parse base and target specifications
- Compare for breaking changes
- Categorize by severity (CRITICAL, ERROR, WARNING, INFO)
- Generate reports for PR reviews
Use cases: CI/CD gates, release validation, API governance
Overlay Transformations
The overlay-transformations workflow applies environment-specific changes:
- Parse base specification
- Load overlay document with JSONPath actions
- Preview changes in dry-run mode
- Apply transformations
Use cases: Multi-environment configs, security additions, filtering internal endpoints
HTTP Validation
The http-validation workflow validates runtime HTTP traffic:
- Parse specification
- Create HTTP validator
- Validate requests (path, query, body)
- Extract typed path parameters
- Validate responses
Use cases: Request validation middleware, API testing, contract compliance
Common Patterns
Parse-Once Optimization
All workflows demonstrate the parse-once pattern for maximum performance:
// Parse once
parsed, _ := parser.ParseWithOptions(parser.WithFilePath("spec.yaml"))
// Reuse for multiple operations
fixer.FixWithOptions(fixer.WithParsed(parsed))
validator.ValidateWithOptions(validator.WithParsed(parsed))
This avoids re-parsing the same spec, providing 9-154x performance improvements.
Functional Options
All packages use the functional options pattern for clean, extensible configuration:
result, err := converter.ConvertWithOptions(
converter.WithFilePath("swagger.yaml"),
converter.WithTargetVersion("3.0.3"),
)
Error Handling
All workflows include proper error handling with rich error types:
result, err := differ.DiffWithOptions(...)
if err != nil {
log.Fatal(err)
}
// Iterate over changes and filter by breaking status
for _, change := range result.Changes {
if result.HasBreakingChanges {
fmt.Printf("[%s] %s: %s\n",
change.Category,
change.Severity,
change.Message)
}
}
Next Steps
- Getting Started Examples - Basic parser and validator usage
- Programmatic API - Build specs from Go code
- Code Generation - Generate client/server code
Generated for oastools