-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Python: Correctly serialize enum with its value (#18327) #18328
Python: Correctly serialize enum with its value (#18327) #18328
Conversation
Is there any way to add a test that would run the generated Python code ? (IE a pytest) |
@BaptisteSaves you can add a new test, for instance in this folder: https://github.com/OpenAPITools/openapi-generator/tree/master/samples/openapi3/client/petstore/python/tests |
here is an example on how to add a test: https://github.com/OpenAPITools/openapi-generator/pull/18272/files#diff-865b48c6f08b84b32f8fa35cc3bf6c755b919e5f05c4c2bb157ea9ea589bba0aR622 |
3ce3d78
to
5c6aa61
Compare
please ignore https://github.com/OpenAPITools/openapi-generator/actions/runs/8614615152/job/23608628515?pr=18328 for the time being. i'll take a look update: fixed in the latest master |
@@ -358,6 +358,8 @@ class ApiClient: | |||
""" | |||
if obj is None: | |||
return None | |||
elif isinstance(obj, Enum): | |||
return obj.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to write a unit test for sanitize_for_serialization with enum ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
f741fc7
to
cea69ce
Compare
cea69ce
to
7309537
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! thanks!
7309537
to
ef86851
Compare
Fixes #18327
Add a serialization case when it is an enum to use its value and not its name.
PR checklist
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.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)cc @cbornet @tomplus @krjakbrjak @fa0311 @multani