bufbuild / buf

The best way of working with Protocol Buffers.
https://buf.build
Apache License 2.0
9.04k stars 273 forks source link

Running a plugin on a single package within a directory #995

Closed jon-whit closed 2 years ago

jon-whit commented 2 years ago

My project organizes protobufs like so:

cmd/app/main.go
protos/
    package1/package1_service.proto
    package2/package2_service.proto
    common/file.proto
    buf.yaml
buf.work.yaml
buf.gen.yaml

package1 and package2 define gRPC service definitions and define protoc_gen_openapiv2 annotations. These packages import the common package, which has definitions that are shared across packages.

I'm trying to build OpenAPI doc for the services in package1 and package2. I want them to be two different outputs because one is customer facing and one is internally facing.

What is the best way to generate OpenAPI doc by invoking the protoc-gen-openapiv2 plugin uniquely for package1 and package2, but not have them overlap with one another?

timostamm commented 2 years ago

Hey Jonathan,

you can limit to specific files:

$ buf generate --path protos/package1 --path protos/common

However, I would generally recommend to use multiple modules:

.
|-- buf.gen.yaml
|-- buf.work.yaml
`-- protos
    |-- common
    |   |-- buf.yaml
    |   `-- common
    |       `-- c.proto
    |-- package1
    |   |-- buf.yaml
    |   `-- package1
    |       `-- p1.proto
    `-- package2
        |-- buf.yaml
        `-- package2
            `-- p2.proto
$ buf generate protos/package1 --include-imports

Does either option work for you?

jon-whit commented 2 years ago

Yep! That works great. Thanks for the tips 👍