-
Notifications
You must be signed in to change notification settings - Fork 11
EN.03.10.01.Protocol Buffers
Protocol Buffers is serialization format developed by Google. In Protocol Buffers, defines data structure by proto file.
On Aeromock, you've only have to make data file related to proto file and it respond binary response of Protocol Buffers. However, protobuf mode cannot coexist template mode.
When configure protobuf
and data
section at project.yaml, be able to respond to binary data of Protocol Buffers.
Root directory of proto file. Specify a relative path from project root path.
protobuf:
root: ./protobuf
In the case of sub directory under root directory is exist, no need request url with /api by defining apiPrefix
.
protobuf:
root: ./protobuf
apiPrefix: /api
Root directory of proto data file. Specify a relative path from project root path.
protobuf:
root: ./protobuf
apiPrefix: /api
data:
root: ./data
Locate proto file and data file at same hierarchy.
proto_root/path1/test.proto -> data_root/path1/test.yaml
Specification of proto data file is the save as JSON API. In addition, there specialized specification on proto data file.
On the specification of Protocol Buffers, can define multiple messages at a proto file. That is, you need to specify message type be used as response message type in proto data file, by defining __type
in data file.
For example, there is a proto file such as the following.
package protobuf.api;
import "schema/user.proto";
message TestRequest {
required int32 prop1 = 1;
required string prop2 = 2;
}
message TestResponse {
required int32 prop1 = 1;
required string prop2 = 2;
required int64 prop3 = 3;
repeated string prop4 = 4;
required schema.TestUser prop5 = 5;
optional int64 prop6 = 6 [default = 1];
}
If you use TestResponse
as response message type, describe data file as the following.
__type: TestResponse
prop1: 100
prop2: prop2value
prop3: 11111111111
prop4:
- "1111"
- "2222"
- "3333"
prop5:
id: 1000
name: testuser