Skip to content

Parser enhancements: anyOf, inline schemas, defaults - #7

Closed
halotukozak wants to merge 4 commits into
feat/pluginfrom
feat/parser-enhancements
Closed

Parser enhancements: anyOf, inline schemas, defaults#7
halotukozak wants to merge 4 commits into
feat/pluginfrom
feat/parser-enhancements

Conversation

@halotukozak

Copy link
Copy Markdown
Contributor

Summary

  • anyOf support — parsed and generated identically to oneOf (sealed hierarchies)
  • Inline schema detection — with structural deduplication via InlineSchemaDeduplicator
  • Default parameter values — extracted from OpenAPI spec, constructor params ordered (required first)
  • Date/time typeskotlin.time.Instant and kotlinx.datetime.LocalDate mapping
  • Wrapper pattern unwrapping — oneOf schemas with single-property wrappers collapsed
  • Primitive type aliases — schemas with only primitive constraints generate typealias
  • allOf reference resolution — properly resolves $ref inside allOf compositions
  • Kotlin keyword escaping — backtick-escapes reserved words in generated identifiers
  • HttpError refactor — flat data class with HttpErrorType enum
  • Conditional SerializersModule — only wired when polymorphic types are present
  • Removed TypeRef.Unknown — dead code cleanup
  • ktlint fixes across codebase

