Skip to content

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

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
raunak2007:test/kotlin-anyof-number-string-gson
Nov 16, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
raunak2007:test/kotlin-anyof-number-string-gson

Conversation

@raunak2007

@raunak2007 raunak2007 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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:

Run it with:

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

PR checklist

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

Written for commit 1cc1cb9. Summary will update on new commits.

View guided diff

…tring]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

@wing328
wing328 merged commit 3ab4ef3 into OpenAPITools:master Nov 16, 2026
15 checks passed
@wing328 wing328 added this to the 7.28.0 milestone Nov 26, 2026
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.

2 participants