Skip to content

[java] fix: five nondeterministic tests#22513

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
yonghanlin:fix/nondeterminism_tests
Dec 9, 2025
Merged

[java] fix: five nondeterministic tests#22513
wing328 merged 1 commit intoOpenAPITools:masterfrom
yonghanlin:fix/nondeterminism_tests

Conversation

@yonghanlin
Copy link
Copy Markdown
Contributor

@yonghanlin yonghanlin commented Dec 8, 2025

This pull request fix five non-deterministic tests that are detected by NonDex, a tool for detecting wrong assumptions on under-determined Java APIs.

Problem

  • In ExampleGeneratorTest (generateFromResponseSchemaWithAllOfChildComposedModel, generateFromResponseSchemaWithAllOfComposedModel, and generateFromResponseSchemaWithDateFormat):
    The test compared the generated example against a single hard-coded JSON string. When the underlying JSON object fields were emitted in a different order, the assertion failed even though the structure and values were correct.

  • JavaClientCodegenTest.testNotDuplicateOauth2FlowsScopes:
    This test assumed a fixed iteration order of getWithBasicAuthAndOauth.authMethods and getWithOauthAuth.authMethods, i.e., that index 0 would always be basic_auth and subsequent entries would always correspond to specific OAuth2 flows. Under NonDex, the backing collection order can change, causing intermittent failures.

  • JetbrainsHttpClientClientCodegenTest.testBasicGenerationManyAuths:
    The test relied on a specific block layout in the generated .http file. NonDeterminism in generation (e.g., heading level changes or header ordering) caused the entire assertion to fail even when the essential content was still present.

To reproduce the failures, run NonDex on modules/openapi-generator using the following commands:

mvn -pl modules/openapi-generator edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=packageName.ClassName#methodName

Replace packageName.ClassName#methodName with one of:

org.openapitools.codegen.ExampleGeneratorTest#generateFromResponseSchemaWithAllOfChildComposedModel
org.openapitools.codegen.ExampleGeneratorTest#generateFromResponseSchemaWithAllOfComposedModel
org.openapitools.codegen.ExampleGeneratorTest#generateFromResponseSchemaWithDateFormat
org.openapitools.codegen.java.JavaClientCodegenTest#testNotDuplicateOauth2FlowsScopes
org.openapitools.codegen.jetbrains.http.client.JetbrainsHttpClientClientCodegenTest#testBasicGenerationManyAuths

The Fix

  • In ExampleGeneratorTest (generateFromResponseSchemaWithAllOfChildComposedModel, generateFromResponseSchemaWithAllOfComposedModel, and generateFromResponseSchemaWithDateFormat):
    Construct an ObjectMapper and compare JsonNode by mapper.readTree(...) for both the expected JSON and examples.get(0).get("example"), so the assertion focuses on field values while ignoring non-deterministic JSON key ordering.

  • JavaClientCodegenTest.testNotDuplicateOauth2FlowsScopes:
    Copy authMethods into new lists and sort them by name before performing assertions. This keeps the intent while avoiding reliance on the original collection iteration order.

  • JetbrainsHttpClientClientCodegenTest.testBasicGenerationManyAuths:
    Update the assertions to check that the generated .http file contains the expected sections, request lines, and headers regardless of their order or heading level, instead of depending on a single fixed layout.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@yonghanlin yonghanlin changed the title fix: three nondeterministic tests [java] fix: three nondeterministic tests Dec 8, 2025
@yonghanlin yonghanlin force-pushed the fix/nondeterminism_tests branch from 7f9a0cd to f2ffeed Compare December 9, 2025 02:15
@yonghanlin yonghanlin changed the title [java] fix: three nondeterministic tests [java] fix: five nondeterministic tests Dec 9, 2025
@wing328 wing328 merged commit 3b232f6 into OpenAPITools:master Dec 9, 2025
14 checks passed
@wing328 wing328 added this to the 7.18.0 milestone Dec 9, 2025
lucy66hw pushed a commit to lucy66hw/openapi-generator that referenced this pull request Dec 16, 2025
rajvesh pushed a commit to rajvesh/openapi-generator that referenced this pull request Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants