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.
-
-
class
invenio_jsonschemas.ext.
InvenioJSONSchemasAPI
(app=None, **kwargs)[source]¶ Invenio-JSONSchemas extension for API.
Extension initialization.
Parameters: app – The Flask application. (Default: None
)
-
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: - path – schema’s relative path.
- with_refs – replace $refs in the schema.
- resolved – resolve schema using the resolver
invenio_jsonschemas.config.JSONSCHEMAS_RESOLVER_CLS
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.
-
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.
-
-
class
invenio_jsonschemas.ext.
InvenioJSONSchemasUI
(app=None, **kwargs)[source]¶ Invenio-JSONSchemas extension for UI.
Extension initialization.
Parameters: app – The Flask application. (Default: None
)
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.
JSON resolver¶
JSON resolver for JSON schemas.
Views¶
Invenio module for building and serving JSONSchemas.
-
invenio_jsonschemas.views.
create_blueprint
(state)[source]¶ Create blueprint serving JSON schemas.
Parameters: state – invenio_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.