1
votes

I have two services: Story and Tag. The files are structured in this way:

Story
|-- StoryService
|   `-- proto
|       `-- storyservice.proto
`-- TagService
    `-- proto
        `-- tagservice.proto

Each one of .proto files needs to use messages from the other one. How can I import them into each other? I tried import "StoryService/proto/storyservice.proto" but it didn't work.

2

2 Answers

0
votes

If you use protoc, all search paths for import directives should be relative to one of the folders listed in -I (--proto_path) parameter. E.g. if you run protoc -I/path/to/Story --go_out=out StoryService/proto/storyservice.proto, it will be able to import TagService/proto/tagservice.proto (since its path is relative to the Story folder which is listed in -I).

Having said that, you don't really need to make each of your proto files import another one. Recursive proto file import won't work with the error message similar to this one:

a.proto: File recursively imports itself: a.proto -> b.proto -> a.proto
0
votes

You cannot import two proto files into each other. There are two solutions for your scenario. 1. Having a third proto file that contains all the shared definitions. 2. Making all shared definitions into one of the two protos you have, so one can import the other one.