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
18.16k stars 2.23k forks source link

Options defined in the OpenAPI config file should take precedence over configs in the Proto file #2891

Open numacci opened 2 years ago

numacci commented 2 years ago

🚀 Feature

As pointed out in #2858, users usually use the openapi configuration file when they can't edit the protobuf file for some reason. So it would be better for the options defined in the openapi configuration file to take precedence.

Currently, only Service has been modified to give priority to the options defined in the OpenAPI configuration file, while the Method, Message, File and Field still give priority to the options defined in the Proto file.

What we need to do

Fix each getXxxOpenAPIOption method so that it first retrieves the options defined in the OpenAPI configuration file, and uses the values defined in the Proto file only if the OpenAPI config options are empty.

It would be nice to check if the automatically generated examples do not change and add some test cases if needed.

For Method, we may need to fix the function below. https://github.com/grpc-ecosystem/grpc-gateway/blob/031bc11c5e7a7ed791f0325cbc01f715ae6714bf/protoc-gen-openapiv2/internal/genopenapi/template.go#L2488

Service has already been fixed. You can refer to the following implementation when fixing the others. https://github.com/grpc-ecosystem/grpc-gateway/blob/031bc11c5e7a7ed791f0325cbc01f715ae6714bf/protoc-gen-openapiv2/internal/genopenapi/template.go#L2518

I think we need to add notes to the doc, as changing the configuration files' priority may impact existing users.

avinilcodes commented 1 year ago

I would like to contribute, can you please assign this to me.

johanbrandhorst commented 1 year ago

Please feel free to open a PR, there's no need to assign the issue. Thanks!