-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmessage.proto
149 lines (117 loc) · 4.65 KB
/
message.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
syntax = "proto3";
package svc.example;
option (transformer.go_repo_package) = "model";
option (transformer.go_protobuf_package) = "example";
option (transformer.go_models_file_path) = "example/model/model.go";
option go_package = "example"; // Package name for pb.go
import "options/annotations.proto";
import "[email protected]/gogoproto/gogo.proto"; // for gogoproto options
import "google/protobuf/timestamp.proto";
message TheOne{
oneof the_decl {
string string_value = 1;
int64 int64_value = 2;
}
}
message NotSupportedOneOf{
oneof the_decl {
bool bool_value = 1;
string string_value = 2;
}
}
message CustomOneof{
oneof value {
string string_value = 1;
int64 int64_value = 2;
}
}
message CustomType{
string value = 1;
}
message Product {
option (transformer.go_struct) = "Product";
int32 id = 1;
string name = 2;
TheOne one = 3;
TheOne second_id = 4;
// Example of the custom transformer for the struct
CustomType custom_field = 5 [(transformer.custom) = true];
// Example of the custom transformer for the struct with oneof type in it
CustomOneof custom_oneof = 6 [(transformer.custom) = true];
// Currently the plugin does not support oneof types
// rather than the specific example with `int64_value` and `string_value`
// In current implementation it generates the PbToPtrVal and ToPbValPtr
// TODO: change these method names to include either field name or field type to it
// Changing method names will break backward compatibility with previous versions of the plugin
NotSupportedOneOf notsupported_oneof = 7;
}
message Order {
option (transformer.go_struct) = "Order";
int64 id = 1;
TheOne first_id = 2;
TheOne second_id = 3;
TheOne third_url = 4;
}
message Address {
option (transformer.go_struct) = "Address";
int64 id = 1;
string type = 2;
}
message Customer {
option (transformer.go_struct) = "Customer";
int64 id = 1;
string name = 2;
repeated Address addresses = 3;
Address default_address = 4;
Address billing_address = 5 [ (gogoproto.nullable) = false ];
string map_field_1 = 6 [
(transformer.map_as) = "MapField_1",
(transformer.map_to) = "MapField1"
];
string map_field_to_without_digits = 7 [ (transformer.map_to) = "MapField2" ];
}
// opposite message order, usage of LineItem is earlier than message is defined.
message LineItemUsage {
option (transformer.go_struct) = "MyLineItemUsage";
LineItem Item = 1;
repeated LineItem List = 2;
}
message LineItem {
option (transformer.go_struct) = "MyLineItem";
// Capitalized ID. It's not by protobuf style guide, but supported too.
int64 ID = 1; // ID-> ID, iD -> ID, id -> Id
string Type = 2;
// SomeField will not be added to transformation function.
string some_field = 3 [ (transformer.skip) = true ];
string URL = 4;
int64 SKU = 5;
}
message Value2Pointer {
option (transformer.go_struct) = "Value2Pointer";
// In message.pb.go Address field will be of type Address.
Address address_nil = 1 [ (gogoproto.nullable) = false ];
}
message Pointer2Value {
option (transformer.go_struct) = "Pointer2Value";
// In message.pb.go Address field will be of type *Address.
Address address_not_nil = 1;
}
message SkippedMessageOne {} // skip it because it hasn't transformer.go_struct option.
message SkippedMessageTwo {} // skip it because it hasn't transformer.go_struct option.
message Timer {
option (transformer.go_struct) = "TimeModel";
google.protobuf.Timestamp time = 1 [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true, (transformer.map_to) = "TimeTime"];
google.protobuf.Timestamp ptr_time = 2 [ (gogoproto.nullable) = true, (gogoproto.stdtime) = true, (transformer.map_to) = "PtrTimeTime" ];
google.protobuf.Timestamp time_to_struct = 3 [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true, (transformer.map_to) = "NullsTime"];
google.protobuf.Timestamp time_to_struct_ptr = 4 [ (gogoproto.nullable) = true, (gogoproto.stdtime) = true, (transformer.map_to) = "PtrNullsTime" ];
google.protobuf.Timestamp time_ptr_to_struct = 5 [ (gogoproto.nullable) = true, (gogoproto.stdtime) = true, (transformer.map_to) = "NullsTime2"];
google.protobuf.Timestamp time_ptr_to_ptr_struct = 6 [ (gogoproto.nullable) = true, (gogoproto.stdtime) = true, (transformer.map_to) = "PtrNullsTime2" ];
}
message Ints {
option (transformer.go_struct) = "IntsModel";
int32 int_for_32_value = 1 [ (transformer.map_to) = "IntFor32Value", (transformer.map_as) = "IntFor_32Value" ];
int64 int_for_64_value = 2 [ (transformer.map_to) = "IntFor64Value", (transformer.map_as) = "IntFor_64Value"];
int32 int32_value = 3;
int64 int64_value = 4;
int64 string_value = 5;
}