feat(python): add serverUrlVariables config flag to Python SDK generator#17119
feat(python): add serverUrlVariables config flag to Python SDK generator#17119willkendall01 wants to merge 2 commits into
Conversation
Add a `serverUrlVariables` custom config flag (boolean, defaults to true) to the Python v1 SDK generator. When true (default), behavior is unchanged: the generated client exposes server-URL-variable constructor kwargs and performs runtime URL-template interpolation. When false, the generator falls back to the pre-feature base-URL behavior, emitting neither the kwargs nor the interpolation. Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
AI Review Summary
Adds a serverUrlVariables config flag to gate server-URL-variable generation. The gate implementation and config parsing look correct and mirror existing patterns. Main concern is the stub-based test being brittle and not exercising the enabled path through the real environments-config code.
- 🔵 1 suggestion(s)
| def test_get_server_variables_default_surfaces_variables() -> None: | ||
| """With server_url_variables enabled (default), server variables are surfaced.""" | ||
| stub = _make_server_variables_generator_stub(server_url_variables=True) | ||
| variables = RootClientGenerator._get_server_variables(stub) # type: ignore[arg-type] | ||
| assert [var.id for var in variables] == ["region"] |
There was a problem hiding this comment.
🔵 suggestion
This test only validates that a SimpleNamespace stub with hand-rolled get_as_union returns the variable — it duplicates the internal shape of _get_server_variables rather than testing it against real IR types. If the method's parsing of environments_config changes, this test won't catch it because it mirrors the implementation. Consider using a real ir_types fixture, or at minimum note that this test is tightly coupled to the current internals.
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Add a `disable-server-url-variables` seed fixture output (customConfig `serverUrlVariables: false`) for both the `server-url-templating` and `server-url-templating-single-url` fixtures, alongside the existing default output. The default output keeps the server-URL-variable constructor kwargs and runtime URL-template interpolation; the disabled output omits both, exercising the pre-feature base-URL fallback. Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Adds a new
serverUrlVariablescustom config flag (boolean, defaults totrue) to the Python v1 SDK generator (generators/python).true(default): behavior is unchanged. The generated client exposes server-URL-variable constructor kwargs (e.g.region: typing.Optional[str]) and performs runtime URL-template interpolation.false: the generator falls back to the pre-feature base-URL behavior, emitting neither the server-URL-variable constructor kwargs nor the URL-template interpolation.Details
server_url_variables: bool = TrueonSDKCustomConfig, mapped from the camelCase JSON keyserverUrlVariablesinparse_obj(mirroring the existing optional flags). Snake_case is also accepted directly.RootClientGenerator._get_server_variables, which returns an empty list when the flag is disabled. Both the constructor-parameter loop and_write_url_template_interpolationkey off this list, so suppressing it disables both behaviors.5.21.0entry (minor bump) at the top ofgenerators/python/sdk/versions.yml.Verification
python -m py_compileon all changed modules and test files: passed.poetry install+pytestwas not run in this environment (poetry unavailable; install too heavy to complete within time limits).Generated with Claude Code