feat: dynamic typealias for non-String inline schemas#19
Conversation
- Test Int, Boolean, Long, Double, Array, and Reference underlying types - Update existing String test with explicit type assertion and underlyingType = null - Tests fail to compile until underlyingType field is added to SchemaModel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add underlyingType: TypeRef? field to SchemaModel with null default - Parser computes underlyingType via toTypeRef() for primitive-only schemas - Generator uses TypeMapping.toTypeName() to resolve dynamic target type - Fallback to String when underlyingType is null (backward compatible) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
Adds support for generating typealiases to non-String Kotlin types when an OpenAPI schema is “primitive-only” (no properties / compositors), by carrying resolved schema type information from parsing into model generation.
Changes:
- Extend
SchemaModelwithunderlyingType: TypeRef?to represent the resolved underlying schema type for primitive-only schemas. - Populate
underlyingTypeinSpecParserand use it inModelGenerator(viaTypeMapping.toTypeName) when generating typealiases. - Expand
ModelGeneratorTestcoverage with additional typealias assertions for multiple primitive/collection/reference cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| core/src/main/kotlin/com/avsystem/justworks/core/model/ApiSpec.kt | Adds underlyingType to SchemaModel to carry primitive-only schema type info. |
| core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt | Attempts to infer and set underlyingType for primitive-only / wrapper schemas during parsing. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/ModelGenerator.kt | Uses underlyingType (mapped through TypeMapping) to generate typealiases to dynamic Kotlin types. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorTest.kt | Adds/updates tests asserting generated typealias targets across multiple underlying types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
core/src/test/kotlin/com/avsystem/justworks/core/gen/ModelGeneratorTest.kt
Show resolved
Hide resolved
- Streamline conditions for determining schema's underlying type - Avoid assigning invalid TypeRef instances in edge cases
|
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
…tion toTypeRef() resolves component schemas to self-referential TypeRef.Reference via componentSchemaIdentity, making underlyingType always null for primitive-only schemas. Extract resolveByType() to resolve structurally from type/format, and use it directly for underlyingType while still honoring $ref for wrappers. 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 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/src/main/kotlin/com/avsystem/justworks/core/parser/SpecParser.kt
Outdated
Show resolved
Hide resolved
Remove unreachable allOf single-ref branch from underlyingType resolution (isPrimitiveOnly requires allOf == null). Reformat to satisfy ktlint newline-before-?. rules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
- Add test cases for primitive, array, reference, object, and allOf schemas - Ensure proper behavior of underlyingType in various schema scenarios - Extend SpecParserTest to cover edge cases and validate correctness
Summary
underlyingType: TypeRef?field toSchemaModel— parser fills it for primitive-only schemas viatoTypeRef()TypeMapping.toTypeName()for dynamic type resolution instead of hardcodedSTRINGPrimitiveType.UUID)Test plan
./gradlew :core:testpasses🤖 Generated with Claude Code