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

Fix problem in sanitize_for_serialization for Python (pydantic type SecretStr ) BUG#16086 (2nd pull) #18023

Merged
merged 22 commits into from
Mar 20, 2024

Conversation

azdolinski
Copy link
Contributor

#16086
handling SecretStr for the password field

this is 2nd pull try
history and more explanation in: #17310

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.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.

@@ -366,7 +371,11 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):

Copy link
Member

@wing328 wing328 Mar 9, 2024

Choose a reason for hiding this comment

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

can you please remove this extra blank line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you please remove this extra blank line?

done

@wing328
Copy link
Member

wing328 commented Mar 9, 2024

@azdolinski
Copy link
Contributor Author

please also review the test failure when you've time...

if complains:

tests/test_model.py:415: error: Argument "password" to "LoginTest" has incompatible type "str"; expected "SecretStr"  [arg-type]

I set password as SecretStr:

l = LoginTest(username="admin", password=SecretStr("testing09876"))

@@ -408,7 +408,12 @@ def test_valdiator(self):
self.assertEqual(a.pattern_with_digits_and_delimiter, "image_123")

# test sanitize for serializaation with SecretStr (format: password)
self.assertEquals(petstore_api.ApiClient().sanitize_for_serialization(a), {'byte': b'string', 'date': '2013-09-17', 'number': 123.45, 'password': 'testing09876', 'pattern_with_digits_and_delimiter': 'image_123'})
Copy link
Member

Choose a reason for hiding this comment

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

thanks for adding another test below

shouldn't this test/assertion still pass after this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shouldn't this test/assertion still pass after this change?

yes, you are right... it can make sense to keep this line also as in case of password which will be as default string - it will also work. I added this line back to this pull.. 0ed3ba4 + will check sanitize function based on bytes/date/integer data types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wing328 - can you please check and confirm that now is ok?

@wing328
Copy link
Member

wing328 commented Mar 18, 2024

cc
@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10) @multani (2023/10)

@wing328 wing328 added this to the 7.5.0 milestone Mar 18, 2024
Copy link
Contributor

@fa0311 fa0311 left a comment

Choose a reason for hiding this comment

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

LGTM!

@wing328 wing328 merged commit c15e267 into OpenAPITools:master Mar 20, 2024
34 checks passed
zapodot pushed a commit to zapodot/openapi-generator that referenced this pull request Mar 21, 2024
…ecretStr ) BUG#16086 (2nd pull) (OpenAPITools#18023)

* fix-for-bug-16086

* add to_dict alternative

* fix assertEqual

* remove extra blank line + test_model Argument SecretStr set

* update samples / remove extra blank line

* restore sanitize test for serialization with different data types

* remove empty line in api_client.mustache

* remove 2nd empty line in api_client.mustache
webertim pushed a commit to webertim/openapi-generator that referenced this pull request Nov 13, 2024
wing328 pushed a commit that referenced this pull request Nov 16, 2024
…ng changes from #18023 (#20102)

* Apply changes of #18023

* Regenerate samples

---------

Co-authored-by: tweber2 <[email protected]>
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.

3 participants