@@ -83,6 +83,8 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
83
83
84
84
// Switch the types, and pick a JSONSchema equivalent:
85
85
switch desc .GetType () {
86
+
87
+ // Float32:
86
88
case descriptor .FieldDescriptorProto_TYPE_DOUBLE ,
87
89
descriptor .FieldDescriptorProto_TYPE_FLOAT :
88
90
if messageFlags .AllowNullValues {
@@ -94,6 +96,7 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
94
96
jsonSchemaType .Type = gojsonschema .TYPE_NUMBER
95
97
}
96
98
99
+ // Int32:
97
100
case descriptor .FieldDescriptorProto_TYPE_INT32 ,
98
101
descriptor .FieldDescriptorProto_TYPE_UINT32 ,
99
102
descriptor .FieldDescriptorProto_TYPE_FIXED32 ,
@@ -108,24 +111,38 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
108
111
jsonSchemaType .Type = gojsonschema .TYPE_INTEGER
109
112
}
110
113
114
+ // Int64:
111
115
case descriptor .FieldDescriptorProto_TYPE_INT64 ,
112
116
descriptor .FieldDescriptorProto_TYPE_UINT64 ,
113
117
descriptor .FieldDescriptorProto_TYPE_FIXED64 ,
114
118
descriptor .FieldDescriptorProto_TYPE_SFIXED64 ,
115
119
descriptor .FieldDescriptorProto_TYPE_SINT64 :
116
- if messageFlags .AllowNullValues {
117
- jsonSchemaType .OneOf = []* jsonschema.Type {
118
- {Type : gojsonschema .TYPE_STRING },
119
- {Type : gojsonschema .TYPE_NULL },
120
+
121
+ // As integer:
122
+ if c .Flags .DisallowBigIntsAsStrings {
123
+ if messageFlags .AllowNullValues {
124
+ jsonSchemaType .OneOf = []* jsonschema.Type {
125
+ {Type : gojsonschema .TYPE_INTEGER },
126
+ {Type : gojsonschema .TYPE_NULL },
127
+ }
128
+ } else {
129
+ jsonSchemaType .Type = gojsonschema .TYPE_INTEGER
120
130
}
121
- } else {
122
- jsonSchemaType .Type = gojsonschema .TYPE_STRING
123
131
}
124
132
125
- if c .Flags .DisallowBigIntsAsStrings {
126
- jsonSchemaType .Type = gojsonschema .TYPE_INTEGER
133
+ // As string:
134
+ if ! c .Flags .DisallowBigIntsAsStrings {
135
+ if messageFlags .AllowNullValues {
136
+ jsonSchemaType .OneOf = []* jsonschema.Type {
137
+ {Type : gojsonschema .TYPE_STRING },
138
+ {Type : gojsonschema .TYPE_NULL },
139
+ }
140
+ } else {
141
+ jsonSchemaType .Type = gojsonschema .TYPE_STRING
142
+ }
127
143
}
128
144
145
+ // String:
129
146
case descriptor .FieldDescriptorProto_TYPE_STRING :
130
147
stringDef := & jsonschema.Type {Type : gojsonschema .TYPE_STRING }
131
148
// Check for custom options
@@ -164,6 +181,7 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
164
181
}
165
182
}
166
183
184
+ // Bytes:
167
185
case descriptor .FieldDescriptorProto_TYPE_BYTES :
168
186
if messageFlags .AllowNullValues {
169
187
jsonSchemaType .OneOf = []* jsonschema.Type {
@@ -180,6 +198,7 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
180
198
jsonSchemaType .BinaryEncoding = "base64"
181
199
}
182
200
201
+ // ENUM:
183
202
case descriptor .FieldDescriptorProto_TYPE_ENUM :
184
203
185
204
// Go through all the enums we have, see if we can match any to this field.
@@ -197,6 +216,7 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
197
216
198
217
jsonSchemaType = & enumSchema
199
218
219
+ // Bool:
200
220
case descriptor .FieldDescriptorProto_TYPE_BOOL :
201
221
if messageFlags .AllowNullValues {
202
222
jsonSchemaType .OneOf = []* jsonschema.Type {
@@ -207,6 +227,7 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
207
227
jsonSchemaType .Type = gojsonschema .TYPE_BOOLEAN
208
228
}
209
229
230
+ // Group (object):
210
231
case descriptor .FieldDescriptorProto_TYPE_GROUP , descriptor .FieldDescriptorProto_TYPE_MESSAGE :
211
232
switch desc .GetTypeName () {
212
233
// Make sure that durations match a particular string pattern (eg 3.4s):
0 commit comments