Skip to content

fix(swift)!: name generated enums and unions after their schema, share AuthActionInput, make models Sendable - #1572

Merged
ekjotmultani merged 23 commits into
mainfrom
fix/swift-codegen-names
Nov 18, 2026
Merged

ekjotmultani merged 23 commits into
mainfrom
fix/swift-codegen-names

Conversation

@ekjotmultani

@ekjotmultani ekjotmultani commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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, Status or DeliveryMedium, 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 nested SetAuthState.Input, so code written against one Auth block doesn't work with another. Generated value types aren't Sendable, which Swift 6 strict concurrency needs.

These are public type names, so they have to settle before the Swift SDK's GA release.

Changes

  • Schema-qualified names. Enums and unions are named after their schema. An array property's enum or union keeps the property's name (AuthenticatedUser.groups is [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.
  • One AuthActionInput. All Auth namespaces share one top-level AuthActionInput, 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 a swift: warning naming the parameter and the reason.
  • Sendable. Generated value types conform to Sendable. Only a type that stores a RealtimeChannel drops it; a type that stores a declared binding's tag stays Sendable.
  • Swift 6 goldens. The fixture goldens compile in Swift 6 language mode, so a wrong Sendable is a compile error.
  • Docs. The README says initializer labels are sorted, and that an open record's attributes: and a hybrid arm's challenge: come last. The quick start compiles against today's spec and against one that names the type. The pending changesets and native/swift/AGENTS.md match 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, DeliveryMedium and GroupValue become AuthenticatedUser…, CodeDeliveryDetails… and so on). A union without a discriminator renames its cases with it (.value_Variant0 becomes .filterValue_Variant0), so a switch over 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.sh passes.
  • 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

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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).
@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 57f881b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.
Comment thread native/swift/README.md Resolved
Comment thread native/swift/README.md Resolved
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.
@ekjotmultani ekjotmultani reopened this Nov 18, 2026
@ekjotmultani ekjotmultani reopened this Nov 18, 2026
@ekjotmultani
ekjotmultani merged commit 00a649b into main Nov 18, 2026
68 checks passed
@ekjotmultani
ekjotmultani deleted the fix/swift-codegen-names branch November 18, 2026 05:52
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

1 inactive deployment
e2e — 57f881b8 Deployed Nov 18, 2026 by harsh62 via Swift E2E (sandbox) #7025
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.

3 participants