Skip to content

feat(sdk-generator): Swift SDK + contract-test backends - #55

Merged
calvin-archastro merged 1 commit into
mainfrom
features/calvin-archastro-21-07-2026-swift-sdk
Jul 21, 2026
Merged

feat(sdk-generator): Swift SDK + contract-test backends#55
calvin-archastro merged 1 commit into
mainfrom
features/calvin-archastro-21-07-2026-swift-sdk

Conversation

@calvin-archastro

Copy link
Copy Markdown
Contributor

Summary

Adds two new generator targets:

--lang Emits
swift Idiomatic async Swift SDK: Codable models, resource classes, Phoenix channel classes, AuthClient, PlatformClient
contract-tests-swift swift-testing contract suites driving the same Prism mock + channel-harness service as the TS/Python tests

The consuming package lives in the new (private) ArchAstro/archastro-swift repo, which mirrors archastro-python's split: generated code + a hand-maintained runtime (HttpClient with one-shot deduplicated 401 refresh, JSONValue, Phoenix v2 Socket/Channel over URLSessionWebSocketTask).

Design notes

  • Single-module namespace: Swift compiles the whole SDK into one module, so every generated type name (schemas, inline inputs/responses, channel payloads) goes through a global SwiftNameRegistry claimed in canonical order. This resolves real collisions (the spec's AuthTokens schema vs. the generated auth-tokens struct) and keeps the separate swift and contract-tests-swift generator runs name-compatible and byte-reproducible.
  • Shared classification: the Swift response-shape classifier re-exports the Python one, so generated assertions can never drift from emitted deserialization behavior.
  • Contract parity: same test matrix as Python minus the sync duplicates (Swift is async-only, like TS) — per-op success + per-documented-error tests against Prism, join/message/push/leave channel tests with wire-level observation assertions, SSE stream tests (ordered events + non-2xx → ApiError).
  • value-generator/method-chain-builder lang unions widened to "swift"; TS/Python output is unchanged (all 313 unit tests + 63 channel-harness integration tests pass).

Verification

Against specs/platform-openapi.json in archastro-swift:

  • swift test with channel tests enabled: 946 tests in 44 suites, all passing (37 REST suites vs Prism, 3 channel suites + 1 SSE stream suite vs the real channel-harness subprocess, 16 runtime unit tests)
  • Regeneration verified deterministic (identical checksums across runs)
  • npm run lint, npx tsc, npm test (313 tests) clean

Follow-up

  • Publishing this as @archastro/sdk-generator@0.8.0 unlocks registry-based regeneration in archastro-swift (its regen script currently supports ARCHASTRO_SDK_GENERATOR_BIN for local use).

🤖 Generated with Claude Code

New --lang swift and --lang contract-tests-swift targets emitting an
idiomatic async Swift SDK (Codable models, resource classes, channels,
auth, PlatformClient) plus swift-testing contract suites that drive the
same Prism mock and channel-harness service as the TS/Python tests.

- backends/swift/: model/resource/namespace/auth/client/channel emitters
  with a global type-name registry (Swift compiles the SDK as a single
  module, so schema/input/response/channel type names share a namespace;
  claiming in canonical order keeps the SDK and contract-test generator
  runs byte-reproducible)
- contract-tests/: swift-emitter + channel-emitter-swift + swift-values
  (typed struct initializers with hoisted-name derivation)
- value-generator/method-chain-builder: lang unions widened to "swift"
- response-shape classification shared with the Python backend so Swift
  assertions can never drift from emitted deserialization behavior

Verified against specs/platform-openapi.json in the archastro-swift
package: 946 tests in 44 suites pass (REST vs Prism, 3 channel suites +
SSE stream suite vs channel-harness), generation is deterministic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@calvin-archastro
calvin-archastro merged commit 548089e into main Jul 21, 2026
2 checks passed
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.

1 participant