# Custom fields plugin for model builder
## Custom fields
Custom fields allow extending model at configuration time, with the same sources.
This plugin adds two types of custom fields - ones defined on an explicit element
(usually the "custom_fields" element is used, but any name can be used) and other
one inlining the custom fields directly to the main content.
Currently there is no support for inlining custom fields to "metadata" element,
but this can be changed in the future.
## Model file
Custom fields are defined on the level of "model":
```yaml
model:
use: invenio
custom-fields:
- element: custom_fields
config: TEST_CUSTOM_FIELDS
properties:
metadata:
properties:
title: fulltext
```
### Explicit custom fields
Explicit custom fields are defined using a pair of `element name` and `config` variable.
In the instance the custom fields will be separated into the `element name`:
```python
# config
from invenio_records_resources.services.custom_fields.text import KeywordCF
TEST_CUSTOM_FIELDS = [
KeywordCF('blah')
]
```
```json5
// instance
{
"metadata": {
"title": "My Title"
},
"custom_fields": { // "element" from model
"blah": "Custom field value" // as defined in "TEST_CUSTOM_FIELDS" variable
}
}
```
### Inline custom fields
Inline custom fields are placed on the root level of the instance, without an enclosing element. To define them, just leave the `element` definition. Note that only 1 definition of inline CF is allowed.
```yaml
model:
use: invenio
custom-fields:
- config: INLINE_CF
properties:
metadata:
properties:
title: fulltext
```
```python
# config
from invenio_records_resources.services.custom_fields.text import KeywordCF
INLINE_CF = [
KeywordCF('blah')
]
```
```json5
// instance
{
"metadata": {
"title": "My Title"
},
"blah": "Custom field value" // as defined in "INLINE_CF" variable
}
```
### Custom fields nested in metadata
Custom fields nested inside the metadata are not supported yet.
## Using custom fields
Custom fields influence the jsonschema file (adding a non-checked object or allowing additional properties) and the mapping file (adding an empty mapping for CF).
During deployment time, after the index is created and before data are poured in,
a specialized mapping for custom fields must be created. To do so, call
```bash
invenio oarepo cf init
```
Raw data
{
"_id": null,
"home_page": "https://github.com/oarepo/oarepo-model-builder-cf",
"name": "oarepo-model-builder-cf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "invenio cf model builder",
"author": "Miroslav Simek",
"author_email": "simek.miroslav@techlib.cz",
"download_url": "https://files.pythonhosted.org/packages/4c/88/fe05b9d54a15065989cfe3d4a8482a8d0d18a02133c6083d49915082b5fc/oarepo_model_builder_cf-4.0.8.tar.gz",
"platform": "any",
"description": "# Custom fields plugin for model builder\n\n## Custom fields\n\nCustom fields allow extending model at configuration time, with the same sources.\nThis plugin adds two types of custom fields - ones defined on an explicit element\n(usually the \"custom_fields\" element is used, but any name can be used) and other\none inlining the custom fields directly to the main content.\n\nCurrently there is no support for inlining custom fields to \"metadata\" element,\nbut this can be changed in the future.\n\n## Model file\n\nCustom fields are defined on the level of \"model\":\n\n```yaml\nmodel:\n use: invenio\n custom-fields:\n - element: custom_fields\n config: TEST_CUSTOM_FIELDS\n properties:\n metadata:\n properties:\n title: fulltext\n```\n\n### Explicit custom fields\n\nExplicit custom fields are defined using a pair of `element name` and `config` variable.\nIn the instance the custom fields will be separated into the `element name`:\n\n```python\n# config\n\nfrom invenio_records_resources.services.custom_fields.text import KeywordCF\n\nTEST_CUSTOM_FIELDS = [\n KeywordCF('blah')\n]\n```\n\n```json5\n// instance\n{\n \"metadata\": {\n \"title\": \"My Title\"\n },\n \"custom_fields\": { // \"element\" from model\n \"blah\": \"Custom field value\" // as defined in \"TEST_CUSTOM_FIELDS\" variable\n }\n}\n```\n\n### Inline custom fields\n\nInline custom fields are placed on the root level of the instance, without an enclosing element. To define them, just leave the `element` definition. Note that only 1 definition of inline CF is allowed.\n\n```yaml\nmodel:\n use: invenio\n custom-fields:\n - config: INLINE_CF\n properties:\n metadata:\n properties:\n title: fulltext\n```\n\n\n```python\n# config\n\nfrom invenio_records_resources.services.custom_fields.text import KeywordCF\n\nINLINE_CF = [\n KeywordCF('blah')\n]\n```\n\n```json5\n// instance\n{\n \"metadata\": {\n \"title\": \"My Title\"\n },\n \"blah\": \"Custom field value\" // as defined in \"INLINE_CF\" variable\n}\n```\n\n### Custom fields nested in metadata\n\nCustom fields nested inside the metadata are not supported yet.\n\n## Using custom fields\n\nCustom fields influence the jsonschema file (adding a non-checked object or allowing additional properties) and the mapping file (adding an empty mapping for CF). \n\nDuring deployment time, after the index is created and before data are poured in,\na specialized mapping for custom fields must be created. To do so, call\n\n```bash\ninvenio oarepo cf init\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\"A model builder plugin for custom fields support\"",
"version": "4.0.8",
"project_urls": {
"Homepage": "https://github.com/oarepo/oarepo-model-builder-cf"
},
"split_keywords": [
"invenio",
"cf",
"model",
"builder"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "092e3ef0584b6edf3b2e23ea7bc94fb05a27e9e9b4d7eaba6e48a7386c00d669",
"md5": "ca91f76d9644039f71982757d89e02a8",
"sha256": "3edc13355ba079fbab1433b3a868dbb009d7f4788c2bbdba39f88f7fdd000d0a"
},
"downloads": -1,
"filename": "oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ca91f76d9644039f71982757d89e02a8",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.9",
"size": 9232,
"upload_time": "2024-08-24T19:18:30",
"upload_time_iso_8601": "2024-08-24T19:18:30.599527Z",
"url": "https://files.pythonhosted.org/packages/09/2e/3ef0584b6edf3b2e23ea7bc94fb05a27e9e9b4d7eaba6e48a7386c00d669/oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4c88fe05b9d54a15065989cfe3d4a8482a8d0d18a02133c6083d49915082b5fc",
"md5": "bf4bd70e245caed2f84750dab87dd2d2",
"sha256": "ca590a70cec738d4546cc75c792068e798ffffa7316e39bc06867397c5359b71"
},
"downloads": -1,
"filename": "oarepo_model_builder_cf-4.0.8.tar.gz",
"has_sig": false,
"md5_digest": "bf4bd70e245caed2f84750dab87dd2d2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 4598,
"upload_time": "2024-08-24T19:18:31",
"upload_time_iso_8601": "2024-08-24T19:18:31.866124Z",
"url": "https://files.pythonhosted.org/packages/4c/88/fe05b9d54a15065989cfe3d4a8482a8d0d18a02133c6083d49915082b5fc/oarepo_model_builder_cf-4.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-24 19:18:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oarepo",
"github_project": "oarepo-model-builder-cf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "oarepo-model-builder-cf"
}