Skip to content

Commit

Permalink
Merge pull request #148 from gengo/swagger_dot_in_path_template
Browse files Browse the repository at this point in the history
Swagger dot in path template
  • Loading branch information
yugui committed May 9, 2016
2 parents 8205819 + 6087747 commit 1d571c7
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 72 deletions.
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

0 comments on commit 1d571c7

Please sign in to comment.