19

Does anyone know where I can find an example of a gRPC protobuf file that imports from a different file and uses a protobuf message in a return? I can't find any at all.

I have a file...

syntax = "proto3";
package a1;
import "a.proto";
service mainservice {
  rpc DoSomething(...) returns (a.SomeResponse) {}


}

a.proto is also in the same directory and also compiles by itself. The error messages I'm getting are: "a.SomeResponse" is not defined. mainfile.proto: warning: Import a.proto but not used.

user3125693
  • 870
  • 11
  • 24

2 Answers2

41

Found the answer... need to make sure the package name of a.proto is used when specifying the object imported (eg: a_package_name.SomeResponse). Example:

base.proto

syntax = "proto3";
option csharp_namespace = "Api.Protos";
package base;
message BaseResponse {
    bool IsSuccess = 1;
    string Message = 2;
}

user.proto

syntax = "proto3";
import "Protos/base.proto";
option csharp_namespace = "Api.Protos";
package user;

message UserCreateResponse {
    base.BaseResponse response = 1;
}
Biswajit Panday
  • 817
  • 10
  • 20
user3125693
  • 870
  • 11
  • 24
0

Seems import from root but not current proto file's folder. So you need add 'Proto/a.proto' if all your proto files are under Proto folder.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 21 '21 at 04:57