Repository navigation
fix(swift)!: name generated enums and unions after their schema, share AuthActionInput, make models Sendable - #1572
Merged
Merged
Conversation
An enum or union declared at the top level of Models.swift for a component schema's property took the property's name (Capability, Status, Kind) and was prefixed only when another type had it, so it collided with an app's own types. It now always takes its schema's prefix (AuthActionCapability, OrderStatus), as on Dart. A name that already starts with the schema's name is not prefixed again, and a reserved name no longer needs a Value suffix. An array property keeps its own name rather than the element's singular, also as on Dart (AuthenticatedUserGroups, was GroupValue).
|
A union parameter the spec names (x-blocks-type-name) is now declared once at the top level of Models.swift under that name, with its variants nested inside (AuthActionInput.SignIn), and every namespace whose parameter has that shape takes it. Before, each Auth namespace declared its own identical SetAuthState.Input, so one sign-in screen could not serve two Auth blocks. Each operation's enum keeps its old names (Input, SignIn, ...) as deprecated typealiases, so existing code still compiles. A parameter whose name another type has, or whose shape differs, keeps its nested Input.
Generated structs, enums and unions now conform to Sendable when everything they store does, so a Swift 6 actor can keep or return an AuthState or take an AuthActionInput without "sending ... risks causing data races". A type that stores a RealtimeChannel or a declared native binding's type is left without the conformance, as is any type that stores one of those.
The README promised initializer labels in declaration order; they are sorted by name, and stay so for compatibility. The README examples use AuthActionInput. Adds changesets for the naming, shared input and Sendable changes.
ekjotmultani
force-pushed
the
fix/swift-codegen-names
branch
from
November 17, 2026 09:11
871c8ed to
eb16c6d
Compare
ekjotmultani
marked this pull request as ready for review
November 17, 2026 17:01
3 tasks done
A top-level enum or union on a schema's property always takes the schema's prefix (User.userType is UserUserType, Status.status is StatusStatus). A map property keeps its own name, as an array property does (FeatureFlags). An enum or union on a discriminated variant's field is named after the variant and its union (EmailNotificationPayloadPriority). All of these match Dart. A prefixed name that is a Swift, Foundation or runtime type (RPC.error) gets a numeric suffix instead of shadowing it. A top-level union's variant structs now claim their names: an inline type no longer takes one, and a differently shaped variant of another union is renamed after its union (BetaPayloadText), so neither declaration is dropped.
Whether a generated type is Sendable was looked up by bare name across all scopes, and only the first type of a name was examined. One operation's Result over a type that stores a realtime channel could claim Sendable when another operation's Result was Sendable, and any non-Sendable Result dropped the conformance from every other one. Each operation's enum is now a scope of its own: a name it declares resolves there, any other name at the top level, and every same-named type is examined. A generated type named Sendable hid the protocol in its scope, so the conformance is spelled Swift.Sendable when one is declared.
A shared parameter type (x-blocks-type-name) could leave its operation's enum declaring names that don't compile: - A hint that is the parameter's own name (command: Command) declared typealias Command = Command. That parameter now keeps its nested type. - Two parameters of the shared shape declared each alias twice, and a result of that shape declared its variant structs beside the aliases. The old types now stay visible to naming and deduplication, each alias is declared once, and a later parameter or the result names the shared type. - A deeper nested type of the shared name (Place.Result.Figure) took the parameter's type. The operation's root scope now claims the name, and the signature names the shared type. - A hint naming a type the generated files use unqualified (RPCError, BlocksClient, JSONDecoder) shadowed it. It now keeps the nested type. Only a discriminated union is shared: a union without a discriminator names its cases after the union, so its old case names couldn't be kept. Each alias now names the member of the same name, and its deprecation message names the replacement in full: a renamed: fix-it replaced only the last component, giving AuthApi.SetAuthState.AuthActionInput.SignIn.
…e tests The Swift error taxonomy removed RPCError from BlocksRuntime, so it is no longer reserved, and the two tests that used it as the runtime name to avoid failed once main was merged: RPC.error took RPCError, and a hint of RPCError became the shared type. They now use TransportError and ApiError, which the generated files name unqualified.
Below an operation's direct result a declared native binding is generated
as JSONValue, so a type that stores one (Rig { handle, name }) stores only
Sendable values. The analysis no longer drops the conformance for it; only
a stored RealtimeChannel does.
A component schema named JWT was not recognized as itself when its own type was named, so Models.swift declared it twice: JWT and JWTJwt (Jwt before this PR). The schema's own type now keeps the schema's spelled name. The enclosing == nil branch, which no caller reached, is gone.
When two parameters name the same union type (x-blocks-type-name) with different shapes, the first in the spec takes the name and the other kept its nested Input with no word, so adding or reordering methods could move the name silently. The generator now prints a swift: warning for that parameter, and for one whose name another type has, as the Dart generator does.
…names The rename changeset now lists the Cognito renames and says a union without a discriminator renames its cases too (value_Variant0 is filterValue_Variant0), so a switch that never names the type breaks. Two pending changesets said the opposite of this PR: identical top-level enums no longer share one declaration, and initializer labels are sorted by name, not in declaration order. They and native/swift/AGENTS.md now match, AGENTS.md says which models are Sendable, and the README says an open record's attributes: and a hybrid arm's challenge: come last. The init-label-order changeset is dropped: the README sentence it corrected never shipped.
In Swift 5 mode a Sendable conformance a golden can't keep is only an advisory warning, so the check passed a golden that a Swift 6 app could not build. Each golden now compiles in Swift 6 mode, where it is an error. BlocksRuntime and the fixture stubs still build in Swift 5 mode, as in Package.swift. All 43 goldens compile with no warnings.
…'s old union
ai.generate(input: Prompt) returning { input: Message, output: Message }
generated output: Prompt. The output field deduplicated against the
result's own Input, and the shared-type rename rewrote every reference
named Input, since that was also the parameter's old root name, so
decoding a valid result threw keyNotFound at output. The old root entry
now records the shared type, and only a union that deduplicates against
that entry names it; the name-based rename is gone.
thisisabhash
approved these changes
Nov 18, 2026
harsh62
added a commit
that referenced
this pull request
Nov 18, 2026
Brings in #1572 (Swift schema-qualified names, shared AuthActionInput, Sendable models), #1495, #1608 and #1579. - README.md: keep both sides. Main's note on AuthActionInput goes before this branch's Blocks() paragraph (cookie session, tokenStore only for bearer tokens), and main's sorted-label initializers bullet sits beside this branch's read-only transferables bullet. - TransferableUnionArmTests.swift merged cleanly: #1572's Sendable assertion and this branch's read-only encode expectation are separate hunks, and the test passes with #1572's codegen.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Swift codegen names a schema enum or union after the property that uses it, not after the schema. So an app gets generic top-level types such as
Capability,StatusorDeliveryMedium, which collide with the app's own types, and the same schema can get different names in different places. Each Auth namespace also gets its own nestedSetAuthState.Input, so code written against one Auth block doesn't work with another. Generated value types aren'tSendable, which Swift 6 strict concurrency needs.These are public type names, so they have to settle before the Swift SDK's GA release.
Changes
AuthenticatedUser.groupsis[AuthenticatedUserGroups]), matching the Dart SDK. Nested structs still singularize, as before. Union variant structs stay at the top level. A schema whose name isn't PascalCase (JWT) is declared once, under its spelled name.AuthActionInput. All Auth namespaces share one top-levelAuthActionInput, with nested deprecated aliases where the old nested names existed. When a named union parameter keeps its nested type instead (another shape took the name first, or another type has it), codegen prints aswift:warning naming the parameter and the reason.Sendable. Generated value types conform toSendable. Only a type that stores aRealtimeChanneldrops it; a type that stores a declared binding's tag staysSendable.Sendableis a compile error.attributes:and a hybrid arm'schallenge:come last. The quick start compiles against today's spec and against one that names the type. The pending changesets andnative/swift/AGENTS.mdmatch the new names.Breaking
Generated type names change for apps on Swift 0.1.1. No aliases are declared for the old names. The changesets list the renames, including the Cognito ones (
SignInProvider,DeliveryMediumandGroupValuebecomeAuthenticatedUser…,CodeDeliveryDetails…and so on). A union without a discriminator renames its cases with it (.value_Variant0becomes.filterValue_Variant0), so aswitchover one breaks too.Validation
swift test --disable-sandbox: 669 tests pass (405 codegen, 246 runtime, 18 generated-code). The iOS simulator run of the codegen and runtime tests passes.compile-fixture-goldens.sh: all 43 goldens compile in Swift 6 mode with no warnings; its.test.shpasses.regenerate-all.sh(Kotlin, Swift, Dart): no drift.check-live-auth-fixtures.mjs --generate: fixtures 18, 23 and 37 match the live spec, and the Swift client generated from it compiles in Swift 6.codegen-config.test.sh,scripts/sink-guards(35/35), SwiftLint and SwiftFormat lint, and the changeset checks.Merge notes
RPCErrortoTransportErrorandApiError.env), so "Local Build and Checks" passes before ci(kotlin): pass the emulator script path through env #1603 merges.generator.sendable = …andrejectTransferableParameters(model)inSwiftCodeGenerator.swift, and re-pinsscripts/sink-guards/codegen.test.mjs.x-blocks-type-namehint. Until it lands, no spec carries the hint and Swift keeps the per-namespace input types. After it merges, regenerate the Swift goldens for fixtures 18, 23 and 44; 18 and 44 then get the sharedAuthActionInput.Sendableand the schema-qualified names.native/swift/README.md; keep both sides' text.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.