msggen: Add UnionField support to all generators for oneOf schemas#8965
Open
4xvgal wants to merge 3 commits intoElementsProject:masterfrom
Open
msggen: Add UnionField support to all generators for oneOf schemas#89654xvgal wants to merge 3 commits intoElementsProject:masterfrom
4xvgal wants to merge 3 commits intoElementsProject:masterfrom
Conversation
The convert generator was capitalizing the union variant suffix (e.g. ArrString) when constructing wrapper type names, while the proto generator used the raw suffix (arr_string). This caused prost-generated struct names to mismatch (DatastoreRequestarrStringWrapper vs DatastoreRequestArrStringWrapper). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cdecker
requested changes
Mar 22, 2026
| optional uint64 generation = 2; | ||
| optional bytes hex = 3; | ||
| optional string string = 4; | ||
| repeated string key = 5; |
Member
There was a problem hiding this comment.
This is a backwards incompatible change. Never change the field numbering in protobuf.
Author
There was a problem hiding this comment.
Fixed - the first variant of each oneof now reuses the original field number.
new numbers are only allocated for additional variants.
Reuse the original field number for the first variant of each oneOf, instead of allocating new numbers for all variants. This maintains backward compatibility with existing gRPC clients. For example, Invoice.label was previously field 3 (string). Now the oneof reuses 3 for label_string and only allocates a new number for label_int. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
msggencould not handleoneOffields in JSON schemas. EveryoneOffield was manually overridden to a single type, which dropped some variants. This PR addsUnionFieldsupport to all generators so that every variant in aoneOfschema is preserved without overrides.For example,
invoice.exposeprivatechannelsacceptstrue,["1x1x3"], or"1x1x3"in JSON-RPC, but cln-rpc only generatedOption<Vec<ShortChannelId>>, making it impossible to passtruethrough the typed API.Changes
model.py:
UnionField.from_js()constructor bug (missingadded/deprecatedargs)oneOfdetection inCompositeField.from_js()oneOfwas not handledGenerators (6 files):
rust.py: Generate#[serde(untagged)]enumsproto.py: Generate protobufoneofblocks with array wrapper messagesconvert.py/unconvert.py: Generate bidirectionalFromimplsgrpc2py.py: GenerateWhichOneof()-based conversionnotification.py: Automatically supported viarust.py'sgen_fieldTraversal:
patch.py,checks.py: Add recursion intoUnionFieldvariantsTests
cargo test -p cln-rpc— passedcargo test -p cln-grpc --features server— passed (4/4)msggen generate— runs without errorsRelated
Resolves #8961, #8964
🤖 Generated with Claude Code