fix: substitute server variable defaults when building base URL from OpenAPI spec#3770
Conversation
When an OpenAPI spec defines server variables (e.g. `https://{region}.api.example.com/v1`),
the default values are now substituted before constructing the httpx client base URL.
Previously, the URL was used as-is, causing all requests to fail for specs that use
server variable templating.
Fixes PrefectHQ#1681
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69624f3b1b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…tution
format_map applies Python string formatting rules, so variable names
like {api.version} would be treated as attribute access and raise errors.
Literal token replacement handles all valid OpenAPI variable names safely.
Test Failure AnalysisSummary: The Windows Python 3.10 CI job failed due to a timeout in an unrelated test ( Root Cause: The test Suggested Solution: This failure is unrelated to this PR's changes (which only touch Detailed AnalysisFailing job: Failing test: Relevant log excerpt: What the test does: Creates a PR changes: Only modify Evidence it's pre-existing: The same Windows runner passed in earlier main-branch runs; there's no code path overlap between this PR and Related Files
|
Ran into this while building a platform that dynamically creates MCP servers from OpenAPI specs. If the spec uses server variables (e.g.
https://{region}.api.example.com/v1), the current_create_default_clientpasses the template string directly to httpx as the base URL, which breaks all requests.The fix substitutes variable defaults before constructing the client, which is what the OpenAPI spec says should happen when no explicit value is provided.
Added tests for single variable, multiple variables, and static URLs (no regression).
Closes #1681