The OneBusAway API Validator implements OpenAPI schema validation using the kin-openapi library to validate API responses against the formal OpenAPI 3.0 specification.
The validator leverages the kin-openapi library, which provides:
- Specification Loading: Parse and validate OpenAPI YAML/JSON specifications
- Request/Response Validation: Comprehensive validation against schema definitions
- Router Integration: Path matching and parameter extraction
For detailed documentation, visit their official documentation.
The schema validator is implemented in the internal/schemavalidator package with a core OpenAPIValidator struct that encapsulates:
- Loader: OpenAPI specification loader with context support
- Document: Parsed and validated OpenAPI specification
- Router: Path matching router for endpoint resolution
- Client: Optional OBA client for live request execution
The validator initialization process:
- Loads and parses the OpenAPI YAML specification
- Validates the specification itself for correctness
- Configures server URLs for local testing
- Sets up router for path matching
The core validation process:
- Route Resolution: Matches the request URL to the OpenAPI specification path
- Parameter Extraction: Extracts path parameters for validation context
- Response Parsing: Parses the JSON response body
- Schema Validation: Validates response against defined schemas
The validator supports both direct response validation and request-based validation for live API testing.
The validator uses the comprehensive OpenAPI 3.0 specification defined in openapi.yml, which provides:
- Complete API Documentation: All endpoints, parameters, and responses
- Schema Definitions: Reusable component schemas with inheritance
- Validation Rules: Type constraints, required fields, and formats
- Response Templates: Standardized response wrapper patterns