Skip to content

Commit

Permalink
Create streamless example service.
Browse files Browse the repository at this point in the history
Also does a major refactor. This changes the way that Messages are
discovered and breaks the generation step down from a monoloithic task
into a much easier to test set. Also parses paths and adjusts them so
that they match what swagger expects.
  • Loading branch information
achew22 committed Dec 28, 2015
1 parent 66886e9 commit 524e235
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 160 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ OPTIONS_PROTO=$(GOOGLEAPIS_DIR)/google/api/annotations.proto $(GOOGLEAPIS_DIR)/g
OPTIONS_GO=$(OPTIONS_PROTO:.proto=.pb.go)

PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mgoogle/api/annotations.proto=$(PKG)/$(GOOGLEAPIS_DIR)/google/api,Mexamples/sub/message.proto=$(PKG)/examples/sub
SWAGGER_EXAMPLES=examples/examplepb/echo_service.proto
SWAGGER_EXAMPLES=examples/examplepb/echo_service.proto \
examples/examplepb/streamless_everything.proto
EXAMPLES=examples/examplepb/echo_service.proto \
examples/examplepb/a_bit_of_everything.proto \
examples/examplepb/flow_combination.proto
Expand Down
50 changes: 32 additions & 18 deletions examples/examplepb/echo_service.swagger.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"swagger": "2.0",
"info": {},
"info": {
"version": "",
"title": ""
},
"schemes": [
"http",
"https"
Expand All @@ -13,42 +16,53 @@
],
"paths": {
"/v1/example/echo/{id}": {
"get": {
"summary": "",
"response": null
},
"post": {
"summary": "Generated for EchoService.Echo - ",
"response": {
"summary": "EchoService.Echo",
"responses": {
"default": {
"description": "Description",
"schema": {
"$ref": "#/definitions/SimpleMessage"
"$ref": "#/definitions/.gengo.grpc.gateway.examples.examplepb.SimpleMessage"
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
"format": "string"
}
]
}
},
"/v1/example/echo_body": {
"get": {
"summary": "",
"response": null
},
"post": {
"summary": "Generated for EchoService.EchoBody - ",
"response": {
"summary": "EchoService.EchoBody",
"responses": {
"default": {
"description": "Description",
"schema": {
"$ref": "#/definitions/SimpleMessage"
"$ref": "#/definitions/.gengo.grpc.gateway.examples.examplepb.SimpleMessage"
}
}
}
},
"parameters": [
{
"name": "",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/.gengo.grpc.gateway.examples.examplepb.SimpleMessage"
}
}
]
}
}
},
"definitions": {
"SimpleMessage": {
".gengo.grpc.gateway.examples.examplepb.SimpleMessage": {
"properties": {
"id": {
"type": "string",
Expand Down
99 changes: 99 additions & 0 deletions examples/examplepb/streamless_everything.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
syntax = "proto3";
option go_package = "examplepb";
package gengo.grpc.gateway.examples.examplepb;

import "google/api/annotations.proto";
import "examples/sub/message.proto";

message ABitOfEverything {
message Nested {
string name = 1;
uint32 amount = 2;
}

string uuid = 1;
repeated Nested nested = 2;
float float_value = 3;
double double_value = 4;
int64 int64_value = 5;
uint64 uint64_value = 6;
int32 int32_value = 7;
fixed64 fixed64_value = 8;
fixed32 fixed32_value = 9;
bool bool_value = 10;
string string_value = 11;
// TODO(yugui) add bytes_value
uint32 uint32_value = 13;
// TODO(yugui) add enum_value
sfixed32 sfixed32_value = 15;
sfixed64 sfixed64_value = 16;
sint32 sint32_value = 17;
sint64 sint64_value = 18;
}

message EmptyMessage {
}

message IdMessage {
string uuid = 1;
}

service ABitOfEverythingService {
rpc Create(ABitOfEverything) returns (ABitOfEverything) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value=strprefix/*}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}"
};
}
rpc CreateBody(ABitOfEverything) returns (ABitOfEverything) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything"
body: "*"
};
}
// TODO: Refering to an empty message breaks the swagger editor right now. Tracking bug: https://github.com/swagger-api/swagger-spec/issues/452
//rpc BulkCreate(ABitOfEverything) returns (EmptyMessage) {
// option (google.api.http) = {
// post: "/v1/example/a_bit_of_everything/bulk"
// body: "*"
// };
//}
rpc Lookup(IdMessage) returns (ABitOfEverything) {
option (google.api.http) = {
get: "/v1/example/a_bit_of_everything/{uuid}"
};
}
rpc List(EmptyMessage) returns (ABitOfEverything) {
option (google.api.http) = {
get: "/v1/example/a_bit_of_everything"
};
}
rpc Update(ABitOfEverything) returns (EmptyMessage) {
option (google.api.http) = {
put: "/v1/example/a_bit_of_everything/{uuid}"
body: "*"
};
}
rpc Delete(IdMessage) returns (EmptyMessage) {
option (google.api.http) = {
delete: "/v1/example/a_bit_of_everything/{uuid}"
};
}
rpc Echo(gengo.grpc.gateway.examples.sub.StringMessage) returns (gengo.grpc.gateway.examples.sub.StringMessage) {
option (google.api.http) = {
get: "/v1/example/a_bit_of_everything/echo/{value}"
//additional_bindings {
// post: "/v2/example/echo"
// body: "value"
//}
//additional_bindings {
// get: "/v2/example/echo"
//}
};
}
rpc BulkEcho(gengo.grpc.gateway.examples.sub.StringMessage) returns (gengo.grpc.gateway.examples.sub.StringMessage) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything/echo"
body: "*"
};
}
}
Loading

0 comments on commit 524e235

Please sign in to comment.