fix(swift): support multi-URL environments in client initialization#16664
fix(swift): support multi-URL environments in client initialization#16664devin-ai-integration[bot] wants to merge 2 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| @@ -130,6 +130,5 @@ fixtures: | |||
| allowedFailures: | |||
| - multi-url-environment | |||
There was a problem hiding this comment.
🚩 multi-url-environment and multi-url-environment-no-default remain in allowedFailures
This PR removes multi-url-environment-reference from allowedFailures but leaves multi-url-environment and multi-url-environment-no-default in the list, even though the PR generates proper multi-URL environment structs and client code for those fixtures as well (visible in the seed output diffs). This might be intentional if those fixtures fail for reasons unrelated to environment generation (e.g., other unsupported features), but it's worth confirming whether they can now also be removed from allowedFailures.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Good catch — I verified both locally with the full seed test (compile + wire tests):
multi-url-environment-no-default→ still fails to build. With no default environment there's no value to seed the convenience initializer'senvironment:default with, so it doesn't yet compile. It legitimately needs more work and stays inallowedFailures.multi-url-environment→ now passes with this change (it just emits the non-fatal⚠ test cases succeeded unexpectedlywarning while it remains in the list).
This PR is intentionally scoped to only multi-url-environment-reference per the task; multi-url-environment / multi-url-environment-no-default are owned by separate PRs, so I left both entries intact here rather than removing multi-url-environment out of scope.
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 |
Description
The Swift SDK generator did not handle APIs whose environments expose multiple base URLs per server group (IR environment type
multipleBaseUrls). For those APIs the generator emitted a singlebaseURL: Stringclient initializer and routed every request throughclientConfig.baseURL, so there was no way to target the correct server per endpoint. This is why themulti-url-environment-referencefixture was listed underallowedFailuresinseed/swift-sdk/seed.yml.This PR adds general multi-URL environment support so the fixture compiles and passes seed tests, and removes it from
allowedFailures.Changes Made
MultiUrlEnvironmentGeneratorwhich emits an environment struct holding one URL field per server group and astatic letfor each declared environment, e.g.:SdkGeneratorCli.generateSourceEnvironmentFilenow switches on the environment IR type, using the existing single-URL enum generator forsingleBaseUrland the new struct generator formultipleBaseUrls.RootClientGeneratornow generates anenvironment:parameter (instead ofbaseURL:) for multi-URL APIs and flattens it into the client config as abaseURLsdictionary keyed by server id.EndpointMethodGeneratorthreads the endpoint'sbaseUrlid intoperformRequest(..., baseUrlId:)so each call resolves the right server.ClientConfig,HTTPClient) gained a backwards-compatible optionalbaseURLsmap andbaseUrlIdparameter;HTTPClient.resolveBaseURL(baseUrlId:)returns the per-server URL when present and otherwise falls back tobaseURL. The new parameters default tonil, so single-URL SDKs are unaffected.seed/swift-sdksnapshots (the template additions touch every fixture'sClientConfig/HTTPClient; multi-URL fixtures also get an environment struct).multi-url-environment-referencefromallowedFailuresinseed/swift-sdk/seed.yml.generators/swift/sdk/changes/unreleased/.Testing
seed test --generator swift-sdk --fixture multi-url-environment-reference→ 1/1 passed (compiles + wire tests).allowedFailures(websocket-multi-url) and a single-URL fixture (imdb) — both build and pass.pnpm run check(biome) clean;@fern-api/swift-sdktypechecks.Link to Devin session: https://app.devin.ai/sessions/89ba0b887e2a43e4ba37cf802d84981f
Requested by: @iamnamananand996