Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix name tags in methods #3843

Merged
merged 10 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 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 Expand Up @@ -1401,7 +1401,7 @@ paths:
/v1/example/a_bit_of_everything/query/{uuidName}:
get:
tags:
- "ABitOfEverythingService"
- "ABitOfEverything"
operationId: "ABitOfEverythingService_GetQuery"
parameters:
- name: "uuidName"
Expand Down Expand Up @@ -4049,7 +4049,7 @@ paths:
$ref: "#/definitions/rpcStatus"
delete:
tags:
- "ABitOfEverythingService"
- "ABitOfEverything"
operationId: "ABitOfEverythingService_Delete"
parameters:
- name: "uuid"
Expand Down Expand Up @@ -4869,7 +4869,7 @@ paths:
/v2/example/overwriterequestcontenttype:
post:
tags:
- "ABitOfEverythingService"
- "ABitOfEverything"
operationId: "ABitOfEverythingService_OverwriteRequestContentType"
consumes:
- "application/x-bar-mime"
Expand Down Expand Up @@ -4909,7 +4909,7 @@ paths:
/v2/example/overwriteresponsecontenttype:
get:
tags:
- "ABitOfEverythingService"
- "ABitOfEverything"
operationId: "ABitOfEverythingService_OverwriteResponseContentType"
produces:
- "application/text"
Expand Down
874 changes: 874 additions & 0 deletions examples/internal/clients/abe/api_a_bit_of_everything.go

Large diffs are not rendered by default.

1,030 changes: 92 additions & 938 deletions examples/internal/clients/abe/api_a_bit_of_everything_service.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/internal/clients/abe/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type APIClient struct {

// API Services

ABitOfEverythingApi *ABitOfEverythingApiService
johanbrandhorst marked this conversation as resolved.
Show resolved Hide resolved

ABitOfEverythingServiceApi *ABitOfEverythingServiceApiService

CamelCaseServiceNameApi *CamelCaseServiceNameApiService
Expand All @@ -71,6 +73,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
c.common.client = c

// API Services
c.ABitOfEverythingApi = (*ABitOfEverythingApiService)(&c.common)
c.ABitOfEverythingServiceApi = (*ABitOfEverythingServiceApiService)(&c.common)
c.CamelCaseServiceNameApi = (*CamelCaseServiceNameApiService)(&c.common)
c.EchoRpcApi = (*EchoRpcApiService)(&c.common)
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 Expand Up @@ -2003,7 +2003,7 @@
}
],
"tags": [
"ABitOfEverythingService"
"ABitOfEverything"
],
"deprecated": true,
"security": [],
Expand Down Expand Up @@ -4711,7 +4711,7 @@
}
],
"tags": [
"ABitOfEverythingService"
"ABitOfEverything"
],
"security": [
{
Expand Down Expand Up @@ -6615,7 +6615,7 @@
}
],
"tags": [
"ABitOfEverythingService"
"ABitOfEverything"
],
"consumes": [
"application/x-bar-mime"
Expand Down Expand Up @@ -6663,7 +6663,7 @@
}
},
"tags": [
"ABitOfEverythingService"
"ABitOfEverything"
],
"produces": [
"application/text"
Expand Down
10 changes: 10 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()
}
johanbrandhorst marked this conversation as resolved.
Show resolved Hide resolved
}
tags = append(tags, tag)
}
Expand Down Expand Up @@ -1521,6 +1524,11 @@ func renderServices(services []*descriptor.Service, paths *openapiPathsObject, r
panic(err)
}

svcOpts, err := getServiceOpenAPIOption(reg, svc)
if err != nil {
grpclog.Error(err)
return err
}
opts, err := getMethodOpenAPIOption(reg, meth)
if opts != nil {
if err != nil {
Expand All @@ -1539,6 +1547,8 @@ func renderServices(services []*descriptor.Service, paths *openapiPathsObject, r
if len(opts.Tags) > 0 {
operationObject.Tags = make([]string, len(opts.Tags))
copy(operationObject.Tags, opts.Tags)
} else if svcOpts.GetName() != "" {
operationObject.Tags = []string{svcOpts.GetName()}
}
if opts.OperationId != "" {
operationObject.OperationID = opts.OperationId
Expand Down
6 changes: 5 additions & 1 deletion protoc-gen-openapiv2/internal/genopenapi/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6344,7 +6344,7 @@ func TestTagsWithGoTemplate(t *testing.T) {
},
{
Name: "ExampleService",
Description: "ExampleService!",
Description: "",
},
{
Name: "not a service tag 2",
Expand All @@ -6354,6 +6354,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
Loading