Skip to content

Commit

Permalink
Update buf example from v1 to v2. (#4347)
Browse files Browse the repository at this point in the history
  • Loading branch information
iFurySt authored Oct 12, 2024
1 parent 2014367 commit 02ff501
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ This step generates the gRPC stubs that you can use to implement the service and
Here's an example `buf.gen.yaml` you can use to generate the stubs with [buf](https:/bufbuild/buf):

```yaml
version: v1
version: v2
plugins:
- plugin: go
- local: protoc-gen-go
out: gen/go
opt:
- paths=source_relative
- plugin: go-grpc
- local: protoc-gen-go-grpc
out: gen/go
opt:
- paths=source_relative
Expand Down Expand Up @@ -190,17 +190,17 @@ The `generate_unbound_methods` should be enabled.
Here's what a `buf.gen.yaml` file might look like with this option enabled:

```yaml
version: v1
version: v2
plugins:
- plugin: go
- local: protoc-gen-go
out: gen/go
opt:
- paths=source_relative
- plugin: go-grpc
- local: protoc-gen-go-grpc
out: gen/go
opt:
- paths=source_relative
- plugin: grpc-gateway
- local: protoc-gen-grpc-gateway
out: gen/go
opt:
- paths=source_relative
Expand Down Expand Up @@ -251,13 +251,13 @@ annotation to your .proto file
> `buf.build/googleapis/googleapis`:
>
> ```yaml
> version: v1
> version: v2
> name: buf.build/yourorg/myprotos
> deps:
> - buf.build/googleapis/googleapis
> ```
>
> Always run `buf mod update` after adding a dependency to your `buf.yaml`.
> Always run `buf dep update` after adding a dependency to your `buf.yaml`.

See [a_bit_of_everything.proto](examples/internal/proto/examplepb/a_bit_of_everything.proto)
for examples of more annotations you can add to customize gateway behavior
Expand All @@ -266,17 +266,17 @@ and generated OpenAPI output.
Here's what a `buf.gen.yaml` file might look like:

```yaml
version: v1
version: v2
plugins:
- plugin: go
- local: protoc-gen-go
out: gen/go
opt:
- paths=source_relative
- plugin: go-grpc
- local: protoc-gen-go-grpc
out: gen/go
opt:
- paths=source_relative
- plugin: grpc-gateway
- local: protoc-gen-grpc-gateway
out: gen/go
opt:
- paths=source_relative
Expand Down Expand Up @@ -316,17 +316,17 @@ generated by the source protobuf file.
Here's what a `buf.gen.yaml` file might look like with this option enabled:

```yaml
version: v1
version: v2
plugins:
- plugin: go
- local: protoc-gen-go
out: gen/go
opt:
- paths=source_relative
- plugin: go-grpc
- local: protoc-gen-go-grpc
out: gen/go
opt:
- paths=source_relative
- plugin: grpc-gateway
- local: protoc-gen-grpc-gateway
out: gen/go
opt:
- paths=source_relative
Expand Down Expand Up @@ -400,22 +400,23 @@ func main() {
Here's what a `buf.gen.yaml` file might look like:

```yaml
version: v1
version: v2
plugins:
- plugin: go
- local: protoc-gen-go
out: gen/go
opt:
- paths=source_relative
- plugin: go-grpc
- local: protoc-gen-go-grpc
out: gen/go
opt:
- paths=source_relative
- plugin: grpc-gateway
- local: protoc-gen-grpc-gateway
out: gen/go
opt:
- paths=source_relative
- plugin: openapiv2
out: gen/openapiv2
- generate_unbound_methods=true
- local: protoc-gen-openapiv2
out: gen/go
```

To use the custom protobuf annotations supported by `protoc-gen-openapiv2`, we need
Expand All @@ -424,7 +425,7 @@ another dependency added to our protobuf generation step. If you are using
to your `deps` array:

```yaml
version: v1
version: v2
name: buf.build/yourorg/myprotos
deps:
- buf.build/googleapis/googleapis
Expand Down Expand Up @@ -461,26 +462,26 @@ for more information.
## Usage with remote plugins

As an alternative to all of the above, you can use `buf` with
[remote plugins](https://docs.buf.build/configuration/v1/buf-gen-yaml#name-or-remote)
[remote plugins](https://buf.build/docs/bsr/remote-plugins/usage)
to manage plugin versions and generation. An example `buf.gen.yaml` using remote
plugin generation looks like this:

```yaml
version: v1
version: v2
plugins:
- plugin: buf.build/protocolbuffers/go:v1.31.0
- remote: buf.build/protocolbuffers/go:v1.31.0
out: gen/go
opt:
- paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
- remote: buf.build/grpc/go:v1.3.0
out: gen/go
opt:
- paths=source_relative
- plugin: buf.build/grpc-ecosystem/gateway:v2.16.2
- remote: buf.build/grpc-ecosystem/gateway:v2.16.2
out: gen/go
opt:
- paths=source_relative
- plugin: buf.build/grpc-ecosystem/openapiv2:v2.16.2
- remote: buf.build/grpc-ecosystem/openapiv2:v2.16.2
out: gen/openapiv2
```

Expand Down Expand Up @@ -511,9 +512,9 @@ When using `buf` to generate stubs, flags and parameters are passed through
the `opt` field in your `buf.gen.yaml` file, for example:

```yaml
version: v1
version: v2
plugins:
- plugin: grpc-gateway
- local: protoc-gen-grpc-gateway
out: gen/go
opt:
- paths=source_relative
Expand Down

0 comments on commit 02ff501

Please sign in to comment.