grpc-ecosystem/grpc-gateway

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

已关闭

#2,891 创建于 2022年9月16日

 (2 条评论) (1 个反应) (0 位负责人)Go (2,250 个派生)batch import
buggood first issuehelp wantedopenapi

仓库指标

星标
 (16,971 个星标)
PR 合并指标
 (平均合并 8天 23小时) (30 天内合并 147 个 PR)

描述

🚀 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.

贡献者指南