-
Notifications
You must be signed in to change notification settings - Fork 336
fix: normalize api key scheme in alias #646
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
base: main
Are you sure you want to change the base?
fix: normalize api key scheme in alias #646
Conversation
Summary of ChangesHello @Wondr-design, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a serialization/deserialization issue in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly normalizes the in_ field to in for APIKeySecurityScheme by adding a Pydantic field alias. The accompanying tests are well-written and effectively validate the change, ensuring both deserialization from in and in_ and serialization to in work as expected. The suggestion to refactor one of the new tests to be parameterized, which would improve maintainability and consolidate test logic, has been kept. Overall, this is a solid fix.
tests/test_types.py
Outdated
| def test_security_scheme_accepts_in_field_name(): | ||
| scheme = SecurityScheme.model_validate( | ||
| { | ||
| 'type': 'apiKey', | ||
| 'in_': 'header', | ||
| 'name': 'X-API-KEY', | ||
| } | ||
| ) | ||
| assert isinstance(scheme.root, APIKeySecurityScheme) | ||
| assert scheme.root.in_ == In.header | ||
| assert scheme.model_dump(mode='json', exclude_none=True)['in'] == 'header' |
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.
For better test coverage and maintainability, you could use a parameterized test to verify that both in and in_ are handled correctly during deserialization, and that the model always serializes to in. This would combine the logic of this test and test_security_scheme_valid into a single, more comprehensive test case.
| def test_security_scheme_accepts_in_field_name(): | |
| scheme = SecurityScheme.model_validate( | |
| { | |
| 'type': 'apiKey', | |
| 'in_': 'header', | |
| 'name': 'X-API-KEY', | |
| } | |
| ) | |
| assert isinstance(scheme.root, APIKeySecurityScheme) | |
| assert scheme.root.in_ == In.header | |
| assert scheme.model_dump(mode='json', exclude_none=True)['in'] == 'header' | |
| @pytest.mark.parametrize("in_field_name", ["in", "in_"]) | |
| def test_security_scheme_in_field_handling(in_field_name: str): | |
| scheme_data = { | |
| 'type': 'apiKey', | |
| 'name': 'X-API-KEY', | |
| in_field_name: 'header', | |
| } | |
| scheme = SecurityScheme.model_validate(scheme_data) | |
| assert isinstance(scheme.root, APIKeySecurityScheme) | |
| assert scheme.root.in_ == In.header | |
| serialized_data = scheme.model_dump(mode='json', exclude_none=True) | |
| assert serialized_data.get('in') == 'header' | |
| assert 'in_' not in serialized_data |
|
Updated tests/test_types.py to use a single parametrized test that validates both 'in' and 'in_' inputs and ensures serialization always outputs 'in'. Ran: uv run pytest tests/test_types.py. |
|
CI import-file-mismatch was due to duplicate module name (tests/server/apps/jsonrpc/test_serialization.py vs tests/server/apps/rest/test_serialization.py). Renamed REST test to tests/server/apps/rest/test_rest_serialization.py to make the module name unique; reran local test for that file. |
|
Pushed a lint fix for PYI034 in |
|
Updated |
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.
This file shouldn't be manually edited. The alias should be added automatically from BaseModel in https://github.com/a2aproject/a2a-python/blob/main/src/a2a/_base.py
Description
Testing
Fixes #615