4.1. How to validate JSON-schemas and instances: code documentation

jsonschema_validator.validate_instance(schemapath, schemafile, instancepath, instancefile, error_printing, store)[source]

Validate a JSON instance against a JSON schema.

Parameters:
  • schemapath – the path to the schema directory
  • schemafile – the name of the schema file
  • instancepath – the path of the instance direvotyr
  • instancefile – the name of the instance path
  • error_printing – the error log
  • store – a store required by RefResolver
Returns:

errors

jsonschema_validator.validate_instance_against_schema(instance, resolver, schema)[source]

Simple function to validate an instance against a schema on the fly

Parameters:
  • instance (dict) – the JSON instance to validate
  • resolver (RefResolver) – the resolver object used by Drat4Validator
  • schema (dict) – the root schema to validate against
Returns:

Draft4Validator.validate

jsonschema_validator.validate_schema(path, schema_file_name)[source]

Validate a JSON schema given the folder/path and file name of the schema file.

Parameters:
  • path – the path to the schema directory
  • schema_file_name – the name of the schema in that directory
Returns:

True or False

jsonschema_validator.validate_schema_file(schema_file)[source]

Validate a JSON schema given the schema file.

Parameters:schema_file – the string the the schema file location
Returns:True
class miflowcyt_validate.FlowRepoClient(mapping, client_id, number_of_items)[source]

A class that provides functionality to download experiments from the FlowRepository (https://flowrepository.org/), transform the XML into JSON and validate the JSON instances against their JSON schema. The transformation from XML to JSON relies on the JSONBender library (https://github.com/Onyo/jsonbender).

get_all_experiments(max_number, accessible_ids)[source]

Grab all experiments from the API for the given number

Parameters:
  • max_number (int) – the number of item to retrieve
  • accessible_ids (list) – the ids that this use can fetch
Returns:

the experiments XMLs

static get_mapping(mapping_file_name)[source]

Build the mapping dictionary based on the given mapping file

Parameters:mapping_file_name – the name of the mapping file
Return mapping:the mapping of the fields
get_user_content_id()[source]

Return all IDs found in the user content XML

Returns:a list of all IDs there were identified in the variable returned by the API
grab_experiment_from_api(item_identifier)[source]

Retrieve the experimental metadata and return it as XML document object

Parameters:item_identifier – the item identifier that should be retrieved
Returns:the XML document object
inject_context()[source]

Transform the myflowcyt JSON into a JSON-LD by injecting @context and @type keywords :return: a JSON-LD of the myflowcyt JSON

make_validation()[source]

Method to run the mapping for the given number of items

Returns:a dictionary containing the list of errors for all processed items
preprocess_content(content)[source]

Preprocess the XML into a JSON that is compliant with the schema. :param content: str containing the XML :type content: str :return: a JSON schema cleaned from residual artifacts

static validate_instance_from_file(instance, item_id, schema_name)[source]

Method to output the extracted JSON into a file and validate it against the given schema

Parameters:
  • instance – the instance to output into a file
  • item_id – the instance ID needed to create the file name
  • schema_name – the schema to check against
Return errors:

a list of fields that have an error for this instance

class miflowcyt_validate.FlowRepoClient(mapping, client_id, number_of_items)[source]

A class that provides functionality to download experiments from the FlowRepository (https://flowrepository.org/), transform the XML into JSON and validate the JSON instances against their JSON schema. The transformation from XML to JSON relies on the JSONBender library (https://github.com/Onyo/jsonbender).

get_all_experiments(max_number, accessible_ids)[source]

Grab all experiments from the API for the given number

Parameters:
  • max_number (int) – the number of item to retrieve
  • accessible_ids (list) – the ids that this use can fetch
Returns:

the experiments XMLs

static get_mapping(mapping_file_name)[source]

Build the mapping dictionary based on the given mapping file

Parameters:mapping_file_name – the name of the mapping file
Return mapping:the mapping of the fields
get_user_content_id()[source]

Return all IDs found in the user content XML

Returns:a list of all IDs there were identified in the variable returned by the API
grab_experiment_from_api(item_identifier)[source]

Retrieve the experimental metadata and return it as XML document object

Parameters:item_identifier – the item identifier that should be retrieved
Returns:the XML document object
inject_context()[source]

Transform the myflowcyt JSON into a JSON-LD by injecting @context and @type keywords :return: a JSON-LD of the myflowcyt JSON

make_validation()[source]

Method to run the mapping for the given number of items

Returns:a dictionary containing the list of errors for all processed items
preprocess_content(content)[source]

Preprocess the XML into a JSON that is compliant with the schema. :param content: str containing the XML :type content: str :return: a JSON schema cleaned from residual artifacts

static validate_instance_from_file(instance, item_id, schema_name)[source]

Method to output the extracted JSON into a file and validate it against the given schema

Parameters:
  • instance – the instance to output into a file
  • item_id – the instance ID needed to create the file name
  • schema_name – the schema to check against
Return errors:

a list of fields that have an error for this instance