Skip to content

fix(swift): generate valid inline union contract values - #109

Merged
calvin-archastro merged 1 commit into
mainfrom
fix/swift-inline-union-contract-values
Sep 24, 2026
Merged

calvin-archastro merged 1 commit into
mainfrom
fix/swift-inline-union-contract-values

Conversation

@calvin-archastro

@calvin-archastro calvin-archastro commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review on ArchCode

Problem

Regenerate SDK in archastro-swift (#6) fails Build + Test (macOS) → REST contract tests: 17 failures, all HTTP 422 from Prism.

spec: ExternalObjectCreateInput.object = oneOf by `type` (r2_bucket requires type + name)
generator: swiftTypedValue(union) → "[:]"
test:     externalObjects.create(input: .init(object: [:], service: "cloudflare"))
Prism:    request fails schema validation → 422
test:     expects 2xx / 401 / 403 / … → fails

Affected: ExternalObjectsContractTests create/update (12) and AiContractTests ai_evaluation_evaluations (5, questions: [[:]]). These tests are new with this spec refresh; Swift main last regenerated in August.

Go hit the same bug and was fixed in dc7b4b3; Swift never got the matching change.

What changed

  • swift-values.ts: case "union" → generateDummyValue(typeRef, fieldName, "swift"), which fills in the first variant's required fields. Same as Go's go-values.ts. unknown still renders [:].
  • Safe to compile: Swift maps every inline union to JSONValue, which accepts dictionary, array, string, number, and boolean literals.

Before → after (generated Swift test):

object: [:]                                   → object: ["name": "test-name", "type": "r2_bucket"]
questions: [[:]]                              → questions: [["id": "test-id", "instructions": "test-value", "type": "boolean"]]

Scope / risk

Generator only (Swift contract-test fixtures). No SDK runtime or model output changes. Low risk.

Testing

  • New swift.test.ts › populates inline union JSONValue inputs with a valid variant: failed before the fix (Received: "[:]"), passes after.
  • npm test (sdk-generator): 425/425. tsc --noEmit and npm run lint clean.
  • End-to-end: built this generator, ran ARCHASTRO_SDK_GENERATOR_BIN=… ./scripts/regenerate_sdk.sh --local <this checkout> in archastro-swift on the auto/regenerate-sdk head, then ran the CI steps locally on macOS:
    • prism mock specs/platform-openapi.json + swift test --skip-build --filter 'ArchAstroPlatformContractTests[.]' → 1559 tests in 64 suites passed (previously 17 failures).
    • ARCHASTRO_RUN_CHANNEL_CONTRACT_TESTS=1 swift test --filter 'ChannelContractTests|StreamContractTests|HarnessLifecycle' → 81 tests in 9 suites passed. ApiChatChannelContractTests output also changes with this fix and passes.
  • Automatic coverage: this repo's CI runs the new vitest case on every PR. archastro-swift CI (Build + Test (macOS)) runs the generated contract tests on each regen PR.

Follow-up

Release sdk-generator v0.11.10 (Release workflow, patch), then rerun Regenerate SDK in archastro-swift.

🤖 Generated with Claude Code

swiftTypedValue rendered every inline union as `[:]`. Inline unions are
JSONValue in the Swift SDK, so the empty dictionary compiled, but Prism
rejects it whenever the variants require fields. After the spec added
ExternalObjectCreateInput.object / ExternalObjectUpdateInput.object
(discriminated on `type`) and EvaluationEvaluationsInput.questions, 17
REST contract tests in archastro-swift got HTTP 422 instead of the
documented status.

Populate the first variant's required fields via generateDummyValue, as
dc7b4b3 did for Go.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@calvin-archastro
calvin-archastro merged commit 0c1ad55 into main Sep 24, 2026
3 checks passed
@calvin-archastro
calvin-archastro deleted the fix/swift-inline-union-contract-values branch September 24, 2026 15:02
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