Validation Pipeline Example
Demonstrates a complete validation pipeline with source map integration for IDE-friendly line numbers in error messages.
What You'll Learn
- How to parse and validate any OpenAPI specification
- How to enable source maps for line numbers in errors
- How to classify and report validation issues by severity
- The parse-once optimization pattern for better performance
Prerequisites
- Go 1.24+
- An OpenAPI specification file to validate
Quick Start
-
Run against the petstore spec:
-
Expected output:
-
Try with your own specification:
Files
| File | Purpose |
|---|---|
main.go |
Complete validation pipeline with error reporting |
go.mod |
Go module definition |
Key Concepts
Source Map Integration: By enabling parser.WithSourceMap(true) and passing it to the validator via v.SourceMap = result.SourceMap, validation errors include line numbers. This is essential for IDE integration and debugging.
Severity Levels: oastools uses four severity levels:
- CRITICAL - Specification cannot be processed
- ERROR - Violates OpenAPI specification requirements
- WARNING - Best practice recommendations
- INFO - Informational notes
Parse-Once Pattern: The example parses once with ParseWithOptions() then validates with ValidateParsed(). This avoids re-parsing the document and provides 9-154x performance improvement for multi-step workflows.
Exit Codes: The example exits with code 0 for success and code 1 for validation failures, making it suitable for CI/CD pipelines.
CLI Equivalent
This example replicates the functionality of:
Next Steps
- Quickstart Example - Minimal introduction
- PetStore Example - Code generation
- Validator Deep Dive
Generated for oastools