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

oneof structure is not persisted in protolock #133

Closed
YaseenAlk opened this issue Jul 2, 2021 · 4 comments · Fixed by #151
Closed

oneof structure is not persisted in protolock #133

YaseenAlk opened this issue Jul 2, 2021 · 4 comments · Fixed by #151

Comments

@YaseenAlk
Copy link
Contributor

I'd like to add some additional rules for my own use case of protolock. From reading the wiki, it's my understanding that the preferred way to add more rules is to implement them in a plugin, which takes as input a Protolock go struct that is built from the output of the proto parser.

One rule I'd like to add is to check if a field becomes part of a oneof, or if it is removed from a oneof. However, I don't believe this is possible because the Protolock file does not track which fields are in oneofs. One way around this could be to introduce an optional "oneof parent" pointer for fields (demonstrated here) but I'm not sure if that is the most elegant solution.

I would like to hear your thoughts on this and whether this was previously considered and rejected, or if there is a way to find oneofs in the plugins that I am not aware of. Happy to also author a PR or help out however I can! CCing @adisuissa

@YaseenAlk
Copy link
Contributor Author

I also noticed that oneof options are not recorded (options can be written on enum types, enum values, oneof fields, service types, and service methods).

@nilslice If there is anything I can do to help, let me know! Happy to work on a PR, just wasn't sure if this has been previously rejected. Either way I will likely make these changes to my own fork if they are not desired for the main protolock repo

@nilslice
Copy link
Owner

Hi @YaseenAlk -

From reading the wiki, it's my understanding that the preferred way to add more rules is to implement them in a plugin, which takes as input a Protolock go struct that is built from the output of the proto parser.

Yes, that's right - a plugin is probably the best way to go. Ideally protolock itself is only about catching compatibility issues on the most critical & common kinds of API changes. There are some examples in different languages (Go, JS) in the plugin-sames dir.

I would like to hear your thoughts on this and whether this was previously considered and rejected, or if there is a way to find oneofs in the plugins that I am not aware of. Happy to also author a PR or help out however I can! [...] I also noticed that oneof options are not recorded (options can be written on enum types, enum values, oneof fields, service types, and service methods).

There are a few places where there may be missing implementations (though I believe protolock is fairly comprehensive), and I would love to have help filling in any gaps you find. With regard to your specific need, I think recording options on oneof types is a great addition, and a PR would be welcomed.

Thank you!

@pdecks
Copy link
Contributor

pdecks commented Dec 19, 2023

I created #151 expanding on YaseenAlk@287eb47 and also added a rule utilizing the new field to prevent backwards-incompatible Go changes per https://google.aip.dev/180#moving-into-oneofs.

@nilslice
Copy link
Owner

Thanks @pdecks! I'll take a look at this now. for the time being, I'm running tests locally, as the CI situation isn't up to date. I need to move off Circle CI and onto GitHub actions. Maybe the holiday break will gift me some free time 😆

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 a pull request may close this issue.

3 participants