API Docs

Invenio module for building and serving JSONSchemas.

class invenio_jsonschemas.ext.InvenioJSONSchemas(app=None, **kwargs)[source]

Invenio-JSONSchemas extension.

Register blueprint serving registered schemas and can be used as an api to register those schemas.

Note

JSON schemas are served as static files. Thus their “id” and “$ref” fields might not match the Flask application’s host and port.

Extension initialization.

Parameters:app – The Flask application. (Default: None)
init_app(app, entry_point_group=None, register_blueprint=True, register_config_blueprint=None)[source]

Flask application initialization.

Parameters:
  • app – The Flask application.
  • entry_point_group – The group entry point to load extensions. (Default: invenio_jsonschemas.schemas)
  • register_blueprint – Register the blueprints.
  • register_config_blueprint – Register blueprint for the specific app from a config variable.
init_config(app)[source]

Initialize configuration.

class invenio_jsonschemas.ext.InvenioJSONSchemasAPI(app=None, **kwargs)[source]

Invenio-JSONSchemas extension for API.

Extension initialization.

Parameters:app – The Flask application. (Default: None)
init_app(app)[source]

Flask application initialization.

Parameters:app – The Flask application.
class invenio_jsonschemas.ext.InvenioJSONSchemasState(app)[source]

InvenioJSONSchemas state and api.

Constructor.

Parameters:app – application registering this state
get_schema(**kwds)[source]

Retrieve a schema.

Parameters:
Raises:

invenio_jsonschemas.errors.JSONSchemaNotFound – If no schema was found in the specified path.

Returns:

The schema in a dictionary form.

get_schema_dir(path)[source]

Retrieve the directory containing the given schema.

Parameters:path – Schema path, relative to the directory where it was registered.
Raises:invenio_jsonschemas.errors.JSONSchemaNotFound – If no schema was found in the specified path.
Returns:The schema directory.
get_schema_path(path)[source]

Compute the schema’s absolute path from a schema relative path.

Parameters:path – relative path of the schema.
Raises:invenio_jsonschemas.errors.JSONSchemaNotFound – If no schema was found in the specified path.
Returns:The absolute path.
list_schemas()[source]

List all JSON-schema names.

Returns:list of schema names.
Return type:list
loader_cls[source]

Loader class used in JsonRef.replace_refs.

path_to_url(path)[source]

Build URL from a path.

Parameters:path – relative path of the schema.
Returns:The schema complete URL or None if not found.
register_schema(directory, path)[source]

Register a json-schema.

Parameters:
  • directory – root directory path.
  • path – schema path, relative to the root directory.
register_schemas_dir(directory)[source]

Recursively register all json-schemas in a directory.

Parameters:directory – directory path.
resolver_cls[source]

Loader to resolve the schema.

url_to_path(url)[source]

Convert schema URL to path.

Parameters:url – The schema URL.
Returns:The schema path or None if the schema can’t be resolved.
class invenio_jsonschemas.ext.InvenioJSONSchemasUI(app=None, **kwargs)[source]

Invenio-JSONSchemas extension for UI.

Extension initialization.

Parameters:app – The Flask application. (Default: None)
init_app(app)[source]

Flask application initialization.

Parameters:app – The Flask application.

Errors

Invenio-JSONSchemas errors.

exception invenio_jsonschemas.errors.JSONSchemaDuplicate(schema, first_dir, second_dir, *args, **kwargs)[source]

Exception raised when multiple schemas match the same path.

Constructor.

Parameters:
  • schema – duplicate schema path.
  • first_dir – first directory where the schema was found.
  • second_dir – second directory where the schema was found.
exception invenio_jsonschemas.errors.JSONSchemaError[source]

Base class for errors in Invenio-JSONSchemas module.

exception invenio_jsonschemas.errors.JSONSchemaNotFound(schema, *args, **kwargs)[source]

Exception raised when a requested JSONSchema is not found.

Constructor.

Parameters:schema – path of the requested schema which was not found.

JSON resolver

JSON resolver for JSON schemas.

invenio_jsonschemas.jsonresolver.jsonresolver_loader(url_map)[source]

JSON resolver plugin that loads the schema endpoint.

Injected into Invenio-Records JSON resolver.

Views

Invenio module for building and serving JSONSchemas.

invenio_jsonschemas.views.create_blueprint(state)[source]

Create blueprint serving JSON schemas.

Parameters:stateinvenio_jsonschemas.ext.InvenioJSONSchemasState instance used to retrieve the schemas.

Utils

Invenio JSONSchemas utils.

invenio_jsonschemas.utils.resolve_schema(schema)[source]

Transform JSON schemas “allOf”.

This is the default schema resolver.

This function was created because some javascript JSON Schema libraries don’t support “allOf”. We recommend to use this function only in this specific case.

This function is transforming the JSON Schema by removing “allOf” keywords. It recursively merges the sub-schemas as dictionaries. The process is completely custom and works only for simple JSON Schemas which use basic types (object, string, number, …). Optional structures like “schema dependencies” or “oneOf” keywords are not supported.

Parameters:schema (dict) – the schema to resolve.
Returns:the resolved schema

Note

The schema should have the $ref already resolved before running this method.