Skip to content

Generate Go bool discriminated unions#1284

Merged
stephentoub merged 1 commit into
github:mainfrom
qmuntal:fix/1264-go-boolean-discriminators
May 14, 2026
Merged

Generate Go bool discriminated unions#1284
stephentoub merged 1 commit into
github:mainfrom
qmuntal:fix/1264-go-boolean-discriminators

Conversation

@qmuntal
Copy link
Copy Markdown
Contributor

@qmuntal qmuntal commented May 13, 2026

Summary

  • teach the Go generator to recognize boolean const/enum discriminator values
  • generate QueuedCommandResult as a boolean-discriminated interface instead of a flattened struct
  • regenerate RPC encoding so handled is preserved when marshaling and unmarshaling queued command results

Fixes #1264

Testing

  • npm run generate:go
  • go test ./rpc
  • go test .

@qmuntal qmuntal requested a review from a team as a code owner May 13, 2026 11:54
Copilot AI review requested due to automatic review settings May 13, 2026 11:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Go code generator to support boolean-valued discriminators in JSON-schema anyOf discriminated unions, and regenerates Go RPC types/encoding so QueuedCommandResult is modeled as a boolean-discriminated interface (preserving the handled discriminator across marshal/unmarshal).

Changes:

  • Extend Go codegen discriminator detection to accept const/enum booleans (in addition to strings), including correct variant naming and switch emission.
  • Regenerate Go RPC types so QueuedCommandResult becomes an interface with Handled() bool, with concrete handled/not-handled variants plus a raw fallback.
  • Regenerate Go RPC JSON encoding to unmarshal/marshal QueuedCommandResult while preserving the discriminator (handled) correctly.
Show a summary per file
File Description
scripts/codegen/go.ts Adds boolean discriminator support for discriminated unions and improves boolean schema merging for flattened object unions.
go/rpc/zrpc.go Regenerates QueuedCommandResult as a boolean-discriminated interface with handled/not-handled variants.
go/rpc/zrpc_encoding.go Adds generated marshal/unmarshal support for the new QueuedCommandResult union and updates request decoding accordingly.

Copilot's findings

Files not reviewed (2)
  • go/rpc/zrpc.go: Language not supported
  • go/rpc/zrpc_encoding.go: Language not supported
  • Files reviewed: 1/3 changed files
  • Comments generated: 0

@qmuntal qmuntal force-pushed the fix/1264-go-boolean-discriminators branch 2 times, most recently from 8e2bcb2 to 9889a0d Compare May 13, 2026 12:10
@qmuntal qmuntal requested a review from Copilot May 13, 2026 12:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

Files not reviewed (2)
  • go/rpc/zrpc.go: Language not supported
  • go/rpc/zrpc_encoding.go: Language not supported
  • Files reviewed: 1/3 changed files
  • Comments generated: 3

Comment thread scripts/codegen/go.ts
Comment thread go/rpc/zrpc_encoding.go
Comment thread scripts/codegen/go.ts Outdated
@qmuntal qmuntal force-pushed the fix/1264-go-boolean-discriminators branch from 9889a0d to cb0db3a Compare May 13, 2026 18:33
@stephentoub stephentoub force-pushed the fix/1264-go-boolean-discriminators branch from cb0db3a to e125082 Compare May 14, 2026 01:46
@stephentoub
Copy link
Copy Markdown
Collaborator

Thanks!

@stephentoub stephentoub added this pull request to the merge queue May 14, 2026
Merged via the queue into github:main with commit 87c315c May 14, 2026
20 of 21 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.

Revisit string enums for Booleans in generated Go code

3 participants