Skip to content

Commit

Permalink
add an example for merged output
Browse files Browse the repository at this point in the history
  • Loading branch information
kentdotn committed Jun 7, 2020
1 parent cd05d23 commit 783c28f
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ SWAGGER_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
SWAGGER_EXAMPLE_MERGE=examples/internal/proto/examplepb/swagger_merge_a.proto \
examples/internal/proto/examplepb/swagger_merge_b.proto

EXAMPLES=examples/internal/proto/examplepb/echo_service.proto \
examples/internal/proto/examplepb/a_bit_of_everything.proto \
Expand All @@ -82,6 +84,7 @@ HELLOWORLD=examples/internal/helloworld/helloworld.proto
EXAMPLE_SVCSRCS=$(EXAMPLES:.proto=.pb.go)
EXAMPLE_GWSRCS=$(EXAMPLES:.proto=.pb.gw.go)
EXAMPLE_SWAGGERSRCS=$(SWAGGER_EXAMPLES:.proto=.swagger.json)
EXAMPLE_SWAGGER_MERGE=examples/internal/proto/examplepb/swagger_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 @@ -176,6 +179,9 @@ $(EXAMPLE_SWAGGERSRCS): ADDITIONAL_SWG_FLAGS:=$(ADDITIONAL_SWG_FLAGS),grpc_api_c
$(EXAMPLE_SWAGGERSRCS): $(SWAGGER_PLUGIN) $(SWAGGER_EXAMPLES)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(SWAGGER_PLUGIN) --swagger_out=logtostderr=true,allow_repeated_fields_in_body=true,use_go_templates=true,$(PKGMAP)$(ADDITIONAL_SWG_FLAGS):. $(SWAGGER_EXAMPLES)

$(EXAMPLE_SWAGGER_MERGE): $(SWAGGER_PLUGIN) $(SWAGGER_EXAMPLE_MERGE)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(SWAGGER_PLUGIN) --swagger_out=logtostderr=true,allow_repeated_fields_in_body=true,use_go_templates=true,allow_merge=true,merge_file_name=$(EXAMPLE_SWAGGER_MERGE:.swagger.json=),$(PKGMAP):. $(SWAGGER_EXAMPLE_MERGE)

$(HELLOWORLD_SVCSRCS): $(GO_PLUGIN) $(HELLOWORLD)
protoc -I $(PROTOC_INC_PATH) -I. -I$(GOOGLEAPIS_DIR) --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc,paths=source_relative:. $(HELLOWORLD)

Expand Down Expand Up @@ -205,7 +211,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_SWAGGERSRCS) $(EXAMPLE_CLIENT_SRCS) $(HELLOWORLD_SVCSRCS) $(HELLOWORLD_GWSRCS)
examples: $(EXAMPLE_DEPSRCS) $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_SWAGGERSRCS) $(EXAMPLE_SWAGGER_MERGE) $(EXAMPLE_CLIENT_SRCS) $(HELLOWORLD_SVCSRCS) $(HELLOWORLD_GWSRCS)
testproto: $(RUNTIME_TEST_SRCS)
test: examples testproto
go test -short -race ./...
Expand Down
311 changes: 311 additions & 0 deletions examples/internal/proto/examplepb/swagger_merge.swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
{
"swagger": "2.0",
"info": {
"title": "Merging Service",
"description": "Merging Service API provides (at least) one service that merges given values.",
"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/runtimeError"
}
}
},
"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/runtimeError"
}
}
},
"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 OutInMessageB",
"description": "Here is the detail explanation about ServiceB.MethodOne.",
"operationId": "ServiceB_MethodOne",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbOutInMessageB"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbInMessageB"
}
}
],
"tags": [
"ServiceB"
]
}
},
"/v1/example/b/2": {
"post": {
"summary": "ServiceB.MethodTwo receives OutInMessageB 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/runtimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbOutInMessageB"
}
}
],
"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/runtimeError"
}
}
},
"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/runtimeError"
}
}
},
"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",
"description": "value represents the divided value."
}
},
"description": "DivideMessage represents a message with values sent to the Divide service."
},
"examplepbOutInMessageB": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "string"
},
"description": "values represents the values to be divided."
}
},
"description": "DividedMessage represents a simple message with the divided value by the Divide service."
},
"examplepbOutMessageA": {
"type": "object",
"properties": {
"value": {
"type": "string",
"title": "Here is the explanation about OutMessageA.value"
}
},
"description": "OutMessageA represents a message returned from ServiceA."
},
"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": {
"type_url": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"runtimeError": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
}
}
}
Loading

0 comments on commit 783c28f

Please sign in to comment.