Repository navigation
fix(tools): send OpenAPI operations to their own declared servers - #8088
Open
julienparenti wants to merge 1 commit into
Open
julienparenti wants to merge 1 commit into
julienparenti wants to merge 1 commit into
Conversation
|
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. |
OpenApiSpecParser picked the root servers[0].url once and reused it for every operation, so a path item or operation that declared its own servers was still called on the root server. Per the OpenAPI spec, operation-level servers override path-level servers, which override the root servers. Resolve the base URL per operation in that order; an empty servers list does not override the enclosing level. Fixes google#8064
julienparenti
force-pushed
the
fix/openapi-server-overrides
branch
from
November 10, 2026 21:55
8c042cd to
518500c
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
OpenApiSpecParserreads the rootservers[0].urlonce and uses it as thebase_urlof every operation. A path item or an operation that declares its ownserversis still called on the root server. The OpenAPI spec says operation-levelserversoverride path-levelservers, which override the rootservers.Solution:
Resolve the base URL per operation, in spec order: operation
servers, then pathservers, then rootservers, then""as before. An emptyserverslist does not override the enclosing level. The first server of the selected list is used, the same rule the parser already applies to the root servers.Requests to a per-operation server still go through the
RestApiToolURL validation, including the private-network block, because that check runs on the final request URL.Server variables (
{var}templating) are out of scope; they were not handled at the root level either.Testing Plan
Unit Tests:
Added to
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py:test_operation_servers_override_path_and_root_serverstest_path_servers_override_root_serverstest_path_servers_apply_when_no_root_serverstest_empty_operation_servers_fall_back_to_path_serversThe four tests fail on
mainand pass with the fix. Related suites:Full suite on all supported versions:
pre-commit runpasses on the changed files.mypyonopenapi_spec_parser.pyreports the same 12 errors as onmain, none on the changed lines.Manual End-to-End (E2E) Tests:
Three local HTTP servers each answer with their own name. An
OpenAPIToolsetis built from a spec where/items GETdeclares operation servers,/itemsdeclares path servers, and/healthrelies on the root server. Each generated tool is called, so a real HTTP request is sent:Before (
main):After:
Checklist