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

Can protoc-gen-swagger hide the specified fields? #1791

Closed
yunqiang-sun opened this issue Nov 5, 2020 · 9 comments · Fixed by #2418
Closed

Can protoc-gen-swagger hide the specified fields? #1791

yunqiang-sun opened this issue Nov 5, 2020 · 9 comments · Fixed by #2418

Comments

@yunqiang-sun
Copy link

🚀 Feature

I want to hide certain fields in the json generated by protoc-gen-swagger

@johanbrandhorst
Copy link
Collaborator

I don't think we support this today. If you'd like to contribute this I would consider it if you can come up with a good design.

@ewhauser
Copy link
Contributor

I think extensions are the best way to handle hidden/private operations, parameters, fields, etc. There's an existing open source tool that allows you to filter your generated schema: https://github.com/Mermade/openapi-filter

I don't believe protoc-gen-swagger lets you define extensions on fields at the moment, but that could be added.

@santhosh-v
Copy link

santhosh-v commented Jul 16, 2021

If field level support is there, I think with this we could use this filter. Is it possible to add soon ?

@johanbrandhorst
Copy link
Collaborator

This isn't going to be added unless someone has the time to contribute it.

@james-o-johnstone
Copy link
Contributor

james-o-johnstone commented Nov 8, 2021

Opened a PR #2418 to define extensions on fields, so fields could be marked with an x-internal extension and filtered using https://github.com/Mermade/openapi-filter.

@johanbrandhorst
Copy link
Collaborator

There is now an alternative implementation to hiding fields/RPCs in #2578. We probably only want to merge one, so would interested parties weigh in on which they would prefer?

@BCook98
Copy link
Contributor

BCook98 commented Mar 11, 2022

I'm slightly biased towards #2578 😉.

Both are nice solutions towards hiding fields/RPCs, but google.api.VisibilityRules provides the ability to completely hide fields from the output. That way consumers never know a field exists, instead of having to rely on the Swagger renderer/ codegen to do that for you.

That being said it looks like #2418 is still useful in other scenarios where you want to apply other swagger extensions to fields and schemas.

@ewhauser
Copy link
Contributor

I concur with @BCook98. First class support for google.api.VisbilityRules seems like the way to go - I'm not sure this was around (or at least I didn't know about it) when I suggested extensions.

I also agree that these two implementations are not mutually exclusive.

@johanbrandhorst
Copy link
Collaborator

Fair points, lets consider each on its own merits, thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants