openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Csharp][GenericHost] Client serialization of oneOf repeats discriminator

Open gerwinjansen opened this issue 1 year ago • 8 comments

Fixes #16597 @mandrean @shibayan @Blackclaws @lucamazzanti @iBicha

In case of a submodel with sub-submodel (e.g. Shape with submodel Triangle, which has submodel EquilateralTriangle), the removal of the properties must start from the root. If Triangle is cleaned first, then Shape doesn't know which properties to remove anymore.

PR checklist

  • [x] Read the contribution guidelines.
  • [x] 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.
  • [x] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH) 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.
  • [x] File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • [x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

gerwinjansen avatar Dec 14 '23 10:12 gerwinjansen

This is an obvious improvement, though what I would really like to see is for the discriminator string not be in any of the classes. Once you're in the class, the discriminator is known, so requiring a string in the constructor is redundant. See this Whale constructor. We known it's a whale, so the string doesn't really need to be there at all. It's okay if we want to merge this though since it appears to fix the problem.

image

devhl-labs avatar Dec 14 '23 23:12 devhl-labs

@gerwinjansen can you please take a look at the test failure when you've time?

https://github.com/OpenAPITools/openapi-generator/actions/runs/7247593357/job/20330032075?pr=17397

wing328 avatar Jan 10 '24 05:01 wing328

@wing328: I fixed it, it is ready for the next run. Please approve.

gerwinjansen avatar Feb 26 '24 18:02 gerwinjansen

Error:  Failures: 
Error:    CSharpGenericHostDiscriminatorTest.oneOfWithReferencesAndDiscriminatorTest:43 » NullPointer
Error:  Tests run: 2110, Failures: 1, Errors: 0, Skipped: 0
Error:  Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0:test (default-test) on project openapi-generator: There are test failures.
Error:  
Error:  Please refer to /home/runner/work/openapi-generator/openapi-generator/modules/openapi-generator/target/surefire-reports for the individual test results.
Error:  Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
Error:  -> [Help 1]
Error:  
Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
Error:  Re-run Maven using the -X switch to enable full debug logging.
Error:  
Error:  For more information about the errors and possible solutions, please read the following articles:

can you please take a look at the build failure when you've time?

ref: https://github.com/OpenAPITools/openapi-generator/actions/runs/8052044583/job/22465390581?pr=17397

wing328 avatar Mar 09 '24 10:03 wing328

@wing328: I fixed it, it is ready for the next run. Please approve.

gerwinjansen avatar Mar 21 '24 13:03 gerwinjansen

This change wont be needed once my remove discrim pr is merged.

devhl-labs avatar Apr 25 '24 11:04 devhl-labs

Can you try my branch to see if it works for you? https://github.com/OpenAPITools/openapi-generator/pull/18445

devhl-labs avatar May 05 '24 18:05 devhl-labs

@devhl-labs: yes, it works for me. This PR can be closed without merge if your PR gets approved.

gerwinjansen avatar May 06 '24 15:05 gerwinjansen