A minimal 5-minute introduction to oastools, demonstrating the parse and validate workflow.
- How to parse an OpenAPI specification with oastools
- How to validate a specification against OAS schema rules
- How to access parsed document structure programmatically
- Go 1.25+
- oastools module dependency (auto-fetched)
-
Clone the repository:
git clone https://github.com/erraggy/oastools.git cd oastools/examples/quickstart -
Run the example:
go run main.go
-
Expected output:
oastools Quickstart =================== [1/3] Parsing OpenAPI specification... Version: 3.0.3 Format: yaml [2/3] Validating against OAS schema... Valid: true Errors: 0 Warnings: 0 [3/3] Accessing document structure... API Title: Quickstart API API Version: 1.0.0 Paths: 1 Schemas: 1 Paths defined: - /hello Schemas defined: - Greeting --- Quickstart complete!
| File | Purpose |
|---|---|
spec.yaml |
Minimal OpenAPI 3.0.3 specification (27 lines) |
main.go |
Demonstrates parse → validate → inspect workflow |
go.mod |
Go module definition |
Parse-Once Pattern: The example uses parser.ParseWithOptions() to parse the specification once, then passes the result to v.ValidateParsed() (a method on *validator.Validator). This avoids re-parsing and provides significant performance improvement for repeated operations.
Version-Agnostic Access: The AsAccessor() method returns a DocumentAccessor interface that works identically for OAS 2.0, 3.0.x, 3.1.x, and 3.2.0 documents, abstracting away version-specific structure differences.
Validation Severity Levels: oastools uses four severity levels:
Critical- Specification cannot be processedError- Violates OpenAPI specification requirementsWarning- Best practice recommendationsInfo- Informational notes
- Validation Pipeline Example - Detailed validation workflow with source maps
- PetStore Generator Example - Generate Go client/server code
- Parser Deep Dive
- Validator Deep Dive
Generated for oastools