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 rpc comment generation against allow_merge (v2) #1446

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ OPENAPI_EXAMPLES=examples/internal/proto/examplepb/echo_service.proto \
examples/internal/proto/examplepb/unannotated_echo_service.proto \
examples/internal/proto/examplepb/use_go_template.proto \
examples/internal/proto/examplepb/response_body_service.proto
OPENAPIMERGE_EXAMPLES=examples/internal/proto/examplepb/openapi_merge_a.proto \
examples/internal/proto/examplepb/openapi_merge_b.proto

EXAMPLES=examples/internal/proto/examplepb/echo_service.proto \
examples/internal/proto/examplepb/a_bit_of_everything.proto \
Expand All @@ -79,6 +81,7 @@ HELLOWORLD=examples/internal/helloworld/helloworld.proto
EXAMPLE_SVCSRCS=$(EXAMPLES:.proto=.pb.go)
EXAMPLE_GWSRCS=$(EXAMPLES:.proto=.pb.gw.go)
EXAMPLE_OPENAPISRCS=$(OPENAPI_EXAMPLES:.proto=.swagger.json)
EXAMPLE_OPENAPIMERGESRCS=examples/internal/proto/examplepb/openapi_merge.swagger.json
EXAMPLE_DEPS=examples/internal/proto/pathenum/path_enum.proto examples/internal/proto/sub/message.proto examples/internal/proto/sub2/message.proto
EXAMPLE_DEPSRCS=$(EXAMPLE_DEPS:.proto=.pb.go)

Expand Down Expand Up @@ -184,6 +187,9 @@ $(EXAMPLE_OPENAPISRCS): ADDITIONAL_SWG_FLAGS:=$(ADDITIONAL_SWG_FLAGS),grpc_api_c
$(EXAMPLE_OPENAPISRCS): $(OPENAPI_PLUGIN) $(OPENAPI_EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(OPENAPI_PLUGIN) --openapiv2_out=logtostderr=true,allow_repeated_fields_in_body=true,use_go_templates=true$(ADDITIONAL_SWG_FLAGS):. $(OPENAPI_EXAMPLES)

$(EXAMPLE_OPENAPIMERGESRCS): $(OPENAPI_PLUGIN) $(OPENAPIMERGE_EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(OPENAPI_PLUGIN) --openapiv2_out=logtostderr=true,allow_repeated_fields_in_body=true,use_go_templates=true,allow_merge=true,merge_file_name=$(EXAMPLE_OPENAPIMERGESRCS:.swagger.json=):. $(OPENAPIMERGE_EXAMPLES)

$(HELLOWORLD_SVCSRCS): $(GO_PLUGIN) $(GO_GRPC_PLUGIN) $(HELLOWORLD)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --plugin=$(GO_GRPC_PLUGIN) --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. $(HELLOWORLD)

Expand Down Expand Up @@ -213,7 +219,7 @@ $(RESPONSE_BODY_EXAMPLE_SRCS): $(RESPONSE_BODY_EXAMPLE_SPEC)
@rm -f $(EXAMPLE_CLIENT_DIR)/responsebody/README.md \
$(EXAMPLE_CLIENT_DIR)/responsebody/git_push.sh

examples: $(EXAMPLE_DEPSRCS) $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_OPENAPISRCS) $(EXAMPLE_CLIENT_SRCS) $(HELLOWORLD_SVCSRCS) $(HELLOWORLD_GWSRCS)
examples: $(EXAMPLE_DEPSRCS) $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_OPENAPISRCS) $(EXAMPLE_OPENAPIMERGESRCS) $(EXAMPLE_CLIENT_SRCS) $(HELLOWORLD_SVCSRCS) $(HELLOWORLD_GWSRCS)
testproto: $(RUNTIME_TEST_SRCS) $(APICONFIG_SRCS)
test: examples testproto
go test -short -race ./...
Expand Down
21 changes: 21 additions & 0 deletions examples/internal/proto/examplepb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ package(default_visibility = ["//visibility:public"])
# gazelle:exclude wrappers_grpc.pb.go
# gazelle:exclude unannotated_echo_service.pb.gw.go
# gazelle:exclude unannotated_echo_service_grpc.pb.go
# gazelle:exclude openapi_merge_a.proto
# gazelle:exclude openapi_merge_b.proto
# gazelle:go_grpc_compilers //:go_apiv2, //:go_grpc, //protoc-gen-grpc-gateway:go_gen_grpc_gateway

