diff --git a/oarepo_model_builder/datatypes/components/marshmallow/field.py b/oarepo_model_builder/datatypes/components/marshmallow/field.py index 448fc2cc..24861c2d 100644 --- a/oarepo_model_builder/datatypes/components/marshmallow/field.py +++ b/oarepo_model_builder/datatypes/components/marshmallow/field.py @@ -70,6 +70,9 @@ def _marshmallow_field_arguments( self, datatype, section, marshmallow, field_name # NOSONAR ): arguments = copy.copy(marshmallow.get("arguments", [])) + required = datatype.definition.get('required', False) + if required: + arguments.append("required=True") read = marshmallow.get("read", True) write = marshmallow.get("write", True) if read and not write: diff --git a/setup.cfg b/setup.cfg index edde0f33..91f60b3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-model-builder -version = 4.0.22 +version = 4.0.23 description = A utility library that generates OARepo required data model files from a JSON specification file authors = Miroslav Bauer , Miroslav Simek readme = README.md diff --git a/tests/test_builder_from_entrypoints.py b/tests/test_builder_from_entrypoints.py index 6ef12303..f320c7ef 100644 --- a/tests/test_builder_from_entrypoints.py +++ b/tests/test_builder_from_entrypoints.py @@ -20,7 +20,7 @@ def test_include_invenio(): "record": { "module": {"qualified": "test"}, OAREPO_USE: "invenio", - "properties": {"a": {"type": "keyword"}}, + "properties": {"a": {"type": "keyword", "required": True}}, }, }, isort=False, @@ -56,7 +56,7 @@ class Meta: unknown = ma.RAISE - a = ma.fields.String() + a = ma.fields.String(required=True) """ ) == strip_whitespaces(data) @@ -73,7 +73,7 @@ class Meta: class TestUISchema(InvenioUISchema): class Meta: unknown = ma.RAISE - a = ma.fields.String() """ + a = ma.fields.String(required=True) """ ) in strip_whitespaces(data) ) diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py index dc85b8e0..a6d96db9 100644 --- a/tests/test_shortcuts.py +++ b/tests/test_shortcuts.py @@ -41,7 +41,7 @@ class Meta: unknown = ma.RAISE - a = ma.fields.List(ma.fields.String()) + a = ma.fields.List(ma.fields.String(), required=True) """ ) in strip_whitespaces(data)