protoc-gen-doc icon indicating copy to clipboard operation
protoc-gen-doc copied to clipboard

Doc with imports failing

Open marcoapferegrino opened this issue 5 years ago • 12 comments

Hi !!

I guess there is an issue with imported Protos.

I have an accounts.proto which imports data.proto they are in the same directory but when I execute I already executed the line inside V1 directory and in services. My directory structure is

  • services -- google --- protobuf ---- empty.proto -- V1 --- accounts.proto --- data.proto

docker run --rm \ -v $(pwd)/doc:/out \ -v $(pwd):/protos \ pseudomuto/protoc-gen-doc

The terminal shows me

V1/data.proto: File not found. accounts.proto: Import "V1/data.proto" was not found or had errors.

I am sure there is no errors because I use other import validators.

Proto Accounts

`// version 0.1.0 syntax = "proto3";

import "google/protobuf/empty.proto"; import "V1/data.proto";

package accounts.v1;`

Proto Data (It contains the messages of the Requests and Responses of accounts.proto)

`syntax = "proto3";

package accounts.v1;`

Is there a missing feature of the doc generator ? or there is an error in my Protos

marcoapferegrino avatar Dec 10 '19 16:12 marcoapferegrino

I got this problem too. Any one found a way to solve this?

prathanbomb avatar Apr 25 '20 07:04 prathanbomb

You need to supply the root directory to protoc via the -I switch just as you would do on the protoc command line. I have a similar setup with proto files nested in subfolders and includes between them. The following works for me:

$PROTO_ROOT = $pwd/services (or whereever your proto files are)
docker run --rm -it -v "$PROTO_ROOT/doc:/out" -v "$PROTO_ROOT:/protos" pseudomuto/protoc-gen-doc -I/protos $(find $PROTO_ROOT -name '*.proto')

timon-k avatar Jun 22 '20 16:06 timon-k

Doesn't seem to work for me either. Do you have more details on your setup/script @timon-k ? Would love a version for the simple usage with just the protoc command

Chr1stian avatar Jul 27 '20 13:07 Chr1stian

Can you tell me what does not work / describe your setup in more detail? Otherwise I don't really know what to describe in more detail. The pseudomuto/protoc-gen-doc image already calls protoc in its entrypoint, therefore I just added parameters for that call (-I, input file list) above.

If you want to have a custom call to protoc you have to override the entrypoint.

timon-k avatar Aug 17 '20 08:08 timon-k

Got it to work by using protoc --proto_path=src/main/protobuf/

Chr1stian avatar Aug 18 '20 08:08 Chr1stian

It does not work for me.

I ran, as the doc said:

 docker run --rm \
  -v $(pwd)/V1/doc:/out \
  -v $(pwd)/V1/.:/protos \

But it told me

V1/accountsBusinessMessages.proto: File not found.
accountsBusiness.proto: Import "V1/accountsBusinessMessages.proto" was not found or had errors.

I execute it from mainDirectory:

  • mainDirectory -- V1 --- accountsBusiness.proto --- accountsBusinessMessages.proto

marcoapferegrino avatar Aug 18 '20 16:08 marcoapferegrino

It does not work for me.

I ran, as the doc said:

 docker run --rm \
  -v $(pwd)/V1/doc:/out \
  -v $(pwd)/V1/.:/protos \

But it told me

V1/accountsBusinessMessages.proto: File not found.
accountsBusiness.proto: Import "V1/accountsBusinessMessages.proto" was not found or had errors.

I execute it from mainDirectory:

  • mainDirectory -- V1 --- accountsBusiness.proto --- accountsBusinessMessages.proto

Try

docker run --rm \
    -v $(pwd)/V1/doc:/out \
    -v $(pwd)/V1/.:/protos \
    -I/protos $(pwd)/V1

Chr1stian avatar Aug 19 '20 12:08 Chr1stian

docker run --rm
-v $(pwd)/V1/doc:/out
-v $(pwd)/V1/.:/protos
-I/protos $(pwd)/V1

Hello friend,

When I ran the command, it shows me :

unknown shorthand flag: 'I' in -I/protos See 'docker run --help'.

marcoapferegrino avatar Aug 19 '20 13:08 marcoapferegrino

docker run --rm -v $(pwd)/V1/doc:/out -v $(pwd)/V1/.:/protos -I/protos $(pwd)/V1

Hello friend,

When I ran the command, it shows me :

unknown shorthand flag: 'I' in -I/protos See 'docker run --help'.

Need to also include pseudomuto/protoc-gen-doc, try the following with and without the last line:

docker run --rm \
    -v $(pwd)/V1/doc:/out \
    -v $(pwd)/V1:/protos:ro \
    pseudomuto/protoc-gen-doc \
    -I/protos accounts.proto

Chr1stian avatar Aug 21 '20 11:08 Chr1stian

Hello dude

I tried in both cases with and without, from my root project. It's really weird, it does not generate the doc files but the directory doc it does. The console told me

V1/accountsBusinessMessages.proto: File not found.
accountsBusiness.proto: Import "V1/accountsBusinessMessages.proto" was not found or had errors.
...

The V1/accountsBusinessMessages.proto: its an import I have inside the V1/accountsBusiness.proto. I really tried different variations.

marcoapferegrino avatar Aug 23 '20 15:08 marcoapferegrino

Hello dude

I tried in both cases with and without, from my root project. It's really weird, it does not generate the doc files but the directory doc it does. The console told me

V1/accountsBusinessMessages.proto: File not found.
accountsBusiness.proto: Import "V1/accountsBusinessMessages.proto" was not found or had errors.
...

The V1/accountsBusinessMessages.proto: its an import I have inside the V1/accountsBusiness.proto. I really tried different variations.

I am also facing same issue.

pundliksarafdar avatar Jul 02 '21 08:07 pundliksarafdar

For my usecase i have found the following solution: Folder Structure:

proto
└── company
    ├── Documentation
    │   ├── generated (Output Dir)
    └── project
        ├── device_config.proto
        ├── firmware_upgrade.proto

Where firmware_upgarde uses import: import "company/project/device_config.proto"; I use the following (additional import dir mounting):

rm -rf proto/company/Documentation/generated
mkdir -p proto/company/Documentation/generated
for file in proto/company/project/*.proto; do
    [ -f "$file" ] || break
    basefiledest=$(basename $file .proto) #get basefile destination (e.g. firmware_upgrade)
    basefile=$(basename $file). #get proto file to configure (e.g. firmware_upgrade.proto)
    echo "Generating for $file --> $basefile"
    docker run --rm \
    -v $(pwd)/proto/company/Documentation/generated:/out \. #map output dir
    -v $(pwd)/proto/company/project/:/protos \.  #add direct mount for proto source files (without folder structure)
    -v $(pwd)/proto/:/imports \.  #add raw import directory with structure according to import (see company/project/*.proto)
    pseudomuto/protoc-gen-doc --doc_opt=markdown,$basefiledest.md -I/imports/ $basefile
done

it's a bit a workaround as i must execute it for all files individually. ideally when using the -I option i wouldn't have to give an input file but unfortunatly this is not supported

stefboerrigterWavin avatar May 04 '22 11:05 stefboerrigterWavin