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

Match protojson's output field order #40

Merged
merged 7 commits into from
Aug 12, 2024
Merged

Match protojson's output field order #40

merged 7 commits into from
Aug 12, 2024

Conversation

Alfus
Copy link
Contributor

@Alfus Alfus commented Aug 9, 2024

see #36
JSON objects are unmarshaled into (unordered) go maps by default. This PR uses yaml.Node (when possible) instead, which preserves the field order from protojson.

Note that yaml refuses to parse control characters into yaml.Nodes, though otherwise handle them correctly.

@Alfus Alfus requested a review from jhump August 9, 2024 14:07
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
encode.go Show resolved Hide resolved
internal/protoyamltest/golden/golden.go Show resolved Hide resolved
protoyaml_test.go Outdated Show resolved Hide resolved
return err.Error(), nil
}
return "", nil
return golden.GenGoldenContent(filePath, data)
Copy link
Member

Choose a reason for hiding this comment

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

I am super-confused by the previous formulation that you've replaced. It looks like it basically always returned the empty string on success, instead of string(data). But the new formulation "round-trips" the file and returns the contents after re-marshaling.

All that intended? Mind adding some remarks in a comment or in the PR description to provide some guidance on some of this diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I added a new 'class' of tests for valid .yaml files, that verifies the marshalled output is as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(basically, it validates that everything is normalized and in the right order for valid .yamls)

@Alfus Alfus merged commit 489b0e2 into main Aug 12, 2024
5 checks passed
@Alfus Alfus deleted the alfus/order branch August 12, 2024 14:50
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