fix(swift): align snippet initializer with generated wrapper struct#15389
Conversation
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 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:
|
There was a problem hiding this comment.
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.
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
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 aninit(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 ofrequest: .init(body: CreateUsernameBody(...))). Adding an unnecessary wrapper struct would add complexity without benefit.Changes Made
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 therequest:parameter instead of wrapping it in.init(body:).request-parameters,exhaustive,bytes-upload,trace,path-parameters,nullable-request-body,schemaless-request-body-examples) to reflect the corrected snippets.generators/swift/sdk/changes/unreleased/fix-snippet-referenced-body.yml.The existing
request-parametersseed fixture already exercises the exact scenario (endpointcreateUsernameWithReferencedTypewith a$refbody + query params).Testing
tsc)literalfixture)pnpm lint:biome,pnpm format,pnpm checkall passLink to Devin session: https://app.devin.ai/sessions/7ed05d4d38b74b6e811599106d1f344d