Schema#

class ocdskit.schema.Field(schema=None, pointer_components=None, path_components=None, definition_pointer_components=None, definition_path_components=None, required=None, deprecated=<factory>, multilingual=None)[source]#

Initializes a schema field object.

Parameters:
  • schema (dict) –

  • pointer_components (tuple) –

  • path_components (tuple) –

  • definition_pointer_components (tuple) –

  • definition_path_components (tuple) –

  • required (bool) –

  • deprecated (dict) –

  • multilingual (bool) –

schema: dict = None#

the field’s schema

pointer_components: tuple = None#

the JSON pointer to the field in the schema, e.g. ('properties', 'tender', 'properties', 'id')

path_components: tuple = None#

the path to the field in data, e.g. ('tender', 'id')

definition_pointer_components: tuple = None#

the JSON pointer to the definition in which the field is defined, e.g. ('definitions', 'Item')

definition_path_components: tuple = None#

the path to the definition in which the field is defined, e.g. ('Item')

required: bool = None#

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 = None#

whether the field has a corresponding field in the schema’s patternProperties

sep = '.'#

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.

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

__annotations__ = {'definition_path_components': <class 'tuple'>, 'definition_pointer_components': <class 'tuple'>, 'deprecated': <class 'dict'>, 'multilingual': <class 'bool'>, 'path_components': <class 'tuple'>, 'pointer_components': <class 'tuple'>, 'required': <class 'bool'>, 'schema': <class 'dict'>}#
__dataclass_fields__ = {'definition_path_components': Field(name='definition_path_components',type=<class 'tuple'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'definition_pointer_components': Field(name='definition_pointer_components',type=<class 'tuple'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'deprecated': Field(name='deprecated',type=<class 'dict'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'multilingual': Field(name='multilingual',type=<class 'bool'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'path_components': Field(name='path_components',type=<class 'tuple'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'pointer_components': Field(name='pointer_components',type=<class 'tuple'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'required': Field(name='required',type=<class 'bool'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'schema': Field(name='schema',type=<class 'dict'>,default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)}#
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)#
__eq__(other)#

Return self==value.

__hash__ = None#
__init__(schema=None, pointer_components=None, path_components=None, definition_pointer_components=None, definition_path_components=None, required=None, deprecated=<factory>, multilingual=None)#
Parameters:
  • schema (dict | None) –

  • pointer_components (tuple | None) –

  • path_components (tuple | None) –

  • definition_pointer_components (tuple | None) –

  • definition_path_components (tuple | None) –

  • required (bool | None) –

  • deprecated (dict) –

  • multilingual (bool | None) –

Return type:

None

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