genrule(
Expand Down Expand Up @@ -64,6 +66,19 @@ proto_library(
],
)

#keep
proto_library(
name = "openapi_merge_proto",
srcs = [
"openapi_merge_a.proto",
"openapi_merge_b.proto",
],
deps = [
"@go_googleapis//google/api:annotations_proto",
"@go_googleapis//google/api:httpbody_proto",
],
)

go_proto_library(
name = "examplepb_go_proto",
compilers = [
Expand Down Expand Up @@ -101,3 +116,9 @@ protoc_gen_openapiv2(
proto = ":examplepb_proto",
single_output = True, # Outputs a single swagger.json file.
)

protoc_gen_openapiv2(
name = "examplepb_openapi_merge",
proto = ":openapi_merge_proto",
single_output = True, # Outputs a single swagger.json file.
)
308 changes: 308 additions & 0 deletions examples/internal/proto/examplepb/openapi_merge.swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
{
"swagger": "2.0",
"info": {
"title": "Merging Services",
"description": "This is an example of merging two proto files.",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/v1/example/a/1": {
"post": {
"summary": "ServiceA.MethodOne receives InMessageA and returns OutMessageA",
"description": "Here is the detail explanation about ServiceA.MethodOne.",
"operationId": "ServiceA_MethodOne",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbOutMessageA"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbInMessageA"
}
}
],
"tags": [
"ServiceA"
]
}
},
"/v1/example/a/2": {
"post": {
"summary": "ServiceA.MethodTwo receives OutMessageA and returns InMessageA",
"description": "Here is the detail explanation about ServiceA.MethodTwo.",
"operationId": "ServiceA_MethodTwo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbInMessageA"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbOutMessageA"
}
}
],
"tags": [
"ServiceA"
]
}
},
"/v1/example/b/1": {
"post": {
"summary": "ServiceB.MethodOne receives InMessageB and returns OutMessageB",
"description": "Here is the detail explanation about ServiceB.MethodOne.",
"operationId": "ServiceB_MethodOne",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbOutMessageB"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbInMessageB"
}
}
],
"tags": [
"ServiceB"
]
}
},
"/v1/example/b/2": {
"post": {
"summary": "ServiceB.MethodTwo receives OutMessageB and returns InMessageB",
"description": "Here is the detail explanation about ServiceB.MethodTwo.",
"operationId": "ServiceB_MethodTwo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbInMessageB"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbOutMessageB"
}
}
],
"tags": [
"ServiceB"
]
}
},
"/v1/example/c/1": {
"post": {
"summary": "ServiceC.MethodOne receives InMessageA and returns OutMessageC",
"description": "Here is the detail explanation about ServiceC.MethodOne.",
"operationId": "ServiceC_MethodOne",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbOutMessageC"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbInMessageA"
}
}
],
"tags": [
"ServiceC"
]
}
},
"/v1/example/c/2": {
"post": {
"summary": "ServiceC.MethodTwo receives OutMessageA and returns InMessageA",
"description": "Here is the detail explanation about ServiceC.MethodTwo.",
"operationId": "ServiceC_MethodTwo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbInMessageA"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbOutMessageA"
}
}
],
"tags": [
"ServiceC"
]
}
}
},
"definitions": {
"examplepbInMessageA": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "string"
},
"title": "Here is the explanation about InMessageA.values"
}
},
"description": "InMessageA represents a message to ServiceA and ServiceC."
},
"examplepbInMessageB": {
"type": "object",
"properties": {
"value": {
"type": "string",
"title": "Here is the explanation about InMessageB.values"
}
},
"description": "InMessageB represents a message to ServiceB."
},
"examplepbOutMessageA": {
"type": "object",
"properties": {
"value": {
"type": "string",
"title": "Here is the explanation about OutMessageA.value"
}
},
"description": "OutMessageA represents a message returned from ServiceA."
},
"examplepbOutMessageB": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "string"
},
"title": "Here is the explanation about OutMessageB.value"
}
},
"description": "OutMessageB represents a message returned from ServiceB."
},
"examplepbOutMessageC": {
"type": "object",
"properties": {
"value": {
"type": "string",
"title": "Here is the explanation about OutMessageC.value"
}
},
"description": "OutMessageC represents a message returned from ServiceC."
},
"protobufAny": {
"type": "object",
"properties": {
"typeUrl": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"rpcStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
}
}
}
Loading