Skip to content

Commit

Permalink
Add example for using buf to set field option jstype
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Jul 29, 2024
1 parent 7ab0abe commit 8436798
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ If you prefer that a field use `string` instead of `bigint`, use the field optio
int64 field = 1 [jstype = JS_STRING]; // will generate `field: string`
```

> [!TIP]
>
> Set `jstype = JS_STRING` on all applicable fields automatically with [buf][buf-cli]. Add the following
> [managed mode][buf.build/managed-mode] config:
>
> ```yaml
> # Add to buf.gen.yaml:
> managed:
> enabled: true
> override:
> - field_option: jstype
> value: JS_STRING
> ```
### Message fields
For the following Protobuf field declaration:
Expand Down Expand Up @@ -2374,6 +2388,7 @@ side of caution.
[buf-images]: https://buf.build/docs/reference/images
[buf.build/conformance-blog]: https://buf.build/blog/protobuf-conformance
[buf.build/descriptors]: https://buf.build/docs/reference/descriptors#deep-dive-into-the-model
[buf.build/managed-mode]: https://buf.build/docs/generate/managed-mode#optimization-and-field-options
[Buf]: https://buf.build
[bundle-size]: https://github.com/bufbuild/protobuf-es/blob/main/packages/bundle-size
[canonical-json]: https://protobuf.dev/programming-guides/proto3/#json
Expand Down
7 changes: 7 additions & 0 deletions packages/protobuf-example/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ plugins:
- local: protoc-gen-es
opt: target=ts
out: src/gen

# Uncomment to set `jstype = JS_STRING` on all applicable fields automatically:
# managed:
# enabled: true
# override:
# - field_option: jstype
# value: JS_STRING

0 comments on commit 8436798

Please sign in to comment.