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

Swagger dot in path template #148

Merged
merged 2 commits into from
May 9, 2016
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
188 changes: 117 additions & 71 deletions examples/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions examples/examplepb/a_bit_of_everything.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "google/api/annotations.proto";
import "examples/sub/message.proto";
import "examples/sub2/message.proto";

// Intentionaly complicated message type to cover much features of Protobuf.
// NEXT ID: 26
message ABitOfEverything {
message Nested {
string name = 1;
Expand All @@ -16,6 +18,7 @@ message ABitOfEverything {
}
DeepEnum ok = 3;
}
Nested single_nested = 25;

string uuid = 1;
repeated Nested nested = 2;
Expand Down Expand Up @@ -112,4 +115,10 @@ service ABitOfEverythingService {
body: "*"
};
}
rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything/{single_nested.name}"
body: "*"
};
}
}
9 changes: 9 additions & 0 deletions examples/examplepb/streamless_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package gengo.grpc.gateway.examples.examplepb;
import "google/api/annotations.proto";
import "examples/sub/message.proto";

// Intentionaly complicated message type to cover much features of Protobuf.
// NEXT ID: 26
message ABitOfEverything {
message Nested {
string name = 1;
Expand All @@ -15,6 +17,7 @@ message ABitOfEverything {
}
DeepEnum ok = 3;
}
Nested single_nested = 25;

string uuid = 1;
repeated Nested nested = 2;
Expand Down Expand Up @@ -115,4 +118,10 @@ service ABitOfEverythingService {
body: "*"
};
}
rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything/{single_nested.name}"
body: "*"
};
}
}
37 changes: 37 additions & 0 deletions examples/examplepb/streamless_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,40 @@
]
}
},
"/v1/example/a_bit_of_everything/{single_nested.name}": {
"post": {
"summary": "ABitOfEverythingService.DeepPathEcho",
"operationId": "DeepPathEcho",
"responses": {
"default": {
"description": "Description",
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
}
},
"parameters": [
{
"name": "single_nested.name",
"in": "path",
"required": true,
"type": "string",
"format": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbABitOfEverything"
}
}
],
"tags": [
"ABitOfEverythingService"
]
}
},
"/v1/example/a_bit_of_everything/{uuid}": {
"get": {
"summary": "ABitOfEverythingService.Lookup",
Expand Down Expand Up @@ -443,6 +477,9 @@
"type": "integer",
"format": "int32"
},
"single_nested": {
"$ref": "#/definitions/ABitOfEverythingNested"
},
"sint32_value": {
"type": "integer",
"format": "int32"
Expand Down
8 changes: 8 additions & 0 deletions examples/server/a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,11 @@ func (s *_ABitOfEverythingServer) BulkEcho(stream examples.ABitOfEverythingServi
}))
return nil
}

func (s *_ABitOfEverythingServer) DeepPathEcho(ctx context.Context, msg *examples.ABitOfEverything) (*examples.ABitOfEverything, error) {
s.m.Lock()
defer s.m.Unlock()

glog.Info(msg)
return msg, nil
}
2 changes: 1 addition & 1 deletion protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func templateToSwaggerPath(path string) string {
// Parts is now an array of segments of the path. Interestingly, since the
// syntax for this subsection CAN be handled by a regexp since it has no
// memory.
re := regexp.MustCompile("{([a-z][a-z0-9_]*).*}")
re := regexp.MustCompile("{([a-z][a-z0-9_.]*).*}")
for index, part := range parts {
parts[index] = re.ReplaceAllString(part, "{$1}")
}
Expand Down