Skip to content

Commit dd651fc

Browse files
committed
Doc strings
1 parent c8ac899 commit dd651fc

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

fastjsonschema/draft04.py

+52-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def generate_one_of(self):
151151
],
152152
}
153153
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.
155155
"""
156156
self.l('{variable}_one_of_count = 0')
157157
for definition_item in self._definition['oneOf']:
@@ -173,7 +173,7 @@ def generate_not(self):
173173
174174
{'not': {'type': 'null'}}
175175
176-
Valid values for this definitions are 'hello', 42, {} ... but not None.
176+
Valid values for this definition are 'hello', 42, {} ... but not None.
177177
178178
Since draft 06 definition can be boolean. False means nothing, True
179179
means everything is invalid.
@@ -211,6 +211,15 @@ def generate_pattern(self):
211211
self.l('raise JsonSchemaException("{name} must match pattern {pattern}")')
212212

213213
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+
"""
214223
with self.l('if isinstance({variable}, str):'):
215224
format_ = self._definition['format']
216225
if format_ in self.FORMAT_REGEXS:
@@ -368,6 +377,19 @@ def generate_required(self):
368377
self.l('raise JsonSchemaException("{name} must contain {required} properties")')
369378

370379
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+
"""
371393
self.create_variable_is_dict()
372394
with self.l('if {variable}_is_dict:'):
373395
self.create_variable_keys()
@@ -385,6 +407,19 @@ def generate_properties(self):
385407
self.l('else: {variable}["{}"] = {}', key, repr(prop_definition['default']))
386408

387409
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+
"""
388423
self.create_variable_is_dict()
389424
with self.l('if {variable}_is_dict:'):
390425
self.create_variable_keys()
@@ -402,6 +437,21 @@ def generate_pattern_properties(self):
402437
)
403438

404439
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+
"""
405455
self.create_variable_is_dict()
406456
with self.l('if {variable}_is_dict:'):
407457
self.create_variable_keys()

0 commit comments

Comments
 (0)