Schema

Methods for interacting with or reasoning about JSON Schema and CSV codelists.

jscc.schema.is_codelist(fieldnames)[source]
Parameters:

fieldnames (list) – the fieldnames of the CSV

Returns:

whether the CSV is a codelist

Return type:

bool

jscc.schema.is_json_schema(data)[source]
Parameters:

data (dict) – JSON data

Returns:

whether the JSON data is a JSON Schema

Return type:

bool

jscc.schema.is_json_merge_patch(data)[source]
Parameters:

data (dict) – JSON data

Returns:

whether the JSON data is a JSON Merge Patch

Return type:

bool

jscc.schema.is_array_of_objects(field)[source]
Parameters:

field (dict) – the field

Returns:

whether a field is an array of objects

Return type:

bool

jscc.schema.is_missing_property(field, prop)[source]
Parameters:
  • field (dict) – the field

  • prop (str) – the property

Returns:

whether a field’s property isn’t set, is empty, or is whitespace

Return type:

bool

jscc.schema.get_types(field)[source]

Return a field’s “type” as a list.

Parameters:

field (dict) – the field

Returns:

a field’s “type”

Return type:

list

jscc.schema.extend_schema(basename, schema, metadata, codelists=None)[source]

Patches a JSON Schema with an extension’s dependencies, recursively.

If codelists is provided, it will be updated with the codelists from the dependencies.

Attention

No timeout is set. If a user can input malicious metadata with unresponsive dependencies or testDependencies URLs, the program can hang indefinitely.

Attention

This function is vulnerable to server-side request forgery (SSRF). A user can create an extension whose dependencies point to internal resources, which would receive a GET request.

Parameters:
  • basename (str) – the JSON Schema file’s basename

  • schema (dict) – the JSON Schema file’s parsed contents

  • metadata (dict) – the extension metadata file’s parsed contents

  • codelists (set) – any set

Returns:

the patched schema

Return type:

dict

class jscc.schema.RejectingDict(dict=None, /, **kwargs)[source]

A dict that raises an error if a key is set more than once.

jscc.schema.rejecting_dict(pairs)[source]

Allow a key to be set at most once. Use as an object_pairs_hook method.