Stacked on feat/plugin (#5).

Test plan

  • All existing unit tests pass
  • ktlintCheck passes
  • Review parser changes in SpecParser.kt
  • Verify generated code for anyOf schemas

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 11, 2026 20:21

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 expands the OpenAPI parsing + Kotlin code generation capabilities in core (anyOf, inline schemas, defaults, improved ref handling) and introduces a new Gradle plugin module to run generation from consumer builds (including functional tests via TestKit).

Changes:

  • Add Gradle plugin module with multi-spec DSL, shared-types generation task, and functional tests.
  • Enhance parser/model/generators: anyOf + wrapper unwrapping, inline schema detection/dedup, default values + constructor ordering, and additional type mappings.
  • Add/expand unit test coverage and test resources for new parsing/generation behaviors.

Reviewed changes

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

Show a summary per file
File Description
settings.gradle.kts Includes the new plugin module in the build.
.gitignore Ignores Gradle/Kotlin/IDE build artifacts.
plugin/build.gradle.kts Configures Gradle plugin publishing + functional test source set.
plugin/src/main/kotlin/com/avsystem/justworks/gradle/JustworksExtension.kt Adds the justworks { specs { ... } } multi-spec DSL container.
plugin/src/main/kotlin/com/avsystem/justworks/gradle/JustworksSpecConfiguration.kt Defines per-spec configuration (spec file + packages).
plugin/src/main/kotlin/com/avsystem/justworks/gradle/JustworksGenerateTask.kt Adds cacheable generation task (parse spec + generate model/client).
plugin/src/main/kotlin/com/avsystem/justworks/gradle/JustworksSharedTypesTask.kt Adds shared-types generation task used by all specs.
plugin/src/main/kotlin/com/avsystem/justworks/gradle/JustworksPlugin.kt Wires DSL -> tasks -> source sets -> compileKotlin dependency.
plugin/src/functionalTest/kotlin/com/avsystem/justworks/gradle/JustworksPluginFunctionalTest.kt TestKit functional coverage for plugin behavior and multi-spec support.
core/build.gradle.kts Adds Arrow dependency and compiler/ktlint configuration.
core/src/main/kotlin/com/avsystem/justworks/core/Generator.kt Keeps generator entry point (placeholder).
core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt Updates core domain model (schemas, refs, discriminator, defaults).
core/src/main/kotlin/com/avsystem/justworks/core/model/TypeRef.kt Adds inline type refs and expands primitive set (date/time).
core/src/main/kotlin/com/avsystem/justworks/core/parser/ParseResult.kt Adds structured parse result with warnings/errors.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt Major parser enhancements: anyOf, inline schemas, wrapper unwrapping, ref preservation.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Adds basic spec validation for required sections + unsupported constructs.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiResponseGenerator.kt Generates shared HTTP result/error types.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Generates Ktor-based API clients (+ conditional serializersModule wiring).
core/src/main/kotlin/com/avsystem/justworks/core/gen/InlineSchemaDeduplicator.kt Structural deduplication for inline schemas.
core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt Generates models (sealed hierarchies, defaults, type aliases, inline models, serializers).
core/src/main/kotlin/com/avsystem/justworks/core/gen/NameUtils.kt Adds consistent identifier transformations + Kotlin keyword escaping.
core/src/main/kotlin/com/avsystem/justworks/core/gen/Names.kt Centralizes KotlinPoet ClassName/MemberName constants.
core/src/main/kotlin/com/avsystem/justworks/core/gen/SerializersModuleGenerator.kt Generates polymorphic SerializersModule when needed.
core/src/main/kotlin/com/avsystem/justworks/core/gen/TypeMapping.kt Maps parsed TypeRef to KotlinPoet types (incl. date/time).
core/src/test/kotlin/com/avsystem/justworks/core/gen/ApiResponseGeneratorTest.kt Unit tests for shared types generation.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt Unit tests for client generation behavior.
core/src/test/kotlin/com/avsystem/justworks/core/gen/InlineSchemaDedupTest.kt Unit tests for inline schema deduplication.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorPolymorphicTest.kt Unit tests for polymorphic model generation (oneOf/anyOf/allOf).
core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorTest.kt Unit tests for defaults, ordering, keyword escaping, aliases, etc.
core/src/test/kotlin/com/avsystem/justworks/core/gen/NameUtilsTest.kt Unit tests for naming/escaping utilities.
core/src/test/kotlin/com/avsystem/justworks/core/gen/SerializersModuleGeneratorTest.kt Unit tests for serializers module generation conditions/output.
core/src/test/kotlin/com/avsystem/justworks/core/gen/TypeMappingTest.kt Unit tests for type mapping, incl. date/time mappings.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserPolymorphicTest.kt Parser tests for oneOf/allOf/discriminator.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserTest.kt Parser tests for refs, anyOf, mixed combinators, errors, etc.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecValidatorTest.kt Validator tests for missing required sections.
core/src/test/resources/anyof-spec.yaml Test spec for anyOf scenarios.
core/src/test/resources/anyof-valid-spec.yaml Test spec for anyOf + discriminator.
core/src/test/resources/invalid-spec.yaml Invalid spec used for error reporting tests.
core/src/test/resources/mixed-combinator-spec.yaml Spec testing mixed anyOf + oneOf rejection.
core/src/test/resources/petstore-v2.json Swagger v2 conversion test resource.
core/src/test/resources/petstore.yaml OpenAPI v3 test resource.
core/src/test/resources/polymorphic-spec.yaml Polymorphic schema test resource (oneOf/allOf).
core/src/test/resources/refs-spec.yaml Ref-resolution test resource.

💡 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/gen/ModelGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Outdated
Copilot AI review requested due to automatic review settings March 12, 2026 12:16

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 50 out of 51 changed files in this pull request and generated 7 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/gen/ClientGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecValidator.kt Outdated
Copilot AI review requested due to automatic review settings March 12, 2026 13:04

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 50 out of 51 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/gen/ClientGenerator.kt Outdated
@halotukozak
halotukozak changed the base branch from master to feat/plugin March 12, 2026 14:18
@halotukozak
halotukozak changed the base branch from feat/plugin to master March 18, 2026 13:28
@halotukozak
halotukozak changed the base branch from master to feat/plugin March 19, 2026 08:53
@halotukozak
halotukozak force-pushed the feat/parser-enhancements branch from b2abec1 to 3168d68 Compare March 19, 2026 08:58
halotukozak and others added 2 commits March 19, 2026 11:54
…mprovements

- anyOf support parsed identically to oneOf (sealed hierarchies)
- Inline schema detection with structural deduplication
- Default parameter values extracted from OpenAPI spec
- Date/time types mapping (kotlin.time.Instant, kotlinx.datetime.LocalDate)
- Wrapper pattern unwrapping for oneOf schemas
- Primitive type aliases for schemas with only primitive constraints
- allOf reference resolution
- Kotlin keyword escaping in generated identifiers
- Conditional SerializersModule (only when polymorphic types present)
- Removed TypeRef.Unknown dead code
@halotukozak
halotukozak force-pushed the feat/parser-enhancements branch from 6dd8eb9 to ebad85e Compare March 19, 2026 11:38
@halotukozak
halotukozak deleted the feat/parser-enhancements branch March 23, 2026 15:52
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.

2 participants