fix(kotlin): preserve enum string values in --just-types mode#3007
Merged
Conversation
Kotlin's base renderer (used by --just-types) emitted bare enum constants, dropping the original JSON string associated with each case. Every other Kotlin framework (Klaxon, Jackson, kotlinx) and Java's --just-types already preserve this value, making --just-types Kotlin enums an inconsistent, lossy outlier. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Kotlin
--just-typesoutput dropped the original string value associatedwith each enum case. Given:
quicktype --lang kotlin --just-typesproduced:with no way to recover which JSON string (
"add","bringtofront", ...)each case originally corresponded to.
Root cause
Kotlin's base
KotlinRenderer(used by--just-typesmode) had its ownemitEnumDefinitionthat emitted a bareenum classwith no valueinformation. Every other Kotlin framework — Klaxon, Jackson, and kotlinx —
overrides
emitEnumDefinitionand does preserve the value via avalue: Stringconstructor arg plus afromValue/toValuemapping. Java's--just-typesmode also preserves the value (viatoValue()/forValue()),without depending on any JSON library. So Kotlin
--just-typeswas theoutlier, silently losing information other modes and other languages
already keep.
Fix
KotlinRenderer.emitEnumDefinitionnow emits each case with its original(escaped) string value as a constructor argument, plus a framework-independent
companion objectwith afromValue(value: String): EnumNamelookup —consistent with the shape already used by the other Kotlin renderers, but
with no dependency on any JSON library (as required for
--just-typesmode):
Test coverage
Added a regression test to
test/unit/just-types-option.test.tsthatgenerates Kotlin
--just-typesoutput from the exact TypeScript enum fromthe issue report and asserts the case constructors carry their original
string values and that a
fromValuelookup is emitted. The test wasconfirmed to fail against the unfixed renderer and pass after the fix.
A unit test (rather than a JSON/JSON Schema fixture) was used because there
is no existing compile-and-run fixture for Kotlin
--just-typesmode (thatmode has no serialization to round-trip, which appears to be why one was
never set up for it), matching the precedent already established by the
other
--just-typesassertions in that same test file.Verification
npm run build— passes.npm run test:unit— 164/164 tests pass.(
node dist/index.js --lang kotlin --just-types canvas.ts) and confirmedthe generated output now preserves the enum values.
kotlinc) is not available in thisenvironment, so the compile-and-run Kotlin fixtures (Klaxon, Jackson,
kotlinx) could not be executed locally. This change only modifies
KotlinRenderer.emitEnumDefinition, which every one of those threeframeworks overrides with its own implementation, so it should have no
effect on their generated output; CI will validate this.
Fixes #1601
🤖 Generated with Claude Code