Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Csharp/anyof oneof mixed primitive object parse error #16706

Conversation

ForgeRubenAguilar
Copy link
Contributor

@ForgeRubenAguilar ForgeRubenAguilar commented Oct 3, 2023

Deserialization fails for C# client models using anyOf/oneOf with json primitive/array types. Triages #16686

This is the current workaround we're using with just the templates, but afaik this will produce uncompilable code if the template needs to generate a ctor with Object args.

Rather than feeding everything to JObject which will fail for primitives/array json tokens. It uses a switch to deserialize the token appropriate to its json token type. The property setter does validation on the typing, though the types will be wrong for non-string types as JsonReader gives Int64s and Doubles back regardless of the json typing, which doesn't jive with the generated C# type validation in the setter.

I added the repro to issue data, but I was unsure where those tests would live. I saw mention of CI tests. Would that cover the in language generation?

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 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • 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)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Oct 3, 2023

FYI @mandrean (2017/08) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @iBicha (2023/07)

@wing328
Copy link
Member

wing328 commented Oct 3, 2023

Thanks for the PR.

Please add tests to the test spec and update test file to cover the issues moving forward.

test file: samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/JSONComposedSchemaTests.cs

test spec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

… object, and array types when deserializing

 Add bug openapi spec

Remove generated files

Add test endpoints

Generate base on spec

Remove issue spec as it is moved into sample test spec

Add back in number and int

Round trip anyOf/oneOf serialization tests

Generate classes with int/num types

Do through converter instead of object ctor

Regen models

Use convert methods

Regen models

Test data

Add enum

Remove enums

Regenned models
@ForgeRubenAguilar ForgeRubenAguilar force-pushed the csharp/anyof-oneof-mixed-primitive-object-parse-error branch from a1c188a to 606437d Compare October 13, 2023 04:03
@ForgeRubenAguilar
Copy link
Contributor Author

ForgeRubenAguilar commented Oct 13, 2023

@wing328 This should be ready now. Added some tests around the anyOf/oneOf round trip json serialization to samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/JSONComposedSchemaTests.cs

This solution only covers primitives. Covering enums will require more work around logic in the template building the json deserializer, especially with potentially mixed String/Enum type parsing.

@wing328
Copy link
Member

wing328 commented Oct 15, 2023

Some CI tests failed. Can you please take a look when you've time?

For https://github.com/OpenAPITools/openapi-generator/actions/runs/6503860025/job/17710059790?pr=16706, you will need to update ./bin/utils/test_file_list.yaml ?

@wing328 wing328 modified the milestones: 7.1.0, 7.2.0 Nov 13, 2023
@wing328 wing328 modified the milestones: 7.2.0, 7.3.0 Dec 22, 2023
@wing328 wing328 modified the milestones: 7.3.0, 7.4.0 Feb 8, 2024
@wing328
Copy link
Member

wing328 commented Feb 29, 2024

thanks for the PR. closed via #17986

@wing328 wing328 closed this Mar 9, 2024
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