fix(openapi): let operation parameters override path-level ones - #7219
Open
CodeTrainerMan wants to merge 2 commits into
Open
CodeTrainerMan wants to merge 2 commits into
CodeTrainerMan wants to merge 2 commits into
Conversation
OpenAPI 3 says an operation-level parameter overrides a path-level one with the same name and in. _collect_operations concatenated both lists instead, so a path parameter declared at the path level and refined on an operation was collected twice. OperationParser renamed the duplicate to account_id_0, the model was asked for the same URL segment as two required arguments, and the path-level value won when both were filled, silently dropping the operation's more specific parameter from the request. Merge the two lists with _merge_parameters, which keys each parameter on (name, in) and drops the path-level entries the operation re-declares. Parameters missing name or in are never deduplicated away. Fixes google#7205
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
CodeTrainerMan
force-pushed
the
fix/openapi-operation-parameter-override
branch
from
September 20, 2026 21:09
906740a to
7167007
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
OpenApiSpecParser._collect_operations()merged the path item'sparametersinto the operation's with a plain concatenation:The OpenAPI 3 Path Item Object says an operation-level parameter overrides a path-level parameter with the same
nameandin. Declaring a shared path parameter once at the path level and refining it on an operation (a more specific description,patternorenum) is common, so both declarations ended up collected.OperationParserde-duplicates by name and renames the second one, so the tool asked the model for the same URL segment twice as two required arguments:Both values map to the same
{accountId}placeholder; the path-level one wins, so the operation's own more specific parameter is silently dropped from the request.Solution:
Merge the two lists with a new
_merge_parameters()helper that keys each parameter on(name, in)and drops the path-level entries the operation re-declares. Parameters missingnameorinare never deduplicated away, so malformed specs behave exactly as before. The operation's parameters keep their leading position, so the ordering of the generated declaration is unchanged except for the removed duplicate.Testing Plan
Unit Tests:
Three tests added to
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py:test_operation_parameter_overrides_path_level_parameter- the reproducer from the issue now yields a singleaccount_idparameter carrying the operation-level description.test_path_level_parameters_are_still_collected- a path-level parameter the operation does not redeclare is still collected.test_parameters_with_same_name_different_location_are_both_kept-inparticipates in the override key, so a same-named query parameter is not deduplicated.That directory had 208 passing tests before the change (28 in
test_openapi_spec_parser.py, the rest intest_openapi_toolset.py/test_rest_api_tool.py), so the 3 new tests account for the delta and nothing else regressed.pyinkandisortreport both changed files unchanged.Manual End-to-End (E2E) Tests:
Before the fix, parsing the issue's spec printed 2 parameters; after it prints 1:
No E2E run against a live API was needed - the defect is in tool declaration and request building, which the parser unit tests cover directly.
Checklist
Additional context
The fix is confined to parameter collection at parse time.
RestApiToolis untouched, and thestyle/explodeserialization gap in query parameters reported in #7204 is a separate change and is not addressed here.