Skip to content

Commit

Permalink
[Bug #3829] [protoc-gen-openapiv2] consider openapiv2_tag.name attrib…
Browse files Browse the repository at this point in the history
…ute when generating ope… (#3830)

* [Bug #3829] consider openapiv2_tag.name attribute when generating openapi docs

* fix artifacts

* fix test

---------

Co-authored-by: Omri Eival <[email protected]>
  • Loading branch information
omrikiei and Omri Eival authored Dec 20, 2023
1 parent b29e87b commit 30552a5
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 141 deletions.
2 changes: 1 addition & 1 deletion examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tags:
- name: "echo rpc"
description: "Echo Rpc description"
x-traitTag: true
- name: "ABitOfEverythingService"
- name: "ABitOfEverything"
description: "ABitOfEverythingService description -- which should not be used in\
\ place of the documentation comment!"
externalDocs:
Expand Down
277 changes: 139 additions & 138 deletions examples/internal/proto/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ message UpdateBookRequest {
// proto messages and URL templates are still processed correctly.
service ABitOfEverythingService {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag) = {
name: "ABitOfEverything"
description: "ABitOfEverythingService description -- which should not be used in place of the documentation comment!"
external_docs: {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"x-traitTag": true
},
{
"name": "ABitOfEverythingService",
"name": "ABitOfEverything",
"description": "ABitOfEverythingService description -- which should not be used in place of the documentation comment!",
"externalDocs": {
"description": "Find out more about EchoService",
Expand Down
3 changes: 3 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ func renderServiceTags(services []*descriptor.Service, reg *descriptor.Registry)
tag.ExternalDocs.Description = goTemplateComments(opts.ExternalDocs.Description, svc, reg)
}
}
if opts.GetName() != "" {
tag.Name = opts.GetName()
}
}
tags = append(tags, tag)
}
Expand Down
7 changes: 6 additions & 1 deletion protoc-gen-openapiv2/internal/genopenapi/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6319,7 +6319,8 @@ func TestTagsWithGoTemplate(t *testing.T) {
Description: "{{ import \"file\" }}",
},
{
Name: "ExampleService",
Name: "ExampleService",
Description: "ExampleService!",
},
{
Name: "not a service tag 2",
Expand Down Expand Up @@ -6354,6 +6355,10 @@ func TestTagsWithGoTemplate(t *testing.T) {
Name: "Service with my_key",
Description: "the my_value",
},
{
Name: "service tag",
Description: "ExampleService!",
},
}
if !reflect.DeepEqual(actual.Tags, expectedTags) {
t.Errorf("Expected tags %+v, not %+v", expectedTags, actual.Tags)
Expand Down

0 comments on commit 30552a5

Please sign in to comment.