Invenio base record model.
pip install oarepo-invenio-model
The library provides extensible Invenio base record model.
Add this package to your dependencies and use it via $ref in json schema.
{
"type": "object",
"allOf": [
{
"properties": {
"title": {
"type": "string"
}
}
},
{
"$ref": "/schemas/invenio-v1.0.0.json#/definitions/InvenioRecord"
}
],
"additionalProperties": "false"
}
Use oarepo-mapping-includes
library for extanding invenio base record model mapping.
{
"mappings": {
"dynamic": "strict",
"oarepo:extends": "invenio-v1.0.0.json#/InvenioRecord",
"properties": {
"title": {
"type": "text"
}
}
}
}
You can extense your schema with Invenio base model schema by inheriting from InvenioRecordMetadataSchemaV1Mixin
.
class SampleSchemaV1(InvenioRecordMetadataSchemaV1Mixin):
title = fields.String(validate=validate.Length(min=5), required=True)
JSON Schema provides allOf
construct to join multiple schemas. The current
implementation of python's schema validator can not handle allOf
in top-level
element.
To enable composition of schemas in the form of top-level "includes":
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "/schemas/dcterms-v2.0.0.json#/definitions/DCObject"
},
{
"$ref": "/schemas/invenio-v1.0.0.json#/definitions/InvenioRecord"
},
{
"properties": {
"category": {
"type": "string",
"enum": ["kovy", "sklo", "keramika", "textil"]
}
}
}
]
}
inherit your record class from InheritedSchemaRecordMixin
:
from oarepo_invenio_model import InheritedSchemaRecordMixin
from invenio_records.api import Record
class MyRecord(InheritedSchemaRecordMixin, Record):
pass