pseudomuto / protoc-gen-doc

Documentation generator plugin for Google Protocol Buffers
MIT License
2.61k stars 462 forks source link

Doc with imports failing #407

Open marcoapferegrino opened 4 years ago

marcoapferegrino commented 4 years ago

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

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

prathanbomb commented 4 years ago

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

timon-k commented 4 years ago

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')
Chr1stian commented 4 years ago

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

timon-k commented 4 years ago

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.

Chr1stian commented 4 years ago

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

marcoapferegrino commented 4 years ago

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:

Chr1stian commented 4 years ago

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
marcoapferegrino commented 4 years ago

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'.

Chr1stian commented 4 years ago

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
marcoapferegrino commented 3 years ago

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.

pundliksarafdar commented 3 years ago

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.

stefboerrigterWavin commented 2 years ago

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