Skip to content

Add fixture coverage for Kotlin kotlinx-serialization#2950

Merged
schani merged 1 commit into
masterfrom
kotlinx-fixture-coverage
Jul 19, 2026
Merged

Add fixture coverage for Kotlin kotlinx-serialization#2950
schani merged 1 commit into
masterfrom
kotlinx-fixture-coverage

Conversation

@schani

@schani schani commented Jul 19, 2026

Copy link
Copy Markdown
Member

Why

The Kotlin renderer's kotlinx-serialization framework (--framework kotlinx) had zero end-to-end fixture coverage — only klaxon (kotlin/schema-kotlin) and jackson (kotlin-jackson/schema-kotlin-jackson) were tested. Any change to KotlinXRenderer.ts shipped unvalidated. In particular, this unblocks #2845: once that PR rebases onto this, its kotlinx serializer changes get validated by CI.

What

  • test/fixtures/kotlinx/ — driver mirroring the klaxon/jackson fixtures: main.kt round-trips JSON through the generated @Serializable types using kotlinx-serialization-json (with explicitNulls = false so nulls are omitted on encode, matching the other Kotlin fixtures' allowMissingNull behavior). The runtime jars (1.7.3) are vendored like the klaxon/jackson jars; the compiler plugin ships inside the Kotlin distribution (lib/kotlinx-serialization-compiler-plugin.jar), which build.sh locates relative to kotlinc.
  • KotlinXLanguage in test/languages.ts, fixtures kotlinx / schema-kotlinx in test/fixtures.ts.
  • CI: new kotlinx,schema-kotlinx matrix entry on the 16-core runner (the existing contains(matrix.fixture, 'kotlin') conditions install Java + Kotlin for it).

Covered vs skipped

Every JSON input (priority, samples, misc) and every schema was compiled and round-tripped locally with kotlinc 2.1.20 to build the skip lists; each skip is a verified, pre-existing kotlinx renderer limitation, not a guess:

  • Unions (20 JSON inputs, 20 schemas): rendered as sealed classes with no serializer wiring — the documented TODO in KotlinXRenderer.ts; deserialization fails at runtime. The union feature is not claimed, so .fail.union.json samples don't run. feat(kotlin): Support for date and datetime from JSON schema #2845 fixes this; these skips can then be lifted.
  • Top-level arrays (40 JSON inputs, union.schema): rendered as typealias TopLevel = JsonArray<T>, which doesn't compile (kotlinx's JsonArray takes no type arguments) — also a documented TODO.
  • blns-object.json, identifiers.json: stringEscape emits astral-plane characters as 5-hex-digit \u escapes in @SerialName, which Kotlin misparses (4 digits only), so keys don't match.
  • keyword-unions.schema: unions, plus the synthesized serializer constructor exceeds the JVM 255-parameter limit.

Everything else runs — 149 of 211 JSON inputs and 46 of 67 schemas, including inputs the klaxon fixtures skip: simple-identifiers.json, no-classes.json, bug427.json, and the any, uuid, keyword-enum, top-level-enum, top-level-primitive, nested-intersection-union, and go-schema-pattern-properties schemas.

Local verification

  • FIXTURE=schema-kotlinx script/test: green (all 67 schemas, exit 0), with kotlinc 2.1.20 + Java 21.
  • FIXTURE=kotlinx script/test (full, including misc): every input was verified individually via generate→compile→run→compare with the harness's comparison semantics; the full harness run was still in progress when this PR was opened, so CI is the final gate there. The two misc skipDiffViaSchema entries (34702.json, 76ae1.json) mirror the klaxon list; diff-via-schema for priority/samples was verified to match klaxon's behavior exactly (only bug427.json/keywords.json differ). Misc inputs don't run in CI (QUICKTEST=true).

🤖 Generated with Claude Code

The kotlinx framework of the Kotlin renderer had no end-to-end fixture
coverage at all — only klaxon (kotlin/schema-kotlin) and jackson
(kotlin-jackson/schema-kotlin-jackson) were tested.

This adds kotlinx and schema-kotlinx fixtures:

- test/fixtures/kotlinx/: driver that round-trips JSON through the
  generated @serializable types with kotlinx-serialization-json (runtime
  jars vendored like the klaxon/jackson jars; the compiler plugin ships
  with the Kotlin distribution).
- KotlinXLanguage entry in test/languages.ts with skips for what the
  kotlinx renderer genuinely cannot do yet, all verified by compiling
  and round-tripping every input locally:
  - unions render as sealed classes with no serializer wiring
    (documented TODO in KotlinXRenderer.ts), so union inputs are
    skipped and the "union" feature is not claimed;
  - top-level arrays render as `typealias TopLevel = JsonArray<T>`,
    which does not compile;
  - astral-plane characters in property names are emitted as 5-hex-digit
    \u escapes in @SerialName, which Kotlin misparses.
- CI matrix entry kotlinx,schema-kotlinx on the 16-core runner.

Compared to the klaxon fixtures this also enables inputs klaxon cannot
handle: simple-identifiers.json, no-classes.json, bug427.json, and the
any, uuid, keyword-enum, top-level-enum, top-level-primitive,
nested-intersection-union, and go-schema-pattern-properties schemas.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schani
schani merged commit 1ba5a25 into master Jul 19, 2026
25 checks passed
@schani
schani deleted the kotlinx-fixture-coverage branch July 19, 2026 17:27
schani added a commit to nikhilunni/quicktype that referenced this pull request Jul 19, 2026
…erence

Merging master brought in the kotlinx fixture coverage from glideapps#2950,
whose skip lists were tuned against master, where Kotlin had no
date-time support. With this branch's date/time mapping:

- Declare the "date-time" feature for KotlinXLanguage. date-time.schema
  itself stays skipped because its union-array properties hit the
  kotlinx sealed-class union limitation; the emitted KSerializers are
  exercised by JSON inputs with inferred date-times instead.
- Skip the misc JSON inputs whose date-times carry trailing zeros in
  the fractional seconds, which java.time doesn't re-serialize
  identically — the same set already skipped for klaxon and jackson.
- Skip date-time-or-string.schema: its string|date-time property was a
  plain string before and now becomes a union.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant