fix: generate discriminated union subtypes for oneOf schemas#20
fix: generate discriminated union subtypes for oneOf schemas#20halotukozak merged 9 commits intomasterfrom
Conversation
…hema inclusion - NameUtilsTest: isValidKotlinIdentifier and sanitizeSchemaName tests - SpecParserPolymorphicTest: boolean discriminator and synthetic schema tests - boolean-discriminator-spec.yaml test fixture Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ization - Add isValidKotlinIdentifier and sanitizeSchemaName to NameUtils.kt - Fix SpecParser.toApiSpec() to include synthetic schemas from wrapper unwrapping - Apply name sanitization in detectAndUnwrapOneOfWrappers for boolean discriminator values - Discriminator mapping preserves original values as keys while schema names are sanitized - Tests for NameUtils, SpecParser polymorphic parsing, and boolean discriminator fixture Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lti-variant oneOf - Test sanitized boolean discriminator names produce valid data classes with correct @SerialName - Test all 6 oneOf variants generate data classes and appear in SerializersModule - Test SerializersModule includes sanitized variant names Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
There was a problem hiding this comment.
Pull request overview
Fixes polymorphic (oneOf/discriminator) subtype generation by ensuring parser-emitted ApiSpec.schemas includes synthetic component schemas created during wrapper unwrapping, and adds schema-name sanitization for discriminator-derived names that would otherwise be invalid Kotlin class names (notably boolean values).
Changes:
- Include synthetic schemas registered during
detectAndUnwrapOneOfWrappersinOpenAPI.toApiSpec()output. - Add
isValidKotlinIdentifier()+sanitizeSchemaName()utilities and apply them when registering synthetic variant schemas. - Add parser/name-utils/generator regression tests plus a boolean-discriminator fixture spec.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt | Collects synthetic schemas into ApiSpec.schemas; sanitizes wrapper-derived synthetic schema names. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/NameUtils.kt | Adds Kotlin identifier validation and schema name sanitization helper. |
| core/src/test/resources/boolean-discriminator-spec.yaml | Adds fixture covering wrapper-style boolean discriminator keys. |
| core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserPolymorphicTest.kt | Adds regression tests asserting synthetic schemas and sanitized names appear in parsed output. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/NameUtilsTest.kt | Adds unit tests for identifier validation and sanitization behavior. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorPolymorphicTest.kt | Adds e2e generator tests for boolean discriminator variants and multi-variant oneOf. |
| .planning/STATE.md | Adds project planning/state tracking document. |
| .planning/ROADMAP.md | Adds roadmap/planning document. |
| .planning/phases/07-discriminated-union-subtype-generation/07-01-SUMMARY.md | Adds Phase 07 summary documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/src/main/kotlin/com/avsystem/justworks/core/gen/NameUtils.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
…ping Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserPolymorphicTest.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
core/src/test/kotlin/com/avsystem/justworks/core/parser/SpecParserPolymorphicTest.kt
Show resolved
Hide resolved
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
…sive function in SpecParser - Improves clarity and ensures consistent schema processing - Updates related test cases in SpecParserPolymorphicTest
Summary
SpecParser.toApiSpec()to include synthetic schemas fromdetectAndUnwrapOneOfWrappers— subtypes likeDataModelSource,ExtenderDeviceetc. were missing from outputsanitizeSchemaName()inNameUtils.ktto handle boolean discriminator values (true/false) that produce invalid Kotlin class names — now prefixed with parent schema name (e.g.,DeviceStatusTrue)Test plan
NameUtilsTest— validates identifier checking and name sanitizationSpecParserPolymorphicTest— verifies synthetic schemas appear in parsed outputModelGeneratorPolymorphicTest— e2e tests for generated polymorphic hierarchies🤖 Generated with Claude Code