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

property pointer#

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

property definition_pointer#

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

property path#

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

property definition_path#

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

property 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, coordinates=False)[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

  • coordinates (bool) – whether the parent is a geospatial coordinates field