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

Adding decimal support for python client generation #19203

Merged
merged 6 commits into from
Jul 23, 2024

Conversation

m-standfuss
Copy link
Contributor

@m-standfuss m-standfuss commented Jul 19, 2024

Adding decimal support for python client generation

This PR adds the ability to handle Decimal objects coming in and out of python servers. We "recognize" the open api decimal field and map it correctly to the python Decimal class. I consider this a non-breaking change because prior to this if a decimal field was used to generate python client library it just didnt work on decimal fields.

#19198

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.

CC Python community for 👀
@cbornet @tomplus @krjakbrjak @fa0311 @multani

Copy link
Contributor

@multani multani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have time, could you regenerate the sample files as explained in the pull request checklist? It should update several files automatically.

Would you also be able to add a couple of tests to verify that serializing/deserializing objects with decimal work as expected? This would be useful to prevent regression in the future. The "echo client" sample should be a good starting point.

Thanks!

@m-standfuss
Copy link
Contributor Author

@multani thank you for looking. I have ran the build steps now and pushed up the commit. Thank you for the example test I will get some coverage added to the branch this weekend and hit you back up to look.

@m-standfuss
Copy link
Contributor Author

@multani curious if you can shoot a link to the "echo client" you were referring to? I found this but just wanted to make sure I am in the right spot as there were a couple other spots that looked similar.

@multani
Copy link
Contributor

multani commented Jul 21, 2024

I was thinking of this sample: https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/echo_api/python

One example of a past change:
5e95464

@wing328
Copy link
Member

wing328 commented Jul 21, 2024

@m-standfuss here is another good starting point to add some tests:

def test_sanitize_for_serialization_list(self):

you can find other tests for sanitize_for_serialization in that test file

@m-standfuss
Copy link
Contributor Author

Thank you @wing328 and @multani! will get some good coverage included.

@m-standfuss
Copy link
Contributor Author

@wing328 and @multani sorry took a minute to get these running locally.

Added to an existing test for serialization and added a new test for deserialization. Please let me know if they are not in the right spot or you would like to see more. Thanks again!

Copy link
Contributor

@multani multani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM 👍

Comment on lines 158 to 162
# decimal
data = Decimal("1.0")
result = self.api_client.sanitize_for_serialization(data)
self.assertEquals(result, "1.0")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can you move this into samples/openapi3/client/petstore/python/tests/test_api_client.py instead?

The "pydantic v1" backend will be removed at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good catch, thats on me, fixing now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@multani @wing328 do i need to worry about the failing steps in the build? They appear to be failures to install poetry for the v1 petstore sample.

Run pipx install --python '/opt/hostedtoolcache/Python/3.7.17/x64/bin/python' poetry
creating virtual environment...
installing poetry...
Fatal error from pip prevented installation. Full pip output in file:
    /opt/pipx/logs/cmd_2024-07-22_16.55.46_pip_errors.log

Some possibly relevant errors from pip install:
    TypeError: Expected maxsize to be an integer or None
Error installing poetry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I can't retry, but I don't think it's related to your change :)

Copy link
Contributor

@multani multani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last cleanup to remove, and it looks good to me afterwards 👍

Comment on lines 12 to 13
import os
import time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this change? It has nothing to do with your original PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep yep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@multani multani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍
Thanks for the change and the tests!

@wing328 wing328 merged commit 6ad5864 into OpenAPITools:master Jul 23, 2024
33 checks passed
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