test(kotlin-client): compile gson anyOf/oneOf wrappers for [number, string]

Merged
RA
4d ago
+32-0

Adds a regression test that generates the kotlin client with jvm-retrofit2 + serializationLibrary=gson + generateOneOfAnyOfWrappers=true for an anyOf [number, string] and a oneOf [number, string] schema, then compiles the generated model sources with KotlinTestUtils.buildModule and checks that both wrapper classes (AnyOfValue, OneOfValue) load.

This was requested by @AndreyVMarkelov in review of #25246. That PR rewrites the gson error messages in kotlin-client/anyof_class.mustache and leaves a trailing comma after the Number message inside a require { } block:

require(jsonElement.getAsJsonPrimitive().isNumber()) {
    "Expected json element to be of type Number in the JSON string but got `${jsonElement}`",
}

Existing tests only check the generated text, so they don't catch this. Compiling the output does.

  • Test: KotlinClientCodegenModelTest#testGsonAnyOfOneOfNumberStringWrappersCompile
  • Spec: reuses src/test/resources/3_0/kotlin/issue25452-anyof-oneof-number.yaml, which already has exactly one anyOf and one oneOf over string/number and nothing else
  • Test only: no template, generator or dependency changes (gson is already a test-scope dependency)

Verified locally:

  • master: passes (1 test, 0 failures, 0 errors)
  • master + #25246's anyof_class.mustache: fails to compile with AnyOfValue.kt:104:117: error: unexpected tokens (use ';' to separate expressions on the same line). Column 117 is that trailing comma.

Run it with:

./mvnw -q -pl modules/openapi-generator -am test -Dtest='KotlinClientCodegenModelTest#testGsonAnyOfOneOfNumberStringWrappersCompile' -Dsurefire.failIfNoSpecifiedTests=false

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    This is a test-only change, so no samples or docs change. Only the targeted test was run locally.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    Kotlin TC: @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l @AndreyVMarkelov

šŸ¤– Generated with Claude Code


Summary by cubic

Adds a regression test that compiles the generated Kotlin client sources for anyOf/oneOf [number, string] wrappers with jvm-retrofit2 and serializationLibrary=gson. Existing tests only check generated text, so they miss syntax errors like the trailing comma in the Number error message inside anyof_class.mustache that breaks AnyOfValue.kt; the new test fails on that output.

The test is KotlinClientCodegenModelTest#testGsonAnyOfOneOfNumberStringWrappersCompile and reuses the existing issue25452-anyof-oneof-number.yaml spec. It's test-only: no template, generator, or dependency changes.