Skip to content

Commit 813bbcd

Browse files
authored
feat: add option to add description to tags (#2939)
1 parent d27f23b commit 813bbcd

File tree

7 files changed

+496
-449
lines changed

7 files changed

+496
-449
lines changed

examples/internal/clients/abe/api/swagger.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ tags:
2121
- name: "camelCaseServiceName"
2222
- name: "AnotherServiceWithNoBindings"
2323
- name: "SnakeEnumService"
24+
- name: "echo rpc"
25+
description: "Echo Rpc description"
2426
schemes:
2527
- "http"
2628
- "https"

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

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

examples/internal/proto/examplepb/a_bit_of_everything.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
185185
}
186186
}
187187
}
188+
tags: {
189+
name: "echo rpc"
190+
description: "Echo Rpc description"
191+
}
188192
extensions: {
189193
key: "x-grpc-gateway-foo";
190194
value {

examples/internal/proto/examplepb/a_bit_of_everything.swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
},
3232
{
3333
"name": "SnakeEnumService"
34+
},
35+
{
36+
"name": "echo rpc",
37+
"description": "Echo Rpc description"
3438
}
3539
],
3640
"schemes": [

protoc-gen-openapiv2/internal/genopenapi/template.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,21 @@ func applyTemplate(p param) (*openapiSwaggerObject, error) {
18471847
s.extensions = exts
18481848
}
18491849

1850+
if spb.Tags != nil {
1851+
for _, v := range spb.Tags {
1852+
newTag := openapiTagObject{}
1853+
newTag.Name = v.Name
1854+
newTag.Description = v.Description
1855+
if v.ExternalDocs != nil {
1856+
newTag.ExternalDocs = &openapiExternalDocumentationObject{
1857+
Description: v.ExternalDocs.Description,
1858+
URL: v.ExternalDocs.Url,
1859+
}
1860+
}
1861+
s.Tags = append(s.Tags, newTag)
1862+
}
1863+
}
1864+
18501865
// Additional fields on the OpenAPI v2 spec's "OpenAPI" object
18511866
// should be added here, once supported in the proto.
18521867
}

0 commit comments

Comments
 (0)