Skip to content

Commit 1ed5aa1

Browse files
authored
Add remove_internal_comments option (#3560)
To allow internal comments within the protobuf which won't make it the generated OAS file. Using Google's AIP-192: https://google.aip.dev/192#internal-comments
1 parent d476e2a commit 1ed5aa1

File tree

16 files changed

+784
-0
lines changed

16 files changed

+784
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ proto:
118118
buf generate \
119119
--template ./examples/internal/proto/examplepb/ignore_comment.buf.gen.yaml \
120120
--path examples/internal/proto/examplepb/ignore_comment.proto
121+
buf generate \
122+
--template ./examples/internal/proto/examplepb/remove_internal_comment.buf.gen.yaml \
123+
--path examples/internal/proto/examplepb/remove_internal_comment.proto
121124
buf generate \
122125
--template ./examples/internal/proto/examplepb/visibility_rule_preview_echo_service.buf.gen.yaml \
123126
--path examples/internal/proto/examplepb/visibility_rule_echo_service.proto

buf.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ lint:
2424
- examples/internal/proto/examplepb/visibility_rule_echo_service.proto
2525
- examples/internal/proto/examplepb/use_go_template.proto
2626
- examples/internal/proto/examplepb/ignore_comment.proto
27+
- examples/internal/proto/examplepb/remove_internal_comment.proto
2728
- examples/internal/proto/examplepb/wrappers.proto
2829
ENUM_VALUE_PREFIX:
2930
- examples/internal/proto/examplepb/a_bit_of_everything.proto
@@ -61,6 +62,7 @@ lint:
6162
- examples/internal/proto/examplepb/visibility_rule_echo_service.proto
6263
- examples/internal/proto/examplepb/use_go_template.proto
6364
- examples/internal/proto/examplepb/ignore_comment.proto
65+
- examples/internal/proto/examplepb/remove_internal_comment.proto
6466
- examples/internal/proto/examplepb/wrappers.proto
6567
- examples/internal/proto/oneofenum/oneof_enum.proto
6668
- examples/internal/proto/pathenum/path_enum.proto
@@ -87,6 +89,7 @@ lint:
8789
- examples/internal/proto/examplepb/visibility_rule_echo_service.proto
8890
- examples/internal/proto/examplepb/use_go_template.proto
8991
- examples/internal/proto/examplepb/ignore_comment.proto
92+
- examples/internal/proto/examplepb/remove_internal_comment.proto
9093
- examples/internal/proto/examplepb/wrappers.proto
9194
- runtime/internal/examplepb/example.proto
9295
- runtime/internal/examplepb/non_standard_names.proto
@@ -108,6 +111,7 @@ lint:
108111
- examples/internal/proto/examplepb/visibility_rule_echo_service.proto
109112
- examples/internal/proto/examplepb/use_go_template.proto
110113
- examples/internal/proto/examplepb/ignore_comment.proto
114+
- examples/internal/proto/examplepb/remove_internal_comment.proto
111115
- examples/internal/proto/examplepb/wrappers.proto
112116
- examples/internal/proto/oneofenum/oneof_enum.proto
113117
- examples/internal/proto/pathenum/path_enum.proto
@@ -166,6 +170,7 @@ lint:
166170
- examples/internal/proto/examplepb/visibility_rule_echo_service.proto
167171
- examples/internal/proto/examplepb/use_go_template.proto
168172
- examples/internal/proto/examplepb/ignore_comment.proto
173+
- examples/internal/proto/examplepb/remove_internal_comment.proto
169174
- examples/internal/proto/examplepb/wrappers.proto
170175
- runtime/internal/examplepb/non_standard_names.proto
171176
SERVICE_PASCAL_CASE:

docs/docs/mapping/customizing_openapi_output.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,11 @@ or with `protoc`:
847847
protoc --openapiv2_out=. --openapiv2_opt=ignore_comments=true ./path/to/file.proto
848848
```
849849

850+
### Removing internal comments
851+
852+
If you want to remove internal comments from the from OpenAPI output (such as `TODO` and `FIXME` directives) you can use the `remove_internal_comments` option.
853+
If set to `true`, this will remove all comment text located between `(--` and `--)` as per [AIP 192: Internal comments](https://google.aip.dev/192#internal-comments).
854+
850855
### Preserve RPC Path Order
851856

852857
By default, generated Swagger files emit paths found in proto files in alphabetical order. If you would like to

examples/internal/proto/examplepb/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package(default_visibility = ["//visibility:public"])
2525
# gazelle:exclude use_go_template.pb.gw.go
2626
# gazelle:exclude use_go_template_grpc.pb.go
2727
# gazelle:exclude ignore_comment.pb.gw.go
28+
# gazelle:exclude remove_internal_comment.pb.gw.go
2829
# gazelle:exclude ignore_comment_grpc.pb.go
2930
# gazelle:exclude wrappers.pb.gw.go
3031
# gazelle:exclude wrappers_grpc.pb.go
@@ -53,6 +54,7 @@ proto_library(
5354
"generated_output.proto",
5455
"ignore_comment.proto",
5556
"non_standard_names.proto",
57+
"remove_internal_comment.proto",
5658
"response_body_service.proto",
5759
"stream.proto",
5860
"unannotated_echo_service.proto",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v1
2+
plugins:
3+
- name: openapiv2
4+
out: .
5+
opt:
6+
- remove_internal_comments=true

examples/internal/proto/examplepb/remove_internal_comment.pb.go

Lines changed: 240 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)