Skip to content

[Python] Correct sanitize_for_serialization in python generator for list in oneOf schema elements #19405

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

Conversation

karge-itestra
Copy link
Contributor

@karge-itestra karge-itestra commented Aug 21, 2024

The method did not consider the objects created for oneOf schemata. If one of the cases was a list, to_dict would return it instead of something that has an items() method.

This should be reviewed by members of the python technical committee:
@cbornet @tomplus @krjakbrjak @fa0311 @multani

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
    
    (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.
  • File the PR against the correct branch: master (upcoming 7.6.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.

…Tools#18106

The method did not consider the objects created for oneOf schemata. If one of the cases was a list, to_dict would return it instead of something that has an items() method.
@karge-itestra karge-itestra changed the title correct sanitize_for_serialization in python generator, fixes #18106 Correct sanitize_for_serialization in python generator for list in oneOf schema elements, fixes #18106 Aug 21, 2024
@wing328
Copy link
Member

wing328 commented Aug 21, 2024

thanks for the PR

please follow step 3 to regenerate the samples so that CI can verify the change

@karge-itestra
Copy link
Contributor Author

thanks for the PR

You´re welcome :)

please follow step 3 to regenerate the samples so that CI can verify the change

Done, compiling took a long time but it and the sample generation lead to the desired result. I am not sure what should happen in the export_docs_generators.sh, it did not change anything in the repo

@karge-itestra karge-itestra changed the title Correct sanitize_for_serialization in python generator for list in oneOf schema elements, fixes #18106 [Python] Correct sanitize_for_serialization in python generator for list in oneOf schema elements, fixes #18106 Aug 22, 2024
@wing328
Copy link
Member

wing328 commented Aug 25, 2024

I wonder if you can add a test or 2 in

def test_sanitize_for_serialization_decimal(self):

@karge-itestra
Copy link
Contributor Author

I wonder if you can add a test or 2 in

def test_sanitize_for_serialization_decimal(self):

The problem I see there is that the pet store example schema doesn´t contain a oneOf part. Adding that or creating a new test exceeds my disposable time. If you provide a stub or two (maybe modeled after the referenced issue #18106), I can implement it.

@denys999
Copy link

@wing328 @karge-itestra can we merge?

@denys999
Copy link

it is already 7.12.0

@denys999
Copy link

@wing328 @karge-itestra
Can you also include something similar for model_oneof.mustache?

        # handle list
        if isinstance(self.actual_instance, list):
            return [item.to_dict() for item in self.actual_instance]

@karge-itestra
Copy link
Contributor Author

@denys999 I have never worked with Mustache, but I can take a look. I would have liked to merge much earlier, but @wing328 asked for tests that I didn´t have the time to design, because the schemas that the tests used lacked cases for testing the behavior, and adding them is much more effort than only writing a testcase.

@ChristophMatthies
Copy link

Hi everyone, thanks for taking a look at this!
@denys999 we'd be very happy to have the fix for the model_oneof.mustache that you proposed.

Any updates on this or some way that I can help out?

@wing328
Copy link
Member

wing328 commented Apr 1, 2025

@ChristophMatthies did you test the fix locally using customized templates (e.g. -t via cli)?

@karge-itestra
Copy link
Contributor Author

karge-itestra commented May 15, 2025

If that helps you @wing328 , I did test that on a real-world usecase which I cannot disclose. Probably updating the API Specs for the tests or adding a new one that includes the case from the issue would be the easiest way to achieve convincing coverage.

@wing328
Copy link
Member

wing328 commented May 20, 2025

👌

will get it merged and see if anyone from the community can contribute a test or 2 later

@wing328 wing328 merged commit 894008f into OpenAPITools:master May 20, 2025
33 checks passed
@wing328 wing328 added this to the 7.14.0 milestone Jun 19, 2025
@wing328 wing328 changed the title [Python] Correct sanitize_for_serialization in python generator for list in oneOf schema elements, fixes #18106 [Python] Correct sanitize_for_serialization in python generator for list in oneOf schema elements Jun 19, 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.

4 participants