Skip to content

feat: dynamic typealias for non-String inline schemas#19

Merged
halotukozak merged 9 commits intomasterfrom
feat/typealias-non-string-primitives
Mar 23, 2026
Merged

feat: dynamic typealias for non-String inline schemas#19
halotukozak merged 9 commits intomasterfrom
feat/typealias-non-string-primitives

Conversation

@halotukozak
Copy link
Member

Summary

  • Add underlyingType: TypeRef? field to SchemaModel — parser fills it for primitive-only schemas via toTypeRef()
  • Generator uses TypeMapping.toTypeName() for dynamic type resolution instead of hardcoded STRING
  • Supports: Int, Long, Double, Float, Boolean, ByteArray, List, and reference wrappers
  • UUID typealias will work automatically once PR feat: extend format-to-type mapping with UUID support #17 merges (adds PrimitiveType.UUID)

Test plan

  • 7 new typealias tests: Int, Boolean, Long, Double, Array, Reference, String regression
  • ./gradlew :core:test passes

🤖 Generated with Claude Code

halotukozak and others added 2 commits March 20, 2026 13:50
- 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>
Copilot AI review requested due to automatic review settings March 20, 2026 13:05
@github-actions
Copy link

Overall Project 93.38% -0.03% 🍏
Files changed 97.5% 🍏

File Coverage
ApiSpec.kt 99.28% 🍏
ModelGenerator.kt 94.72% 🍏
SpecParser.kt 88.96% -0.1% 🍏

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 SchemaModel with underlyingType: TypeRef? to represent the resolved underlying schema type for primitive-only schemas.
  • Populate underlyingType in SpecParser and use it in ModelGenerator (via TypeMapping.toTypeName) when generating typealiases.
  • Expand ModelGeneratorTest coverage 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.

halotukozak and others added 2 commits March 20, 2026 14:52
- Streamline conditions for determining schema's underlying type
- Avoid assigning invalid TypeRef instances in edge cases
@github-actions
Copy link

Overall Project 93.38% -0.05% 🍏
Files changed 96.33% 🍏

File Coverage
ApiSpec.kt 99.28% 🍏
ModelGenerator.kt 94.72% 🍏
SpecParser.kt 89.01% -0.2% 🍏

@github-actions
Copy link

Overall Project 93.38% -0.05% 🍏
Files changed 96.33% 🍏

File Coverage
ApiSpec.kt 99.28% 🍏
ModelGenerator.kt 94.72% 🍏
SpecParser.kt 89.01% -0.2% 🍏

Copy link
Contributor

Copilot AI left a comment

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 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.

…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>
Copy link
Contributor

Copilot AI left a comment

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 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.

@halotukozak halotukozak self-assigned this Mar 20, 2026
halotukozak and others added 2 commits March 20, 2026 15:14
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>
@github-actions
Copy link

Overall Project 93.43% -0.51% 🍏
Files changed 87.03% 🍏

File Coverage
ApiSpec.kt 99.28% 🍏
ModelGenerator.kt 94.72% 🍏
SpecParser.kt 89.22% -1.85% 🍏

@github-actions
Copy link

Overall Project 93.23% -0.72% 🍏
Files changed 82.35% 🍏

File Coverage
ApiSpec.kt 99.28% 🍏
ModelGenerator.kt 94.72% 🍏
SpecParser.kt 88.52% -2.62% 🍏

@halotukozak halotukozak requested a review from MattK97 March 20, 2026 14:36
- 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
@halotukozak halotukozak requested a review from MattK97 March 23, 2026 09:43
@halotukozak halotukozak merged commit dec23c9 into master Mar 23, 2026
1 check failed
@halotukozak halotukozak deleted the feat/typealias-non-string-primitives branch March 23, 2026 10:30
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