grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec
https://grpc-ecosystem.github.io/grpc-gateway/
BSD 3-Clause "New" or "Revised" License
17.98k stars 2.21k forks source link

protoc-gen-openapiv2: support deprecated field option #2906

Open lachlancooper opened 1 year ago

lachlancooper commented 1 year ago

🚀 Feature

When generating an openapiv2 definition, any protobuf deprecated field options are currently ignored. It would be nice if the generator automatically set the deprecated field on the resulting parameter object accordingly.

Note that the deprecated field on operation objects is already supported, though this is handled through a custom annotation instead of the official deprecated option. This was already touched on in #2856, but in my opinion it makes sense to support the official option (deprecated = true can be set on rpc, message, enum, and field) wherever possible instead of requiring the use of custom annotations.

johanbrandhorst commented 1 year ago

Hi, thanks for your issue! I'm surprised we didn't already have an issue for this, I agree that it makes sense to automatically apply this. Furthermore, if both an annotation and a protobuf level option is set, the annotation should take precedence (so that it's always possible to change the output of the openapi generator without changing the protobuf definition).

denisdubovitskiy commented 1 year ago

@johanbrandhorst i think that this annotation should also add some context value to indicate that the method is deprecated. Having this, we can use an interceptor to collect a metric and notify clients about new implementation. What do you think?

johanbrandhorst commented 1 year ago

I don't think that should be necessary - with APIv2 it should be possible to tell already through reflection whether a method is deprecated. I would consider this ask outside the scope of the gateway.

ankur-kalita commented 1 month ago

can you please assign this issue to me ?

johanbrandhorst commented 1 month ago

Please just submit a PR if you want to work on this