Skip to content

OpenAPI data model, parser, and validator - #2

Merged
halotukozak merged 27 commits into
masterfrom
feat/model-parser
Mar 16, 2026
Merged

OpenAPI data model, parser, and validator#2
halotukozak merged 27 commits into
masterfrom
feat/model-parser

Conversation

@halotukozak

Copy link
Copy Markdown
Contributor

Summary

  • Intermediate data model (ApiSpec, TypeRef, SchemaModel, EnumModel) for parsed OpenAPI 3.0 specs
  • SpecParser — schemas, endpoints, oneOf/anyOf/allOf, discriminators, inline schemas, wrapper pattern detection
  • SpecValidator — checks for unsupported features (callbacks, links, etc.)
  • Test fixtures (petstore, polymorphic, anyOf, refs specs) and comprehensive tests

Test plan

  • ./gradlew core:test passes (parser + validator tests)

Depends on #1

🤖 Generated with Claude Code

halotukozak and others added 2 commits March 11, 2026 14:02
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Intermediate model (ApiSpec, TypeRef, SchemaModel) for parsed OpenAPI specs.
SpecParser handles schemas, endpoints, oneOf/anyOf/allOf, discriminators,
inline schemas, and wrapper pattern detection.
SpecValidator checks for unsupported features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 11, 2026 13:05
@halotukozak
halotukozak changed the base branch from master to feat/gradle-plugin March 11, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an intermediate OpenAPI 3.0 data model plus a spec parser/validator implementation, along with test fixtures and unit tests to validate parsing behaviors (refs, anyOf/oneOf/allOf, discriminator handling, and Swagger 2.0 conversion). It also adds the Gradle wrapper/build configuration and CI workflow needed to run the test suite with coverage.

Changes:

  • Add ApiSpec/TypeRef-based intermediate model and SpecParser that transforms swagger-parser output into that model.
  • Add SpecValidator and a suite of parser/validator tests with multiple OpenAPI/Swagger fixtures.
  • Add Gradle wrapper/build configuration and a CI workflow to run tests with Kover coverage.

Reviewed changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
settings.gradle.kts Defines root project name and includes core module.
build.gradle.kts Sets up root Kotlin plugin version and common repositories/versioning.
core/build.gradle.kts Adds core module deps (swagger-parser, kotlinpoet, datetime), test setup, publishing, and Kover.
gradle.properties Enables Kotlin official code style.
gradlew Adds Gradle wrapper POSIX script.
gradlew.bat Adds Gradle wrapper Windows script.
gradle/wrapper/gradle-wrapper.properties Pins Gradle distribution URL and wrapper settings.
gradle/wrapper/gradle-wrapper.jar Adds Gradle wrapper JAR.
.github/workflows/ci.yml CI job to run coverage task and upload report to Codecov on PRs.
core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt Introduces intermediate API spec/domain model types (endpoints, schemas, enums, discriminator, etc.).
core/src/main/kotlin/com/avsystem/justworks/core/model/TypeRef.kt Adds TypeRef sealed interface and PrimitiveType enum used by the parser/model.
core/src/main/kotlin/com/avsystem/justworks/core/parser/ParseResult.kt Adds ParseResult for success/failure + warning propagation.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Implements OpenAPI parsing and transformation to the intermediate model (refs, inline schemas, combinators, etc.).
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Implements basic OpenAPI validation / unsupported feature checks.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Comprehensive parser tests (petstore, refs, invalid specs, Swagger v2 conversion, anyOf/mixed combinators, allOf property ref).
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserPolymorphicTest.kt Tests polymorphic parsing behavior (allOf merge, oneOf refs, discriminator preservation).
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecValidatorTest.kt Tests validator behavior for valid/missing-info specs.
core/src/test/resources/petstore.yaml OpenAPI 3 petstore fixture used in parser tests.
core/src/test/resources/petstore-v2.json Swagger 2.0 fixture used to test auto-conversion.
core/src/test/resources/refs-spec.yaml Fixture to exercise $ref resolution in parameters and schema graphs.
core/src/test/resources/polymorphic-spec.yaml Fixture to exercise oneOf/allOf + discriminator parsing.
core/src/test/resources/anyof-spec.yaml Fixture for anyOf without discriminator.
core/src/test/resources/anyof-valid-spec.yaml Fixture for anyOf with discriminator + mapping.
core/src/test/resources/mixed-combinator-spec.yaml Fixture intended to fail when mixing oneOf+anyOf.
core/src/test/resources/invalid-spec.yaml Fixture intended to fail validation (missing required info).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Outdated
Comment thread .github/workflows/ci.yml
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
# Conflicts:
#	.github/workflows/ci.yml
Base automatically changed from feat/gradle-plugin to master March 11, 2026 13:35
- Integrated Arrow core for improved null safety and functional error handling in `SpecParser` and `SpecValidator`.
- Refactored validation logic to use Arrow's contextual `Raise` API, distinguishing errors and warnings as independent result types.
- Added support for Kotlin compiler `-Xcontext-parameters` flag for cleaner contextual DSL usage.
- Adjusted Gradle dependencies to include `arrow-core` and updated Kotlin compile configuration.
- Reorganized schema-handling logic to reduce duplication and enhance maintainability.
- Simplified inline type reference creation and property extraction.
- Improved handling of `oneOf`, `anyOf`, and `allOf` schemas with reusable utilities.
- Replaced ad-hoc checks with clear helper functions for resolving primitives and composite types.
- Optimized property and required field merging logic for `allOf` schemas, reducing redundancies.
…Arrow

- Removed the `ParseResult` sealed interface and fully transitioned to Arrow's `Either` for handling parsing outcomes.
- Refactored tests and internal methods to use `either` for improved safety and simplicity in error management.
- Enhanced validation and schema parsing to seamlessly integrate with functional error handling.
Copilot AI review requested due to automatic review settings March 11, 2026 19:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecValidatorTest.kt Outdated
Comment thread core/build.gradle.kts Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
halotukozak and others added 2 commits March 11, 2026 20:14
- Set ktlint version to `1.8.0` as a temporary fix for known issue #912.
- Removed unused imports and redundant helper functions from `SpecParser`.
- Replaced custom string case conversion with `replaceFirstChar` for clarity and consistency.
…llOf

- Remove Arrow either/Either usage from test helpers, use ParseResult pattern match
- Fix SpecValidator test to use ValidationIssue.message
- Fix null-safe allOf access in toTypeRef
- Use resolveName() for identity-based schema resolution in toTypeRef

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 11, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/build.gradle.kts Outdated
Comment thread core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Outdated
halotukozak and others added 3 commits March 11, 2026 20:40
…extraction

- Updated handling of `required` fields using `orEmpty
Group methods into logical sections: public API, transformation,
endpoint/schema extraction, allOf merging, oneOf detection,
type resolution, schema extensions, naming helpers, constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Streamlined the code by removing section headers and redundant comments. Reformatted property extraction and type resolution logic for better readability.
Copilot AI review requested due to automatic review settings March 11, 2026 19:44
- Removed redundant `SpecParser.` prefix in test assertions and parsing logic.
- Updated tests for consistency and clarity in handling ParseResult types.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/build.gradle.kts Outdated
Comment thread core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
…n `SpecParser`

- Removed redundant `isEnum` property from `ApiSpec`.
- Refined `allOf` property merging by adding parent context in `extractAllOfProperties`.
- Standardized handling of `JSON_CONTENT_TYPE` and improved `oneOf` schema validation.
- Fixed property ordering in operations and updated array/item resolution logic.
- Adjusted compiler options configuration in Gradle for clarity and correctness.
- Replace `mapValuesNotNull` with stricter `associate` for clearer logic.
- Enhance handling of `additionalProperties` in `toTypeRef`, supporting schema references and boolean validation.
- Add fallback for unknown type handling in `toTypeRef`.
…extraction

- Introduced `HttpMethod.parse` with case-insensitive parsing.
- Updated `extractEndpoints` to leverage `HttpMethod.parse` for improved safety.
- Refactored schema extraction logic to prevent redundancy and ensure unique definitions.
- Extract shared test logic into `SpecParserTestBase`.
- Remove unused `loadResource` and `parseSpec` methods.
- Clean up legacy validation logic in SpecParser tests.
- Comment placeholder for future cookie parameter addition in `ParameterLocation`.
Copilot AI review requested due to automatic review settings March 13, 2026 11:05
- Corrected the order of `extractEnumModel` and `extractSchemaModel` to ensure proper model generation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Copilot AI review requested due to automatic review settings March 13, 2026 11:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
@halotukozak
halotukozak requested a review from mzielu March 13, 2026 12:09
…Parser

- Simplified schema folding logic by using `toMap` for more concise and efficient transformation.
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Comment thread core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Outdated
Copilot AI review requested due to automatic review settings March 16, 2026 11:01
@halotukozak
halotukozak requested a review from mzielu March 16, 2026 11:05

@mzielu mzielu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

core/build.gradle.kts:29

  • tasks.test { useJUnitPlatform() } and the test sources import org.junit.jupiter.api.*, but the module only declares testImplementation(kotlin("test")). Unless another dependency brings JUnit Jupiter, this will fail to compile/run tests. Add the JUnit 5 dependencies explicitly (e.g., kotlin("test-junit5") + Jupiter engine) or remove useJUnitPlatform() / Jupiter imports to align the test stack.
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

context(_: ComponentSchemaIdentity, _: ComponentSchemas)
private fun SwaggerParameter.toParameter(): Parameter = Parameter(
name = name ?: "",
location = ParameterLocation.parse(`in`) ?: ParameterLocation.QUERY,
Comment on lines +293 to +298

val schemaName = ensureNotNull(
propertySchema.resolveName() ?: propertyName
.takeIf { propertySchema.isInlineObject }
?.also { name ->
componentSchemas[name] = propertySchema
@halotukozak
halotukozak merged commit c8a7a97 into master Mar 16, 2026
1 check passed
@halotukozak
halotukozak deleted the feat/model-parser branch March 18, 2026 13:27
@halotukozak halotukozak added this to the 0.0.1 milestone Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants