Skip to content

fix(swift): align snippet initializer with generated wrapper struct#15389

Merged
fern-support merged 1 commit into
mainfrom
devin/1777131614-fix-swift-snippet-referenced-body
Apr 28, 2026
Merged

fix(swift): align snippet initializer with generated wrapper struct#15389
fern-support merged 1 commit into
mainfrom
devin/1777131614-fix-swift-snippet-referenced-body

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Description

Linear ticket: Closes FER-10087

The Swift dynamic-snippet generator emitted .init(body: <SomeRequest>(...)) on the generated request wrapper struct, but the Swift SDK only accepts the referenced type directly as a method parameter — no wrapper struct with an init(body:) is generated. This caused compiled snippet failures for any spec with a body that $refs a top-level schema.

Design choice: Option (b) from the ticket — changed the snippet generator to construct the inner request directly and pass it to the method. This is more idiomatic Swift because the SDK already accepts the referenced type directly (e.g. request: CreateUsernameBody(...) instead of request: .init(body: CreateUsernameBody(...))). Adding an unnecessary wrapper struct would add complexity without benefit.

Changes Made

  • Modified generators/swift/dynamic-snippets/src/EndpointSnippetGenerator.ts: When an inlined request body is of type "referenced", the snippet now passes the type literal directly to the request: parameter instead of wrapping it in .init(body:).
  • Updated seed fixture outputs across 8 affected fixtures (request-parameters, exhaustive, bytes-upload, trace, path-parameters, nullable-request-body, schemaless-request-body-examples) to reflect the corrected snippets.
  • Added changelog entry at generators/swift/sdk/changes/unreleased/fix-snippet-referenced-body.yml.

The existing request-parameters seed fixture already exercises the exact scenario (endpoint createUsernameWithReferencedType with a $ref body + query params).

Testing

  • TypeScript compilation passes (tsc)
  • Swift dynamic snippet unit tests pass (32/32)
  • Full swift-sdk seed test suite passes (126/127 — 1 expected failure on literal fixture)
  • No regressions in any existing Swift seed snapshot
  • pnpm lint:biome, pnpm format, pnpm check all pass

Link to Devin session: https://app.devin.ai/sessions/7ed05d4d38b74b6e811599106d1f344d

When an endpoint body $refs a top-level schema, the Swift SDK accepts
the referenced type directly as a method parameter—no wrapper struct is
generated. The dynamic snippet generator was emitting .init(body: ...)
on the nonexistent wrapper, causing compile failures.

Now, for referenced body types inside inlined requests, the snippet
passes the type literal directly (e.g. CreateUsernameBody(...)) instead
of .init(body: CreateUsernameBody(...)).

Fixes FER-10087

Co-Authored-By: barry.zou <barry.zou@buildwithfern.com>
@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 and CI monitoring

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@devin-ai-integration devin-ai-integration Bot changed the title fix(swift-sdk): align snippet initializer with generated wrapper struct fix(swift): align snippet initializer with generated wrapper struct Apr 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-04-23T04:59:11Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
swift-sdk square 41s (n=5) 290s (n=5) 42s +1s (+2.4%)

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-04-23T04:59:11Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-04-25 15:58 UTC

@fern-support fern-support merged commit b66168c into main Apr 28, 2026
78 of 80 checks passed
@fern-support fern-support deleted the devin/1777131614-fix-swift-snippet-referenced-body branch April 28, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants