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

Option field "(google.api.http)" is not a field or extension of message "ServiceOptions" #241

Closed
shenshouer opened this issue Oct 20, 2016 · 4 comments

Comments

@shenshouer
Copy link

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.ssjt.heartbeat";
option java_outer_classname = "Hearbeat";

package protobuf;

import "google/api/annotations.proto";

service Greeter {
    rpc SayHello (HelloRequest) returns (HelloRespone) {}
    option (google.api.http) = {
      post: "/v1/example/echo"
      body: "*"
    };
}

message HelloRequest {
  string name = 1;
  string ip = 2;
  string osname = 3;
  string osversion = 4;

  int64 CPUModelName = 5;
  int64 CPUCount = 6;

  message MemoryInfo {
      int64 MemTotal = 1;
      int64 MemFree = 2;
      int64 MemAvailable = 3;
      double UsedPercent = 4;
  }
  MemoryInfo memoryInfo = 7;

  message DiskInfo {
    string Device = 1;
    double Total = 2;
    double Free = 3;
    double UsedPercent = 4;
  }
  DiskInfo diskInfo = 8;
}

// The response message containing the greetings
message HelloRespone {
  string message = 1;
}

protobuf git:(master) ✗ protoc -I/usr/local/include -I. \                                                 
 -I$GOPATH/src \                                                                                             
 -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \                               
 --go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/
api,plugins=grpc:. \                                                                                         
*.proto                                                                                                      
heartbeat.proto:13:12: Option field "(google.api.http)" is not a field or extension of message "ServiceOptions".              

How to fix this?

@shenshouer
Copy link
Author

change to

service Greeter {
    rpc SayHello (HelloRequest) returns (HelloRespone) {
    option (google.api.http) = {
      post: "/v1/example/echo"
      body: "*"
    }
}
}

worked fine

@tamalsaha tamalsaha mentioned this issue Mar 30, 2017
1 task
@lei314121077
Copy link

How to fix this?

@rogerhub
Copy link

rogerhub commented Aug 4, 2018

@lei314121077 "google.api.http" is an extension of MethodOptions, not ServiceOptions. Make sure that your annotations are within the curly braces for an RPC method.

Using the examples from above:

Wrong:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloResponse) {}
  option (google.api.http) = {
    post: "/v1/example/echo"
    body: "*"
  };
}

Correct:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloResponse) {
    option (google.api.http) = {
      post: "/v1/example/echo"
      body: "*"
    }
  };
}

@lei314121077
Copy link

OK thanks regerhub !!

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

No branches or pull requests

3 participants