Utils Docs

Public api for methods and functions to handle/verify the jsonschemas.

class inspire_schemas.utils.LocalRefResolver(base_uri, referrer, store=(), cache_remote=True, handlers=(), urljoin_cache=None, remote_cache=None)[source]

Bases: jsonschema.validators.RefResolver

Simple resolver to handle non-uri relative paths.

resolve_remote(uri)[source]

Resolve a uri or relative path to a schema.

inspire_schemas.utils.get_schema_path(schema)[source]

Retrieve the installed path for the given schema.

Parameters:schema (str) – String with the (relative or absolute) url of the schema to validate, for example, ‘records/authors.json’ or ‘jobs.json’, or by just the name like ‘jobs’.
Returns:The path or the given schema name.
Return type:str
inspire_schemas.utils.load_schema(schema_name)[source]

Load the given schema from wherever it’s installed.

Parameters:schema_name – Name of the schema to load, for example ‘authors’.
inspire_schemas.utils.normalize_author_name_with_comma(author)[source]

Normalize author name.

Parameters:author (string) – author name
Return name:the name of the author normilized
inspire_schemas.utils.normalize_date_iso(date)[source]

Normalize date for schema (format yyyy-mm-ddT00:00:00).

Parameters:date (string with the format (yyyy-mm-dd)) – a generic date
Return formatted_date:
 the input date in

the format (yyyy-mm-ddT00:00:00)

inspire_schemas.utils.validate(data, schema_name=None)[source]

Validate the given dictionary against the given schema.

Parameters:
  • data (dict) – Dict to validate.
  • schema_name (str) – String with the name of the schema to validate, for example, ‘authors’ or ‘jobs’. If None passed it will expect for the data to have the schema specified in the $ref key.
Returns:

None

Raises:
  • inspire_schemas.errors.SchemaNotFound – if the given schema was not found.
  • inspire_schemas.errors.SchemaKeyNotFound – if the given schema was not found.
  • jsonschema.SchemaError – if the schema is invalid
  • jsonschema.ValidationError – if the data is invalid