Skip to content

Conversation

fkellner
Copy link
Contributor

The ModelUtils.getParentName function description states:

If there are multiple elements in the composed schema and it is not clear which one should be the parent, return null.

It returned the first parent candidate instead. This resulted in a weird bug where generated client models did not contain all fields of their subschemas mentioned in oneOf (fixes #21773 , in particular this affects at least Java Microprofile and Vertx generators).

This PR contains some new tests:

  • one regression test for the fixed function (in ModelUtilsTest)
  • one test case with the (simplified) spec that discovered the bug in JavaCodegenTest (and also in DefaultCodegenTest to narrow it down)

Also, the oneOf-Test was changed to contain three schemas, because at first I thought the issue was with the number of schemas and in general it is probably better to test something accepting a list with three instead of two elements.

Running the scripts to update samples and docs did not change anything (as was to be expected).

Please tell me if I should

  • rebase this onto latest master
  • squash the commits
  • rename the example yaml to something different

Also, since I found this mostly via debugging and am not proficient with the terminology and edge cases of this project, my fix follows the philosophy to touch/change as little as possible, however, somebody with more experience than me might want to clean up that function since there seems to be some unreachable/unused code according to my IDE.

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.

@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg

@wing328
Copy link
Member

wing328 commented Aug 22, 2025

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@fkellner
Copy link
Contributor Author

Thank you very much, adding the email address fixed it!

@fkellner
Copy link
Contributor Author

since there was a failing check that is probably due to the branch being based on an outdated master, I synced the branch.

@wing328
Copy link
Member

wing328 commented Sep 1, 2025

please

  • merge the latest master into your branch and resolve the merge conflicts
  • update the samples

then i will try to test your fix before merging

@wing328 wing328 added this to the 7.16.0 milestone Sep 1, 2025
@fkellner fkellner force-pushed the bugfix/one-of-three branch from 6007e7e to e0786cd Compare September 1, 2025 08:08
@wing328
Copy link
Member

wing328 commented Sep 1, 2025

https://github.com/OpenAPITools/openapi-generator/actions/runs/17371620947/job/49309557740?pr=21799

please run the command to update the samples one more time

@wing328
Copy link
Member

wing328 commented Sep 2, 2025

did a test locally and all tests passed

#21859

@wing328
Copy link
Member

wing328 commented Sep 2, 2025

we will later revise the test instead if it still occurs after merging into master

thanks for the PR to fix the bug

@wing328 wing328 merged commit efd06f5 into OpenAPITools:master Sep 2, 2025
151 of 158 checks passed
@wing328
Copy link
Member

wing328 commented Sep 2, 2025

update: merged #21865 to disable the tests (which only failed in Windows but not Linux)

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.

[BUG] OneOf-Generation does not work with more than two child schemas
2 participants