@@ -151,7 +151,7 @@ def generate_one_of(self):
151
151
],
152
152
}
153
153
154
- Valid values for this definitions are 3, 5, 6, ... but not 15 for example.
154
+ Valid values for this definition are 3, 5, 6, ... but not 15 for example.
155
155
"""
156
156
self .l ('{variable}_one_of_count = 0' )
157
157
for definition_item in self ._definition ['oneOf' ]:
@@ -173,7 +173,7 @@ def generate_not(self):
173
173
174
174
{'not': {'type': 'null'}}
175
175
176
- Valid values for this definitions are 'hello', 42, {} ... but not None.
176
+ Valid values for this definition are 'hello', 42, {} ... but not None.
177
177
178
178
Since draft 06 definition can be boolean. False means nothing, True
179
179
means everything is invalid.
@@ -211,6 +211,15 @@ def generate_pattern(self):
211
211
self .l ('raise JsonSchemaException("{name} must match pattern {pattern}")' )
212
212
213
213
def generate_format (self ):
214
+ """
215
+ Means that value have to be in specified format. For example date, email or other.
216
+
217
+ .. code-block:: python
218
+
219
+ {'format': 'email'}
220
+
221
+ Valid value for this definition is [email protected] but not @username
222
+ """
214
223
with self .l ('if isinstance({variable}, str):' ):
215
224
format_ = self ._definition ['format' ]
216
225
if format_ in self .FORMAT_REGEXS :
@@ -368,6 +377,19 @@ def generate_required(self):
368
377
self .l ('raise JsonSchemaException("{name} must contain {required} properties")' )
369
378
370
379
def generate_properties (self ):
380
+ """
381
+ Means object with defined keys.
382
+
383
+ .. code-block:: python
384
+
385
+ {
386
+ 'properties': {
387
+ 'key': {'type': 'number'},
388
+ },
389
+ }
390
+
391
+ Valid object is containing key called 'key' and value any number.
392
+ """
371
393
self .create_variable_is_dict ()
372
394
with self .l ('if {variable}_is_dict:' ):
373
395
self .create_variable_keys ()
@@ -385,6 +407,19 @@ def generate_properties(self):
385
407
self .l ('else: {variable}["{}"] = {}' , key , repr (prop_definition ['default' ]))
386
408
387
409
def generate_pattern_properties (self ):
410
+ """
411
+ Means object with defined keys as patterns.
412
+
413
+ .. code-block:: python
414
+
415
+ {
416
+ 'patternProperties': {
417
+ '^x': {'type': 'number'},
418
+ },
419
+ }
420
+
421
+ Valid object is containing key starting with a 'x' and value any number.
422
+ """
388
423
self .create_variable_is_dict ()
389
424
with self .l ('if {variable}_is_dict:' ):
390
425
self .create_variable_keys ()
@@ -402,6 +437,21 @@ def generate_pattern_properties(self):
402
437
)
403
438
404
439
def generate_additional_properties (self ):
440
+ """
441
+ Means object with keys with values defined by definition.
442
+
443
+ .. code-block:: python
444
+
445
+ {
446
+ 'properties': {
447
+ 'key': {'type': 'number'},
448
+ }
449
+ 'additionalProperties': {'type': 'string'},
450
+ }
451
+
452
+ Valid object is containing key called 'key' and it's value any number and
453
+ any other key with any string.
454
+ """
405
455
self .create_variable_is_dict ()
406
456
with self .l ('if {variable}_is_dict:' ):
407
457
self .create_variable_keys ()
0 commit comments