Schema

class ocdskit.schema.Field(name, schema, deprecated_self, deprecated, pointer, path_components, definition, pattern=False, multilingual=False, required=False, merge_by_id=False, codelist='', open_codelist=False)[source]

Initialize a schema field object.

Parameters:
name: str

The field’s name.

schema: dict

The field’s schema.

deprecated_self: dict

The deprecated property of the field.

deprecated: dict

The deprecated property of the field, or an ancestor of the field.

pointer: str

The JSON pointer to the field in the schema, e.g. /properties/tender/properties/id. Used, for example, to look up a modified field’s original schema in the release schema.

path_components: tuple

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

definition: str

The definition in which the field is defined, e.g. 'Item'.

pattern: bool = False

Whether the field is defined under patternProperties.

multilingual: bool = False

Whether the field has a corresponding field in the schema’s patternProperties (like in OCDS 1.1).

required: bool = False

Whether the field is listed under required.

merge_by_id: bool = False

Whether the field’s name is id and isn’t under a wholeListMerge array.

codelist: str = ''

The field’s codelist.

open_codelist: bool = False

Whether the field’s codelist is open.

sep = '.'

The separator to use in string representations of paths.

property path

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

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

Return the field as a dict, with keys for all properties except path_components.

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__ = {'codelist': 'str', 'definition': 'str', 'deprecated': 'dict', 'deprecated_self': 'dict', 'merge_by_id': 'bool', 'multilingual': 'bool', 'name': 'str', 'open_codelist': 'bool', 'path_components': 'tuple', 'pattern': 'bool', 'pointer': 'str', 'required': 'bool', 'schema': 'dict'}
__dataclass_fields__ = {'codelist': Field(name='codelist',type='str',default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'definition': Field(name='definition',type='str',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'deprecated': Field(name='deprecated',type='dict',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'deprecated_self': Field(name='deprecated_self',type='dict',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'merge_by_id': Field(name='merge_by_id',type='bool',default=False,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'multilingual': Field(name='multilingual',type='bool',default=False,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'name': Field(name='name',type='str',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'open_codelist': Field(name='open_codelist',type='bool',default=False,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='tuple',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'pattern': Field(name='pattern',type='bool',default=False,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'pointer': Field(name='pointer',type='str',default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'required': Field(name='required',type='bool',default=False,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'schema': Field(name='schema',type='dict',default=<dataclasses._MISSING_TYPE object>,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__(name, schema, deprecated_self, deprecated, pointer, path_components, definition, pattern=False, multilingual=False, required=False, merge_by_id=False, codelist='', open_codelist=False)
Parameters:
Return type:

None

ocdskit.schema.get_schema_fields(schema, pointer='', path_components=(), definition='', deprecated=None, *, whole_list_merge=False, array=False)[source]

Yield a Field for each name under properties or patternProperties.

Parameters:
  • schema (dict) – A dereferenced JSON schema. If using jsonref, and if subschemas set both $ref and other properties, the schema must be dereferenced with either proxies=True or merge_props=True.

  • pointer (str) – The JSON pointer to the field in the schema, e.g. /properties/tender/properties/id.

  • path_components (tuple) – The path to the field in data, e.g. ('tender', 'id').

  • definition (str) – The definition in which the field is defined, e.g. 'Item'.

  • deprecated (dict | None) – If the field, or an ancestor of the field, sets deprecated, the deprecated object.

  • whole_list_merge (bool) – Whether the field, or an ancestor of the field, sets wholelistMerge.

  • array (bool) – Whether the field is under items/properties or items/patternProperties.

ocdskit.schema.add_validation_properties(schema, *, unique_items=True, coordinates=False)[source]

Add “minItems” and “uniqueItems” if an array, add “minProperties” if an object, and add “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