【发布时间】:2020-05-16 18:00:56
【问题描述】:
关注Deploying the Endpoints configuration后,我已经成功部署了我编译好的.proto文件和gRPC API配置文件。
太好了。我决定做一个好公民,在我的.proto 上使用Google's API Linter。
这导致了许多包含各种注释的建议。注释需要新的 proto 导入;
之前
syntax = "proto3";
package api.v1;
// Request message for Get method.
message GetFooRequest {
// The field will contain name of the resource requested.
string name = 1;
}
...blah,blah
之后
syntax = "proto3";
package api.v1;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
// Request message for Get method.
message GetFooRequest {
// The field will contain name of the resource requested.
string name = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "api.v1.HelloWorld/Foo"
];
}
...blah,blah
注解需要导入四个新的 proto 文件:
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
所有都是Google's Common API protos 的一部分,因此我将the repo 克隆到/Users/Jack/api-common-protos/ 中:
git clone https://github.com/googleapis/api-common-protos.git
...并在编译我的.proto 文件时包含它:
python3 -m grpc_tools.protoc --proto_path=api
--proto_path=/Users/Jack/api-common-protos/google
api/v1/foo.proto
没有错误。伟大的。最后我部署了 API:
gcloud endpoints services deploy api_descriptor.pb api-config.yaml
这就完成了。但是,开发者门户现在显示:
We encountered the following errors while processing this API specification:
API parse error: Error: ENOENT: no such file or directory, open '/tmp/google/api/client.proto'
Please correct these errors and try again.
Scrot:
如果我删除注释(和所需的导入),我的 API 的 Endpoints Developer Portal 工作正常。
【问题讨论】:
-
似乎“protoc”正在寻找文件
/tmp/google/api/client.proto,而您克隆的存储库中的该文件位于/Users/Jack/api-common-protos/google/api/client.proto下
标签: google-cloud-platform protocol-buffers grpc google-cloud-endpoints google-api-linter