openapi-parser is a Java-based OpenAPI 3.0.x & 3.1 parser and validator with pluggable YAML/JSON converters and document readers. It's organized as a multi-module Gradle project supporting both OpenAPI 3.0 and 3.1 specifications with separate versioned APIs.
Core Modules (from settings.gradle.kts)
- openapi-parser - Main parser module (depends on json-schema-validator, io-interfaces)
- json-schema-validator - JSON Schema validation for OpenAPI documents
- io-interfaces - Plugin interfaces:
Reader(document loading),Converter(YAML/JSON parsing),Writer - io-jackson & io-snakeyaml - Pluggable converter implementations
- memory-protocol - In-memory resource handling
- openapi-parser-bom & json-schema-validator-bom - Bill of Materials (dependency management)
DocumentLoaderloads document by URI using pluggableReader+ConverterOpenApiParser.parse()detects version (3.0 vs 3.1) by reading "openapi" fieldResolverresolves$refreferences (uses Draft4 for 3.0, Draft202012 for 3.1)- Version-specific result returned:
OpenApiResult30orOpenApiResult31 - User calls
result.getModel(OpenApi.class)to get navigable model tree
All I/O abstraction via interfaces in io-interfaces:
- Implement
Readerfor custom document loading (default:UriReader) - Implement
Converterto support new YAML/JSON parsers (default: Jackson & SnakeYAML) - Implement
Writerto output documents (JSON/YAML writers available)
# Build with coverage (default)
./gradlew build
# Run specific module tests
./gradlew :openapi-parser:test
./gradlew :json-schema-validator:test
# Check dependency versions for updates
./gradlew dependencyUpdates
# View coverage reports
./gradlew jacocoLogAggregatedCoverage
# Check specific dependency
./gradlew dependencyInsight --dependency org.slf4j:slf4j-api --configuration testRuntimeClasspath- JUnit 5 (Jupiter) for test execution
- Kotest (StringSpec style) with table-driven tests (
kotest-table) - MockK for mocking in Kotlin tests
- Kotlin test files use
Specsuffix (e.g.,OpenApiParserSpec.kt)
Three apply to all modules:
- openapiparser.library - JVM toolchain (Java 11 build, 17 test), Checker Framework (null safety), JaCoCo (coverage)
- openapiparser.test - JUnit 5, Kotest, MockK setup
- openapiparser.publish - Maven Central publishing
- Detected via
openapifield in YAML/JSON:3.0.x→OpenApiResult30,3.1.x→OpenApiResult31 - Separate model packages:
io.openapiparser.model.v30.*vsio.openapiparser.model.v31.* - Use generic
OpenApiResultinterface in public APIs, cast to version-specific when needed
ParserException- wraps parsing failures with document URI for contextConverterException- YAML/JSON conversion failuresUnknownVersionException- unsupported OpenAPI versions
Testing Patterns (examples from OpenApiParserSpec.kt, ApiBuilder.kt)
- Use
ApiBuildertest utility: fluent API to build parsers with inline YAML buildParser()→parser.parse(URI)→result.getModel(OpenApi.class)- Test resources in
src/test/resources/organized by feature (e.g.,bundle-ref-schema/) - Table-driven tests with Kotest for multiple cases
- Checker Framework annotations:
@Nullable,@NonNullon methods returning/accepting potentially null values - Use
nonNull()helper (from jsonschema support) for assertions in critical paths - Default values: missing optional properties return false/empty collection per OpenAPI spec
- Jackson 2.20 (jackson-bom) - JSON/YAML parsing (io-jackson module)
- SnakeYAML 2.5 - Alternative YAML parser (io-snakeyaml module)
- jsonpath 2.9 - Document traversal (optional, for overlay features)
- SLF4J 2.0.17 + Logback 1.5.18 - Logging
- Embedded JSON Schema validator for OpenAPI validation
- Supports multiple JSON Schema drafts (Draft 4, Draft 6, Draft 7, Draft 202012)
- Test suites in json-schema-validator/src/test/resources/suites/
OverlayParserhandles Overlay 1.0 specificationsOpenApiBundlercombines multi-file references into single documentOverlayApplierapplies overlay transformations using JSONPath
- Main README - overview, usage examples (current 2023.3 API)
- openapi-parser README - detailed API usage with code examples
- Module READMEs - specific implementation details
- Published on Maven Central:
io.openapiprocessor:openapi-parser:*
Adding a new OpenAPI feature: Add to model classes, update converters in json-schema-validator
Adding yaml/json parser: Implement Converter interface in new module (see io-jackson/jackson pattern)
Adding custom document loading: Implement Reader interface, pass to DocumentLoader
Testing multi-file OpenAPI: Use DocumentStore to preload documents, pass to parser
Performance: Resolver caches $refs; reuse DocumentLoader across parses when possible