protobufjs 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +2 -1
- package/README.md +144 -22
- package/bin/pbjs +2 -2
- package/bower.json +2 -2
- package/cli/pbjs/targets/amd.js +1 -1
- package/cli/pbjs/targets/json.js +8 -0
- package/cli/pbjs/util.js +1 -1
- package/cli/pbjs.js +1 -1
- package/dist/protobuf-light.js +166 -128
- package/dist/protobuf-light.min.js +88 -81
- package/dist/protobuf-light.min.js.gz +0 -0
- package/dist/protobuf-light.min.map +4 -4
- package/dist/protobuf.js +171 -129
- package/dist/protobuf.min.js +106 -98
- package/dist/protobuf.min.js.gz +0 -0
- package/dist/protobuf.min.map +4 -4
- package/docs/ProtoBuf.Builder.Message.html +1408 -971
- package/docs/ProtoBuf.Builder.Service.html +266 -197
- package/docs/ProtoBuf.Builder.html +758 -542
- package/docs/ProtoBuf.DotProto.Parser.html +223 -161
- package/docs/ProtoBuf.DotProto.Tokenizer.html +344 -248
- package/docs/ProtoBuf.DotProto.html +20 -12
- package/docs/ProtoBuf.Element.html +554 -554
- package/docs/ProtoBuf.Map.html +158 -123
- package/docs/ProtoBuf.Reflect.Element.html +286 -143
- package/docs/ProtoBuf.Reflect.Enum.Value.html +329 -228
- package/docs/ProtoBuf.Reflect.Enum.html +757 -537
- package/docs/ProtoBuf.Reflect.Extension.html +73 -56
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +1013 -740
- package/docs/ProtoBuf.Reflect.Message.Field.html +926 -649
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +327 -245
- package/docs/ProtoBuf.Reflect.Message.html +915 -651
- package/docs/ProtoBuf.Reflect.Namespace.html +648 -447
- package/docs/ProtoBuf.Reflect.Service.Method.html +363 -251
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +545 -397
- package/docs/ProtoBuf.Reflect.Service.html +721 -511
- package/docs/ProtoBuf.Reflect.T.html +268 -197
- package/docs/ProtoBuf.Reflect.html +20 -12
- package/docs/ProtoBuf.Util.html +169 -118
- package/docs/ProtoBuf.html +840 -628
- package/docs/ProtoBuf.js.html +177 -134
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/index.html +7 -5
- package/docs/styles/jsdoc-default.css +95 -75
- package/docs/styles/prettify-tomorrow.css +1 -1
- package/examples/protoify/json.js +123 -123
- package/examples/protoify/json.json +123 -123
- package/examples/websocket/server.js +4 -4
- package/externs/protobuf.js +1 -1
- package/jsdoc.json +1 -1
- package/package.json +2 -2
- package/scripts/build.js +53 -53
- package/src/ProtoBuf/Builder/Message.js +9 -5
- package/src/ProtoBuf/Builder.js +19 -2
- package/src/ProtoBuf/DotProto/Parser.js +5 -1
- package/src/ProtoBuf/Reflect/Element.js +13 -1
- package/src/ProtoBuf/Reflect/Message/Field.js +2 -2
- package/src/ProtoBuf/Reflect/Message.js +6 -1
- package/src/ProtoBuf/Util.js +116 -116
- package/src/bower.json +1 -1
- package/src/google/protobuf/descriptor.json +27 -1
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -1
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/imports.json +83 -83
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/options.json +32 -32
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +43 -1
- package/sandbox/gapi/googleapis/google/api/annotations.proto +0 -29
- package/sandbox/gapi/googleapis/google/api/http.proto +0 -245
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/datastore.proto +0 -281
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/entity.proto +0 -189
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/query.proto +0 -281
- package/sandbox/gapi/googleapis/google/longrunning/operations.proto +0 -144
- package/sandbox/gapi/googleapis/google/protobuf/any.proto +0 -98
- package/sandbox/gapi/googleapis/google/protobuf/any_test.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/api.proto +0 -201
- package/sandbox/gapi/googleapis/google/protobuf/descriptor.proto +0 -773
- package/sandbox/gapi/googleapis/google/protobuf/duration.proto +0 -95
- package/sandbox/gapi/googleapis/google/protobuf/empty.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/field_mask.proto +0 -167
- package/sandbox/gapi/googleapis/google/protobuf/map_lite_unittest.proto +0 -130
- package/sandbox/gapi/googleapis/google/protobuf/map_proto2_unittest.proto +0 -60
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest.proto +0 -129
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest_proto3.proto +0 -120
- package/sandbox/gapi/googleapis/google/protobuf/source_context.proto +0 -47
- package/sandbox/gapi/googleapis/google/protobuf/struct.proto +0 -94
- package/sandbox/gapi/googleapis/google/protobuf/timestamp.proto +0 -107
- package/sandbox/gapi/googleapis/google/protobuf/type.proto +0 -176
- package/sandbox/gapi/googleapis/google/protobuf/unittest.proto +0 -878
- package/sandbox/gapi/googleapis/google/protobuf/unittest_arena.proto +0 -46
- package/sandbox/gapi/googleapis/google/protobuf/unittest_custom_options.proto +0 -394
- package/sandbox/gapi/googleapis/google/protobuf/unittest_drop_unknown_fields.proto +0 -58
- package/sandbox/gapi/googleapis/google/protobuf/unittest_embed_optimize_for.proto +0 -51
- package/sandbox/gapi/googleapis/google/protobuf/unittest_empty.proto +0 -38
- package/sandbox/gapi/googleapis/google/protobuf/unittest_enormous_descriptor.proto +0 -1048
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import.proto +0 -66
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_lite.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_proto3.proto +0 -68
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_lite.proto +0 -43
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_proto3.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite.proto +0 -385
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite_imports_nonlite.proto +0 -44
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset.proto +0 -82
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset_wire_format.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena.proto +0 -202
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_import.proto +0 -37
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_lite.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_field_presence.proto +0 -138
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_generic_services.proto +0 -54
- package/sandbox/gapi/googleapis/google/protobuf/unittest_optimize_for.proto +0 -67
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum.proto +0 -71
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum2.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3.proto +0 -388
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3_arena.proto +0 -206
- package/sandbox/gapi/googleapis/google/protobuf/unittest_well_known_types.proto +0 -112
- package/sandbox/gapi/googleapis/google/protobuf/unknown_enum_test.proto +0 -62
- package/sandbox/gapi/googleapis/google/protobuf/wrappers.proto +0 -117
- package/sandbox/gapi/googleapis/google/rpc/code.proto +0 -190
- package/sandbox/gapi/googleapis/google/rpc/error_details.proto +0 -157
- package/sandbox/gapi/googleapis/google/rpc/status.proto +0 -90
- package/sandbox/gapi/googleapis/google/type/color.proto +0 -163
- package/sandbox/gapi/googleapis/google/type/date.proto +0 -43
- package/sandbox/gapi/googleapis/google/type/dayofweek.proto +0 -50
- package/sandbox/gapi/googleapis/google/type/latlng.proto +0 -36
- package/sandbox/gapi/googleapis/google/type/money.proto +0 -40
- package/sandbox/gapi/googleapis/google/type/timeofday.proto +0 -42
- package/sandbox/gapi/test.js +0 -17
- package/sandbox/gapi/test.proto +0 -12
- package/sandbox/issue146/MyOptions.proto +0 -28
- package/sandbox/issue146/Sample.proto +0 -21
- package/sandbox/issue146/main.js +0 -3
- package/sandbox/issue147/enum.proto +0 -8
- package/sandbox/issue147/main.js +0 -3
- package/sandbox/issue182/commands.proto +0 -10
- package/sandbox/issue182/execute.js +0 -22
- package/sandbox/issue182/session_commands.proto +0 -14
- package/sandbox/issue289/A.proto +0 -8
- package/sandbox/issue289/B.proto +0 -8
- package/sandbox/issue289/common.proto +0 -5
- package/sandbox/issue289/main.js +0 -7
- package/sandbox/issue300/IAuth.proto +0 -14
- package/sandbox/issue300/Request.proto +0 -14
- package/sandbox/issue300/main.js +0 -26
- package/sandbox/issue347/index.js +0 -27
- package/sandbox/issue355/main.proto +0 -15
- package/sandbox/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
package/tests/options.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"package": "My",
|
|
3
|
-
"messages": [
|
|
4
|
-
{
|
|
5
|
-
"name": "Test",
|
|
6
|
-
"fields": [
|
|
7
|
-
{
|
|
8
|
-
"rule": "optional",
|
|
9
|
-
"options": {
|
|
10
|
-
"default": "Max"
|
|
11
|
-
},
|
|
12
|
-
"type": "string",
|
|
13
|
-
"name": "name",
|
|
14
|
-
"id": 1
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"enums": [],
|
|
18
|
-
"messages": [],
|
|
19
|
-
"options": {
|
|
20
|
-
"(inmessage)": "My.Test",
|
|
21
|
-
"(foo.my_option).bar": false
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"enums": [],
|
|
26
|
-
"imports": [],
|
|
27
|
-
"options": {
|
|
28
|
-
"(toplevel_1)": 10,
|
|
29
|
-
"(toplevel_2)": "Hello world!"
|
|
30
|
-
},
|
|
31
|
-
"services": []
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"package": "My",
|
|
3
|
+
"messages": [
|
|
4
|
+
{
|
|
5
|
+
"name": "Test",
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"rule": "optional",
|
|
9
|
+
"options": {
|
|
10
|
+
"default": "Max"
|
|
11
|
+
},
|
|
12
|
+
"type": "string",
|
|
13
|
+
"name": "name",
|
|
14
|
+
"id": 1
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"enums": [],
|
|
18
|
+
"messages": [],
|
|
19
|
+
"options": {
|
|
20
|
+
"(inmessage)": "My.Test",
|
|
21
|
+
"(foo.my_option).bar": false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"enums": [],
|
|
26
|
+
"imports": [],
|
|
27
|
+
"options": {
|
|
28
|
+
"(toplevel_1)": 10,
|
|
29
|
+
"(toplevel_2)": "Hello world!"
|
|
30
|
+
},
|
|
31
|
+
"services": []
|
|
32
|
+
}
|
package/tests/proto2js/Bar.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"package": null,
|
|
3
|
-
"messages": [
|
|
4
|
-
{
|
|
5
|
-
"ref": "Foo",
|
|
6
|
-
"fields": [
|
|
7
|
-
{
|
|
8
|
-
"rule": "required",
|
|
9
|
-
"type": "string",
|
|
10
|
-
"name": "buzz",
|
|
11
|
-
"id": 2,
|
|
12
|
-
"options": {}
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
],
|
|
17
|
-
"enums": [],
|
|
18
|
-
"imports": [
|
|
19
|
-
{
|
|
20
|
-
"package": null,
|
|
21
|
-
"messages": [
|
|
22
|
-
{
|
|
23
|
-
"name": "Foo",
|
|
24
|
-
"fields": [
|
|
25
|
-
{
|
|
26
|
-
"rule": "required",
|
|
27
|
-
"type": "string",
|
|
28
|
-
"name": "fizz",
|
|
29
|
-
"id": 1,
|
|
30
|
-
"options": {}
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
"enums": [],
|
|
34
|
-
"messages": [],
|
|
35
|
-
"options": {}
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"enums": [],
|
|
39
|
-
"imports": [],
|
|
40
|
-
"options": {},
|
|
41
|
-
"services": []
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
"options": {},
|
|
45
|
-
"services": []
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"package": null,
|
|
3
|
+
"messages": [
|
|
4
|
+
{
|
|
5
|
+
"ref": "Foo",
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"rule": "required",
|
|
9
|
+
"type": "string",
|
|
10
|
+
"name": "buzz",
|
|
11
|
+
"id": 2,
|
|
12
|
+
"options": {}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"enums": [],
|
|
18
|
+
"imports": [
|
|
19
|
+
{
|
|
20
|
+
"package": null,
|
|
21
|
+
"messages": [
|
|
22
|
+
{
|
|
23
|
+
"name": "Foo",
|
|
24
|
+
"fields": [
|
|
25
|
+
{
|
|
26
|
+
"rule": "required",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"name": "fizz",
|
|
29
|
+
"id": 1,
|
|
30
|
+
"options": {}
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"enums": [],
|
|
34
|
+
"messages": [],
|
|
35
|
+
"options": {}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"enums": [],
|
|
39
|
+
"imports": [],
|
|
40
|
+
"options": {},
|
|
41
|
+
"services": []
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"options": {},
|
|
45
|
+
"services": []
|
|
46
|
+
}
|
package/tests/suite.js
CHANGED
|
@@ -263,6 +263,36 @@
|
|
|
263
263
|
test.deepEqual(t2, t3);
|
|
264
264
|
test.done();
|
|
265
265
|
},
|
|
266
|
+
|
|
267
|
+
"constructorWithOneofs": function(test) {
|
|
268
|
+
try {
|
|
269
|
+
var builder = ProtoBuf.loadProtoFile(__dirname+"/oneof.proto"),
|
|
270
|
+
MyOneOf = builder.build("MyOneOf"),
|
|
271
|
+
TOneOf = builder.lookup(".MyOneOf");
|
|
272
|
+
test.ok(TOneOf.getChild("my_oneof"));
|
|
273
|
+
|
|
274
|
+
var myOneOf = new MyOneOf();
|
|
275
|
+
test.strictEqual(myOneOf.my_oneof, null);
|
|
276
|
+
myOneOf.set("id", 1);
|
|
277
|
+
test.strictEqual(myOneOf.my_oneof, "id");
|
|
278
|
+
myOneOf.set("name", "me");
|
|
279
|
+
test.strictEqual(myOneOf.my_oneof, "name");
|
|
280
|
+
test.strictEqual(myOneOf.id, null);
|
|
281
|
+
|
|
282
|
+
var copy = new MyOneOf(myOneOf); // this line is what was failing
|
|
283
|
+
// Error: .MyOneOf#my_oneof is not a field: undefined
|
|
284
|
+
|
|
285
|
+
test.deepEqual(myOneOf, copy);
|
|
286
|
+
|
|
287
|
+
// Test same things are there
|
|
288
|
+
test.strictEqual(copy.my_oneof, "name");
|
|
289
|
+
test.strictEqual(copy.name, "me");
|
|
290
|
+
test.strictEqual(copy.id, null);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
fail(e);
|
|
293
|
+
}
|
|
294
|
+
test.done();
|
|
295
|
+
},
|
|
266
296
|
|
|
267
297
|
"numberFormats": function(test) {
|
|
268
298
|
try {
|
|
@@ -396,7 +426,7 @@
|
|
|
396
426
|
try {
|
|
397
427
|
var builder = ProtoBuf.loadProto("message Image { required bytes data = 1; }"),
|
|
398
428
|
Image = builder.build("Image"),
|
|
399
|
-
data = fs.readFileSync(__dirname+"/../
|
|
429
|
+
data = fs.readFileSync(__dirname+"/../protobuf.png"),
|
|
400
430
|
image = new Image({ data: data }),
|
|
401
431
|
bb = image.encode(),
|
|
402
432
|
imageDec = Image.decode(bb),
|
|
@@ -674,6 +704,18 @@
|
|
|
674
704
|
test.done();
|
|
675
705
|
},
|
|
676
706
|
|
|
707
|
+
// Test error messages
|
|
708
|
+
"errorMessage": function(test) {
|
|
709
|
+
test.throws(function() {
|
|
710
|
+
var builder = ProtoBuf.loadJsonFile(__dirname+"/complex.json");
|
|
711
|
+
var Game = builder.build("Game");
|
|
712
|
+
var car = new Game.Cars.Car();
|
|
713
|
+
car.speed = "hello";
|
|
714
|
+
car.encode();
|
|
715
|
+
}, /Illegal value for speed/);
|
|
716
|
+
test.done();
|
|
717
|
+
},
|
|
718
|
+
|
|
677
719
|
// Builder reused to add definitions from multiple sources
|
|
678
720
|
"multiBuilder": function(test) {
|
|
679
721
|
try {
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015, Google Inc.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
syntax = "proto3";
|
|
16
|
-
|
|
17
|
-
package google.api;
|
|
18
|
-
|
|
19
|
-
import "google/api/http.proto";
|
|
20
|
-
import "google/protobuf/descriptor.proto";
|
|
21
|
-
|
|
22
|
-
option java_multiple_files = true;
|
|
23
|
-
option java_outer_classname = "AnnotationsProto";
|
|
24
|
-
option java_package = "com.google.api";
|
|
25
|
-
|
|
26
|
-
extend google.protobuf.MethodOptions {
|
|
27
|
-
// See `HttpRule`.
|
|
28
|
-
HttpRule http = 72295728;
|
|
29
|
-
}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2015, Google Inc.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
syntax = "proto3";
|
|
16
|
-
|
|
17
|
-
package google.api;
|
|
18
|
-
|
|
19
|
-
option java_multiple_files = true;
|
|
20
|
-
option java_outer_classname = "HttpProto";
|
|
21
|
-
option java_package = "com.google.api";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// `HttpRule` defines the mapping of an RPC method to one or more HTTP
|
|
25
|
-
// REST APIs. The mapping determines what portions of the request
|
|
26
|
-
// message are populated from the path, query parameters, or body of
|
|
27
|
-
// the HTTP request. The mapping is typically specified as an
|
|
28
|
-
// `google.api.http` annotation, see "google/api/annotations.proto"
|
|
29
|
-
// for details.
|
|
30
|
-
//
|
|
31
|
-
// The mapping consists of a field specifying the path template and
|
|
32
|
-
// method kind. The path template can refer to fields in the request
|
|
33
|
-
// message, as in the example below which describes a REST GET
|
|
34
|
-
// operation on a resource collection of messages:
|
|
35
|
-
//
|
|
36
|
-
// ```proto
|
|
37
|
-
// service Messaging {
|
|
38
|
-
// rpc GetMessage(GetMessageRequest) returns (Message) {
|
|
39
|
-
// option (google.api.http).get = "/v1/messages/{message_id}";
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
// message GetMessageRequest {
|
|
43
|
-
// string message_id = 1; // mapped to the URL
|
|
44
|
-
// }
|
|
45
|
-
// message Message {
|
|
46
|
-
// string text = 1; // content of the resource
|
|
47
|
-
// }
|
|
48
|
-
// ```
|
|
49
|
-
//
|
|
50
|
-
// This definition enables an automatic, bidrectional mapping of HTTP
|
|
51
|
-
// JSON to RPC. Example:
|
|
52
|
-
//
|
|
53
|
-
// HTTP | RPC
|
|
54
|
-
// -----|-----
|
|
55
|
-
// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
|
|
56
|
-
//
|
|
57
|
-
// In general, not only fields but also field paths can be referenced
|
|
58
|
-
// from a path pattern. Fields mapped to the path pattern cannot be
|
|
59
|
-
// repeated and must have a primitive (non-message) type.
|
|
60
|
-
//
|
|
61
|
-
// Any fields in the request message which are not bound by the path
|
|
62
|
-
// pattern automatically become (optional) HTTP query
|
|
63
|
-
// parameters. Assume the following definition of the request message:
|
|
64
|
-
//
|
|
65
|
-
// ```proto
|
|
66
|
-
// message GetMessageRequest {
|
|
67
|
-
// string message_id = 1; // mapped to the URL
|
|
68
|
-
// int64 revision = 2; // becomes a parameter
|
|
69
|
-
// }
|
|
70
|
-
// ```
|
|
71
|
-
//
|
|
72
|
-
// This enables a HTTP JSON to RPC mapping as below:
|
|
73
|
-
//
|
|
74
|
-
// HTTP | RPC
|
|
75
|
-
// -----|-----
|
|
76
|
-
// `GET /v1/messages/123456?revision=2` | `GetMessage(message_id: "123456" revision: 2)`
|
|
77
|
-
//
|
|
78
|
-
// Note that fields which are mapped to HTTP parameters must have a
|
|
79
|
-
// primitive type or a repeated primitive type. Message types are not
|
|
80
|
-
// allowed. In the case of a repeated type, the parameter can be
|
|
81
|
-
// repeated in the URL, as in `...?param=A¶m=B`.
|
|
82
|
-
//
|
|
83
|
-
// For HTTP method kinds which allow a request body, the `body` field
|
|
84
|
-
// specifies the mapping. Consider a REST update method on the
|
|
85
|
-
// message resource collection:
|
|
86
|
-
//
|
|
87
|
-
// ```proto
|
|
88
|
-
// service Messaging {
|
|
89
|
-
// rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
|
|
90
|
-
// option (google.api.http) = {
|
|
91
|
-
// put: "/v1/messages/{message_id}"
|
|
92
|
-
// body: "message"
|
|
93
|
-
// }
|
|
94
|
-
// }
|
|
95
|
-
// message UpdateMessageRequest {
|
|
96
|
-
// string message_id = 1; // mapped to the URL
|
|
97
|
-
// Message message = 2; // mapped to the body
|
|
98
|
-
// }
|
|
99
|
-
// ```
|
|
100
|
-
//
|
|
101
|
-
// The following HTTP JSON to RPC mapping is enabled, where the
|
|
102
|
-
// representation of the JSON in the request body is determined by
|
|
103
|
-
// protos JSON encoding:
|
|
104
|
-
//
|
|
105
|
-
// HTTP | RPC
|
|
106
|
-
// -----|-----
|
|
107
|
-
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })`
|
|
108
|
-
//
|
|
109
|
-
// The special name `*` can be used in the body mapping to define that
|
|
110
|
-
// every field not bound by the path template should be mapped to the
|
|
111
|
-
// request body. This enables the following alternative definition of
|
|
112
|
-
// the update method:
|
|
113
|
-
//
|
|
114
|
-
// ```proto
|
|
115
|
-
// service Messaging {
|
|
116
|
-
// rpc UpdateMessage(Message) returns (Message) {
|
|
117
|
-
// option (google.api.http) = {
|
|
118
|
-
// put: "/v1/messages/{message_id}"
|
|
119
|
-
// body: "*"
|
|
120
|
-
// }
|
|
121
|
-
// }
|
|
122
|
-
// message Message {
|
|
123
|
-
// string message_id = 2;
|
|
124
|
-
// string text = 2;
|
|
125
|
-
// }
|
|
126
|
-
// ```
|
|
127
|
-
//
|
|
128
|
-
// The following HTTP JSON to RPC mapping is enabled:
|
|
129
|
-
//
|
|
130
|
-
// HTTP | RPC
|
|
131
|
-
// -----|-----
|
|
132
|
-
// `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
|
|
133
|
-
//
|
|
134
|
-
// Note that when using `*` in the body mapping, it is not possible to
|
|
135
|
-
// have HTTP parameters, as all fields not bound by the path end in
|
|
136
|
-
// the body. This makes this option more rarely used in practice of
|
|
137
|
-
// defining REST APIs. The common usage of `*` is in custom methods
|
|
138
|
-
// which don't use the URL at all for transferring data.
|
|
139
|
-
//
|
|
140
|
-
// It is possible to define multiple HTTP methods for one RPC by using
|
|
141
|
-
// the `additional_bindings` option. Example:
|
|
142
|
-
//
|
|
143
|
-
// ```proto
|
|
144
|
-
// service Messaging {
|
|
145
|
-
// rpc GetMessage(GetMessageRequest) returns (Message) {
|
|
146
|
-
// option (google.api.http) = {
|
|
147
|
-
// get: "/v1/messages/{message_id}"
|
|
148
|
-
// additional_bindings {
|
|
149
|
-
// get: "/v1/users/{user_id}/messages/{message_id}"
|
|
150
|
-
// }
|
|
151
|
-
// }
|
|
152
|
-
// }
|
|
153
|
-
// message GetMessageRequest {
|
|
154
|
-
// string message_id = 1;
|
|
155
|
-
// string user_id = 2;
|
|
156
|
-
// }
|
|
157
|
-
// ```
|
|
158
|
-
//
|
|
159
|
-
// This enables the following two alternative HTTP JSON to RPC
|
|
160
|
-
// mappings:
|
|
161
|
-
//
|
|
162
|
-
// HTTP | RPC
|
|
163
|
-
// -----|-----
|
|
164
|
-
// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
|
|
165
|
-
// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
|
|
166
|
-
//
|
|
167
|
-
// # Rules for HTTP mapping
|
|
168
|
-
// The rules for mapping HTTP path, query parameters, and body fields
|
|
169
|
-
// to the request message are as follows:
|
|
170
|
-
//
|
|
171
|
-
// 1. The `body` field specifies either `*` or a field path, or is
|
|
172
|
-
// omitted. If omitted, it assumes there is no HTTP body.
|
|
173
|
-
// 2. Leaf fields (recursive expansion of nested messages in the
|
|
174
|
-
// request) can be classified into three types:
|
|
175
|
-
// (a) Matched in the URL template.
|
|
176
|
-
// (b) Covered by body (if body is `*`, everything except (a) fields;
|
|
177
|
-
// else everything under the body field)
|
|
178
|
-
// (c) All other fields.
|
|
179
|
-
// 3. URL query parameters found in the HTTP request are mapped to (c) fields.
|
|
180
|
-
// 4. Any body sent with an HTTP request can contain only (b) fields.
|
|
181
|
-
//
|
|
182
|
-
// The syntax of the path template is as follows:
|
|
183
|
-
//
|
|
184
|
-
// Template = "/" Segments [ Verb ] ;
|
|
185
|
-
// Segments = Segment { "/" Segment } ;
|
|
186
|
-
// Segment = "*" | "**" | LITERAL | Variable ;
|
|
187
|
-
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
|
|
188
|
-
// FieldPath = IDENT { "." IDENT } ;
|
|
189
|
-
// Verb = ":" LITERAL ;
|
|
190
|
-
//
|
|
191
|
-
// `*` matches a single path component, `**` zero or more path components, and
|
|
192
|
-
// `LITERAL` a constant. A `Variable` can match an entire path as specified
|
|
193
|
-
// again by a template; this nested template must not contain further variables.
|
|
194
|
-
// If no template is given with a variable, it matches a single path component.
|
|
195
|
-
// The notation `{var}` is henceforth equivalent to `{var=*}`. NOTE: the field
|
|
196
|
-
// paths in variables and in the `body` must not refer to repeated fields.
|
|
197
|
-
//
|
|
198
|
-
// Use CustomHttpPattern to specify any HTTP method that is not included in the
|
|
199
|
-
// pattern field, such as HEAD, or "*" to leave the HTTP method unspecified for
|
|
200
|
-
// a given URL path rule. The wild-card rule is useful for services that provide
|
|
201
|
-
// content to Web (HTML) clients.
|
|
202
|
-
message HttpRule {
|
|
203
|
-
|
|
204
|
-
// Determines the URL pattern is matched by this rules. This pattern can be
|
|
205
|
-
// used with any of the {get|put|post|delete|patch} methods. A custom method
|
|
206
|
-
// can be defined using the 'custom' field.
|
|
207
|
-
oneof pattern {
|
|
208
|
-
// Used for listing and getting information about resources.
|
|
209
|
-
string get = 2;
|
|
210
|
-
|
|
211
|
-
// Used for updating a resource.
|
|
212
|
-
string put = 3;
|
|
213
|
-
|
|
214
|
-
// Used for creating a resource.
|
|
215
|
-
string post = 4;
|
|
216
|
-
|
|
217
|
-
// Used for deleting a resource.
|
|
218
|
-
string delete = 5;
|
|
219
|
-
|
|
220
|
-
// Used for updating a resource.
|
|
221
|
-
string patch = 6;
|
|
222
|
-
|
|
223
|
-
// Custom pattern is used for defining custom verbs.
|
|
224
|
-
CustomHttpPattern custom = 8;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// The name of the request field whose value is mapped to the HTTP body, or
|
|
228
|
-
// `*` for mapping all fields not captured by the path pattern to the HTTP
|
|
229
|
-
// body. NOTE: the referred field must not be a repeated field.
|
|
230
|
-
string body = 7;
|
|
231
|
-
|
|
232
|
-
// Additional HTTP bindings for the selector. Nested bindings must
|
|
233
|
-
// not contain an `additional_bindings` field themselves (that is,
|
|
234
|
-
// the nesting may only be one level deep).
|
|
235
|
-
repeated HttpRule additional_bindings = 11;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// A custom pattern is used for defining custom HTTP verb.
|
|
239
|
-
message CustomHttpPattern {
|
|
240
|
-
// The name of this custom HTTP verb.
|
|
241
|
-
string kind = 1;
|
|
242
|
-
|
|
243
|
-
// The path matched by this custom verb.
|
|
244
|
-
string path = 2;
|
|
245
|
-
}
|