Parser enhancements: anyOf, inline schemas, defaults - #7
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b2abec1 to
3168d68
Compare
feat: add client generation
…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
6dd8eb9 to
ebad85e
Compare
Summary
InlineSchemaDeduplicatorkotlin.time.Instantandkotlinx.datetime.LocalDatemapping$refinside allOf compositionsHttpErrorTypeenumTypeRef.Unknown— dead code cleanupStacked on
feat/plugin(#5).Test plan
SpecParser.kt🤖 Generated with Claude Code