Repository navigation
feat(proto)!: keep unknown fields on every message - #70
Merged
Merged
Conversation
0.5.0 keeps unknown fields on State and Resource alone. Every field Crossplane has added since the function API went v1 is on another message, where prost still discards it, so a function that forwards a request or returns a response it did not build loses such a field. protobuf-go keeps unknown fields on every message. Codegen now replaces prost's Message derive. prost-build writes every struct as before, and codegen/src/messages.rs gives each one an unknown_fields field and the impls the derive would have written: the fallback arm of merge_field keeps a field's bytes and encode_raw writes them back. It reads the field kinds the function proto uses from the #[prost(...)] attributes and refuses one it does not know. State and Resource are generated again, and sdk/src/proto/state.rs is gone. Codegen also writes the messages as prost derives them to sdk/tests/generated/prost_v1.rs. sdk/tests/generated_messages.rs holds every message to that reference: the same bytes, the same verdict and error on malformed input, the same Debug, defaults and accessors. The codegen-drift check covers the new file. BREAKING CHANGE: every message has a new public unknown_fields field. Struct literals and patterns that list every field of a message no longer compile; add ..Default::default() or `..`. The Debug output of every message includes unknown_fields. Fixes #69 Signed-off-by: Jonasz Małecki <[email protected]>
jonasz-lasut
marked this pull request as ready for review
November 19, 2026 10:54
This was referenced Nov 19, 2026
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.
All 16 messages of the function API now keep the fields their proto doesn't know, as
StateandResourcehave since 0.5.0. Codegen replaces prost'sMessagederive: prost-build still writes each struct, andcodegen/src/messages.rsaddsunknown_fieldsand writes the impls the derive would have written, with the fallback arm keeping the bytes. Codegen generatesStateandResourceagain, which removessdk/src/proto/state.rs. A proto update doesn't need hand edits unless it uses a field kind the pass doesn't write yet, and then codegen fails with the field's name.This is breaking for every message in the way 0.5.0 was for two: a struct literal or a pattern that lists every field needs
..Default::default()or.., andDebugoutput includesunknown_fields. It needs 0.6.0.Codegen also writes the messages as prost derives them to
sdk/tests/generated/prost_v1.rs, andsdk/tests/generated_messages.rscompares each message with that reference: the bytes, the verdict and error on malformed input,Debug, the defaults and the accessors. A map decoded without its wire-type check and a wrong default for an enumeration, each put into the pass on purpose, failed those tests.codegen-driftcovers the reference file too.Fixes #69