Skip to content

fix(swift): support multi-URL environments in client initialization#16664

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1782191377-swift-multi-url-environment-reference
Open

fix(swift): support multi-URL environments in client initialization#16664
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1782191377-swift-multi-url-environment-reference

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

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 single baseURL: String client initializer and routed every request through clientConfig.baseURL, so there was no way to target the correct server per endpoint. This is why the multi-url-environment-reference fixture was listed under allowedFailures in seed/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

  • Added MultiUrlEnvironmentGenerator which emits an environment struct holding one URL field per server group and a static let for each declared environment, e.g.:
    public struct ApiEnvironment: Sendable {
        public let base: String
        public let auth: String
        public let upload: String
        public static let production: ApiEnvironment = ApiEnvironment(
            base: "https://api.example.com/2.0",
            auth: "https://auth.example.com/oauth2",
            upload: "https://upload.example.com/2.0"
        )
        // ...
    }
  • SdkGeneratorCli.generateSourceEnvironmentFile now switches on the environment IR type, using the existing single-URL enum generator for singleBaseUrl and the new struct generator for multipleBaseUrls.
  • RootClientGenerator now generates an environment: parameter (instead of baseURL:) for multi-URL APIs and flattens it into the client config as a baseURLs dictionary keyed by server id.
  • EndpointMethodGenerator threads the endpoint's baseUrl id into performRequest(..., baseUrlId:) so each call resolves the right server.
  • Client templates (ClientConfig, HTTPClient) gained a backwards-compatible optional baseURLs map and baseUrlId parameter; HTTPClient.resolveBaseURL(baseUrlId:) returns the per-server URL when present and otherwise falls back to baseURL. The new parameters default to nil, so single-URL SDKs are unaffected.
  • Regenerated seed/swift-sdk snapshots (the template additions touch every fixture's ClientConfig/HTTPClient; multi-URL fixtures also get an environment struct).
  • Removed multi-url-environment-reference from allowedFailures in seed/swift-sdk/seed.yml.
  • Added a changelog entry under generators/swift/sdk/changes/unreleased/.

Testing

  • seed test --generator swift-sdk --fixture multi-url-environment-reference → 1/1 passed (compiles + wire tests).
  • Verified no regression on a multi-URL fixture not in allowedFailures (websocket-multi-url) and a single-URL fixture (imdb) — both build and pass.
  • pnpm run check (biome) clean; @fern-api/swift-sdk typechecks.

Link to Devin session: https://app.devin.ai/sessions/89ba0b887e2a43e4ba37cf802d84981f
Requested by: @iamnamananand996


Open in Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Comment thread seed/swift-sdk/seed.yml
@@ -130,6 +130,5 @@ fixtures:
allowedFailures:
- multi-url-environment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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's environment: default with, so it doesn't yet compile. It legitimately needs more work and stays in allowedFailures.
  • multi-url-environment → now passes with this change (it just emits the non-fatal ⚠ test cases succeeded unexpectedly warning 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.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-06-22T05:47:30Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
swift-sdk square 58s (n=5) 435s (n=5) 49s -9s (-15.5%)

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 fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-06-22T05:47:30Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-06-23 05:34 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant