Schema

class ocdskit.schema.Field(schema=None, pointer=None, path=None, definition_pointer=None, definition_path=None, required=None, deprecated=None, multilingual=None, sep='.')[source]
__init__(schema=None, pointer=None, path=None, definition_pointer=None, definition_path=None, required=None, deprecated=None, multilingual=None, sep='.')[source]

Initializes a schema field object.

Parameters:
  • schema (dict) – the field’s schema
  • pointer (tuple) – the JSON pointer to the field in the schema, e.g. ('properties', 'tender', 'properties', 'id')
  • path (tuple) – the path to the field in data, e.g. ('tender', 'id')
  • definition_pointer (tuple) – the JSON pointer to the definition in which the field is defined, e.g. ('definitions', 'Item')
  • definition_path (tuple) – the path to the definition in which the field is defined, e.g. ('Item')
  • required (bool) – whether the field is listed in the schema’s required
  • deprecated (dict) – if the field, or an ancestor of the field, sets deprecated, the deprecated object
  • multilingual (bool) – whether the field has a corresponding field in the schema’s patternProperties
  • sep (str) – the separator to use in string representations of paths
pointer

Returns the JSON pointer to the field in the schema, e.g. /properties/tender/properties/id.

definition_pointer

Returns the JSON pointer to the definition in which the field is defined, e.g. /definitions/Item.

path

Returns the path to the field in data with self.sep as separator, e.g. tender.id.

definition_path

Returns the path to the definition in which the field is defined with self.sep as separator, e.g. Item.

sep

Returns the separator to use in string representations of paths.

asdict(sep=None, exclude=None)[source]

Returns the field as a dict, with keys for: schema, pointer, path, definition_pointer, definition_path, required, deprecated, multilingual.

Parameters:
  • sep (list) – the separator to use in string representations of paths, overriding self.sep
  • exclude (list) – a list of keys to exclude from the dict
ocdskit.schema.get_schema_fields(schema, pointer=None, path=None, definition_pointer=None, definition_path=None, deprecated=None)[source]

Yields a Field object for each field (whether under properties or patternProperties) in a JSON schema.

Parameters:
  • schema (dict) – a JSON schema
  • pointer (tuple) – the JSON pointer to the field in the schema, e.g. ('properties', 'tender', 'properties', 'id')
  • path (tuple) – the path to the field in data, e.g. ('tender', 'id')
  • definition_pointer (tuple) – the JSON pointer to the definition in which the field is defined, e.g. ('definitions', 'Item')
  • definition_path (tuple) – the path to the definition in which the field is defined, e.g. ('Item')
  • deprecated (dict) – if the field, or an ancestor of the field, sets deprecated, the deprecated object
ocdskit.schema.add_validation_properties(schema, unique_items=True)[source]

Adds “minItems” and “uniqueItems” if an array, adds “minProperties” if an object, and adds “minLength” if a string and if “enum”, “format” and “pattern” aren’t set.

Parameters:
  • schema (dict) – a JSON schema
  • unique_items (bool) – whether to add “uniqueItems” properties to array fields