Skip to content

Commit

Permalink
feat: add option to add description to tags (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
same-id committed Oct 14, 2022
1 parent d27f23b commit 813bbcd
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 449 deletions.
2 changes: 2 additions & 0 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ tags:
- name: "camelCaseServiceName"
- name: "AnotherServiceWithNoBindings"
- name: "SnakeEnumService"
- name: "echo rpc"
description: "Echo Rpc description"
schemes:
- "http"
- "https"
Expand Down
28 changes: 15 additions & 13 deletions examples/internal/proto/examplepb/a_bit_of_everything.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/internal/proto/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
}
}
}
tags: {
name: "echo rpc"
description: "Echo Rpc description"
}
extensions: {
key: "x-grpc-gateway-foo";
value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
},
{
"name": "SnakeEnumService"
},
{
"name": "echo rpc",
"description": "Echo Rpc description"
}
],
"schemes": [
Expand Down
15 changes: 15 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,21 @@ func applyTemplate(p param) (*openapiSwaggerObject, error) {
s.extensions = exts
}

if spb.Tags != nil {
for _, v := range spb.Tags {
newTag := openapiTagObject{}
newTag.Name = v.Name
newTag.Description = v.Description
if v.ExternalDocs != nil {
newTag.ExternalDocs = &openapiExternalDocumentationObject{
Description: v.ExternalDocs.Description,
URL: v.ExternalDocs.Url,
}
}
s.Tags = append(s.Tags, newTag)
}
}

// Additional fields on the OpenAPI v2 spec's "OpenAPI" object
// should be added here, once supported in the proto.
}
Expand Down
Loading

0 comments on commit 813bbcd

Please sign in to comment.