@@ -16,6 +16,11 @@ import (
16
16
"github.com/xeipuuv/gojsonschema"
17
17
)
18
18
19
+ const (
20
+ PatternIpv6WithMask = "^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))(\\ \\ /(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))$"
21
+ PatternIpv4WithMask = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\ .){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(/(3[0-2]|[1-2][0-9]|[0-9]))$"
22
+ )
23
+
19
24
var (
20
25
globalPkg = newProtoPackage (nil , "" )
21
26
@@ -101,6 +106,7 @@ func (c *Converter) applyAllowNullValuesOption(schema *jsonschema.Type, schemaCh
101
106
}, {
102
107
Type : schemaChanges .Type ,
103
108
Format : schemaChanges .Format ,
109
+ Pattern : schemaChanges .Pattern ,
104
110
Minimum : schemaChanges .Minimum ,
105
111
ExclusiveMinimum : schemaChanges .ExclusiveMinimum ,
106
112
Maximum : schemaChanges .Maximum ,
@@ -115,6 +121,7 @@ func (c *Converter) applyAllowNullValuesOption(schema *jsonschema.Type, schemaCh
115
121
} else { // direct mapping (schema could be already partially built -> need to fill new values into it)
116
122
schema .Type = schemaChanges .Type
117
123
schema .Format = schemaChanges .Format
124
+ schema .Pattern = schemaChanges .Pattern
118
125
schema .Minimum = schemaChanges .Minimum
119
126
schema .ExclusiveMinimum = schemaChanges .ExclusiveMinimum
120
127
schema .Maximum = schemaChanges .Maximum
@@ -224,6 +231,64 @@ func (c *Converter) convertField(curPkg *ProtoPackage, desc *descriptor.FieldDes
224
231
Format : "ipv6" ,
225
232
},
226
233
}
234
+ case ligato .LigatoOptions_IPV4_WITH_MASK :
235
+ schema .Type = gojsonschema .TYPE_STRING
236
+ schema .Pattern = PatternIpv4WithMask
237
+ case ligato .LigatoOptions_IPV6_WITH_MASK :
238
+ schema .Type = gojsonschema .TYPE_STRING
239
+ schema .Pattern = PatternIpv6WithMask
240
+ case ligato .LigatoOptions_IP_WITH_MASK :
241
+ schema .OneOf = []* jsonschema.Type {
242
+ {
243
+ Type : gojsonschema .TYPE_STRING ,
244
+ Pattern : PatternIpv4WithMask ,
245
+ },
246
+ {
247
+ Type : gojsonschema .TYPE_STRING ,
248
+ Pattern : PatternIpv6WithMask ,
249
+ },
250
+ }
251
+ case ligato .LigatoOptions_IPV4_OPTIONAL_MASK :
252
+ schema .OneOf = []* jsonschema.Type {
253
+ {
254
+ Type : gojsonschema .TYPE_STRING ,
255
+ Format : "ipv4" ,
256
+ },
257
+ {
258
+ Type : gojsonschema .TYPE_STRING ,
259
+ Pattern : PatternIpv4WithMask ,
260
+ },
261
+ }
262
+ case ligato .LigatoOptions_IPV6_OPTIONAL_MASK :
263
+ schema .OneOf = []* jsonschema.Type {
264
+ {
265
+ Type : gojsonschema .TYPE_STRING ,
266
+ Format : "ipv6" ,
267
+ },
268
+ {
269
+ Type : gojsonschema .TYPE_STRING ,
270
+ Pattern : PatternIpv6WithMask ,
271
+ },
272
+ }
273
+ case ligato .LigatoOptions_IP_OPTIONAL_MASK :
274
+ schema .OneOf = []* jsonschema.Type {
275
+ {
276
+ Type : gojsonschema .TYPE_STRING ,
277
+ Format : "ipv4" ,
278
+ },
279
+ {
280
+ Type : gojsonschema .TYPE_STRING ,
281
+ Pattern : PatternIpv4WithMask ,
282
+ },
283
+ {
284
+ Type : gojsonschema .TYPE_STRING ,
285
+ Format : "ipv6" ,
286
+ },
287
+ {
288
+ Type : gojsonschema .TYPE_STRING ,
289
+ Pattern : PatternIpv6WithMask ,
290
+ },
291
+ }
227
292
default : // no annotations or annotation used are not applicable here
228
293
schema .Type = gojsonschema .TYPE_STRING
229
294
}
0 commit comments