Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuf: fix casing of json attributes with the switch from gogo #5524

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

jsternberg
Copy link
Collaborator

With the switch from gogo, the oneof fields no longer have their json:"name" fields emitted. Protobuf doesn't formally support these fields and tells users to use the protojson package, but we didn't and the official format is incompatible with the current format we use.

This adds some custom marshaling code to the already existant custom unmarshaling code to ensure these fields are marshaled with the correct casing.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

LGTM 🙏

@crazy-max crazy-max added this to the v0.17.2 milestone Nov 15, 2024
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

Could we have some golden output tests, to make sure this doesn't break again. Current tests only seem to check that the marshaler we used generates data that can be parsed with our current parser, not that the marshaler generates consistent data.

@jsternberg
Copy link
Collaborator Author

I'll change the marshal side of the tests to use an expected string output for the JSON rather than relying on the previous marshal. I'll still have it deserialize both to a map though because maps are easier to compare than JSON strings.

With the switch from gogo, the `oneof` fields no longer have their
`json:"name"` fields emitted. Protobuf doesn't formally support these
fields and tells users to use the `protojson` package, but we didn't and
the official format is incompatible with the current format we use.

This adds some custom marshaling code to the already existant custom
unmarshaling code to ensure these fields are marshaled with the correct
casing.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg jsternberg force-pushed the json-casing-regression branch from 7a15c23 to 56ffa9f Compare November 15, 2024 19:17
@jsternberg
Copy link
Collaborator Author

The tests now have raw JSON in them which should be more reliable.

@tonistiigi tonistiigi merged commit edaa93d into moby:master Nov 19, 2024
91 checks passed
@jsternberg jsternberg deleted the json-casing-regression branch November 20, 2024 01:45
@tonistiigi tonistiigi removed this from the v0.17.2 milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants