Skip to content

Commit

Permalink
Merge pull request #197 from oarepo/marshmallow_required
Browse files Browse the repository at this point in the history
marshmallow required field
  • Loading branch information
Alzpeta authored Jul 10, 2023
2 parents 2729524 + b8ffa97 commit dfba81e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down
6 changes: 3 additions & 3 deletions tests/test_builder_from_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,7 +56,7 @@ class Meta:
unknown = ma.RAISE
a = ma.fields.String()
a = ma.fields.String(required=True)
"""
)
== strip_whitespaces(data)
Expand All @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dfba81e

Please sign in to comment.