fix(swift): build wire-test JSON body from typed example shape#15687
fix(swift): build wire-test JSON body from typed example shape#15687devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
When a Swift wire-test response body contains a Dictionary<String, T> whose value is an explicit-null nullable<T>, the generator was silently dropping those entries from the embedded JSON body via JSON.stringify of the IR's jsonExample (which leaves them as JS undefined). The expected struct built from the typed example shape retained them as Nullable<T>.null, so the decoded body and the expected struct disagreed at runtime equality. Build the JSON body by walking the typed ExampleTypeReference shape directly so it stays in sync with the expected struct by construction. Closes FER-10341 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-10341
Fixes 7 Swift wire-test runtime equality failures observed in the latest nightly Square baseline-e2e run —
OrdersClient.{updateOrder2,payOrder2,calculateOrder2,cloneOrder2,retrieveOrder2,createOrder2}andCheckoutClient.createPaymentLink2.Root cause
When a wire-test response body contains a
Dictionary<String, T>whose value is an explicit-nullNullable<T>, the typed example shape stored onExampleTypeReferenceretains the entry (mapContainer.maphas a key whose value is aContainer.nullablewithnullable: undefined), but the IR's paralleljsonExampleprojection ends up with the value as JSundefined.JSON.stringifythen silently drops the key from the embedded JSON body. The expected response struct, however, is built by walking the typed shape (Nullable<T>.nullis preserved), soJSONDecoder.decode(...)produces[:]while the expected struct contains["metadata": .null], and the runtime equality assertion fails:Fix
Build the wire-test JSON body by walking the typed
ExampleTypeReferenceshape directly, the same source the expected struct is built from. This keeps the two sides in sync by construction. Discriminated and undiscriminated unions (whose wire format requires type-declaration metadata not present on the example shape) fall back to the IR-suppliedjsonExample, since the map-with-null-entries asymmetry does not apply within union examples.Changes Made
buildJsonFromExampleTypeReference(ingenerators/swift/sdk/src/generators/test/) walksExampleTypeReference.shapeand produces a JSON-encodable JS value mirroring the wire format. Maps with explicit-null entries surface asnull(notundefined) so they surviveJSON.stringify.WireTestFunctionGeneratornow routes the embedded response body through this helper instead ofJSON.stringify(exampleTypeRef.jsonExample, null, 2). Existing raw-string fast path (used for the iCalendar fixture from fix(swift): emit wire-test response bodies as raw multi-line string literals #15605) is preserved.Testing
buildJsonFromExampleTypeReference.test.tscovering primitives, populated and unset nullables, optionals, lists withnullable<T>items, the regression case ofmap<string, nullable<string>>with an explicit-null entry, and a nested-object containing such a map.Local seed verification was not feasible because
pnpm seed:buildis currently broken onmaindue to an unrelated@fern-api/registerTypeScript compile error against the pinned@fern-api/fdr-sdk(Availabilityenum missingLegacy/Alpha/Previewvariants).Link to Devin session: https://app.devin.ai/sessions/9531f957724c47d389f7043dd1ec80cc