Skip to content

Support alloy open + discriminated unions (un-exclude conformance cases) - #35

Merged
aaylward merged 1 commit into
mainfrom
claude/issue-27-fix-42z1s0
Jul 7, 2026
Merged

aaylward merged 1 commit into
mainfrom
claude/issue-27-fix-42z1s0

Conversation

@aaylward

@aaylward aaylward commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

What

Implements alloy's @discriminated and @jsonUnknown (open union) wire encodings in the union serde, closing #27.

  • SerdeGenerator.writeUnion now branches on the alloy traits:
    • @discriminated("key") unions serialize the engaged member's fields inline with the discriminator spliced into the same object ({"key": "smol", "content": "..."}), not a single-key tagged wrapper; deserialization switches on the discriminator value and parses the same object as the member's structure.
    • A @jsonUnknown member retains the entire wire object when the tag (tagged unions) or discriminator value (discriminated unions) matches no known member, in both directions.
  • Closed unions are untouched — plain tagged serde output is byte-for-byte identical (the examples/ goldens regenerate with no diff), including the strict exactly-one-member guard the malformed-request suite pins.
  • The three alloy.test#PizzaAdminService cases are removed from protocol-test-exclusions.txt (the list only shrank): OpenUnionsUnknownTaggedUnionCase, OpenUnionsKnownDiscriminatedUnionCase, OpenUnionsUnknownDiscriminatedUnionCase.
  • The regenerated protocol-tests/simplerestjson/generated output is committed: new serde for OpenTaggedUnion/OpenDiscriminatedUnion and 12 new conformance tests (the 3 cases × client request/response + server request/response), plus a smoke round-trip.
  • Documented the wire behavior in docs/generated-types.md (Serde section).

Testing

  • bazel test //protocol-tests/simplerestjson/generated/tests:all — 5/5 targets green; all four OpenUnions* cases now execute in each of the four suites (verified in the gtest XML).
  • bazel test //... (excluding //benchmarks/... and the Beast targets, which cannot fetch Boost/BoringSSL behind this environment's proxy — the exclusion documented in docs/development.md) — 63/63 tests pass.
  • (cd codegen && gradle build spotlessCheck) — green.
  • gradle generateFixtures generateProtocolTests — regenerated output committed; only protocol-tests/simplerestjson changed, examples/ goldens byte-identical.

Checklist

  • Tests added/updated for the change (12 un-excluded conformance tests + smoke round-trip)
  • bazel test //... and (cd codegen && gradle build spotlessCheck) pass locally (Beast/benchmark targets excluded per docs — proxy blocks their archive fetches)
  • Formatting clean (spotless; generated code is exempt from clang-format, no hand-written C++/Starlark touched)
  • Architectural decisions recorded as an ADR (not applicable — protocol serde detail, no architectural change)

🤖 Generated with Claude Code

https://claude.ai/code/session_01SyQAo21Pv6GYhHrkbQj8xQ


Generated by Claude Code

Implement alloy's @Discriminated and @jsonUnknown (open union) wire
encodings in SerdeGenerator.writeUnion:

- @Discriminated("key") unions serialize the engaged member's fields
  inline with the discriminator spliced into the same object
  ({"key": "smol", ...fields}) instead of a single-key tagged wrapper,
  and deserialize by switching on the discriminator value.
- A @jsonUnknown member retains the entire wire object when the tag or
  discriminator value matches no known member, for both tagged and
  discriminated unions; closed unions keep the strict exactly-one-member
  behavior byte-for-byte.

Un-exclude the three PizzaAdminService conformance cases
(OpenUnionsUnknownTaggedUnionCase, OpenUnionsKnownDiscriminatedUnionCase,
OpenUnionsUnknownDiscriminatedUnionCase) and regenerate the
simplerestjson suite: 12 new conformance tests (client+server,
request+response) plus a smoke round-trip, all green.

Closes #27

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyQAo21Pv6GYhHrkbQj8xQ
@aaylward
aaylward merged commit 13feab7 into main Jul 7, 2026
12 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.

2 participants