Skip to content

Commit

Permalink
Merge pull request #261 from oarepo/krist/be-231-fix-apiuserdocs-to-r…
Browse files Browse the repository at this point in the history
…eturn-published-draft-user-documents

customizable args for record index field
  • Loading branch information
SilvyPuzzlewell authored Mar 21, 2024
2 parents 2f0b476 + d422e18 commit 3d4d2c3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions oarepo_model_builder/datatypes/components/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class ModelMappingSchema(ma.Schema):
metadata={"doc": "Mapping template, merged with generated mapping"},
)
skip = ma.fields.Boolean()
index_field_arguments = ma.fields.List(
ma.fields.String(),
data_key="index-field-arguments",
attribute="index-field-arguments",
metadata={"doc": "Other arguments for index field"},
)

class Meta:
unknown = ma.RAISE
Expand Down Expand Up @@ -89,3 +95,4 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
f"{short_index_name}.json",
),
)
mapping.setdefault("index-field-args", [])
5 changes: 4 additions & 1 deletion oarepo_model_builder/invenio/edtf_interval_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def get_paths(self, parent_node) -> Iterator[str]:
children = parent_node
for c in children:
node = children[c]
if node.model_type == "edtf-interval" or node.model_type == "edtf-time-interval":
if (
node.model_type == "edtf-interval"
or node.model_type == "edtf-time-interval"
):
yield self.to_path(node.path)
elif node.children != {}:
yield from self.get_paths(node.children)
Expand Down
4 changes: 3 additions & 1 deletion oarepo_model_builder/invenio/templates/record.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class {{ vars.record|class_header }}:
schema = ConstantField("$schema", "{{ settings.schema_server }}{{ vars.json_schema_settings.name }}")
{% endif %}
{% if not vars.mapping.skip %}
index = IndexField("{{ vars.mapping.index }}")
index = IndexField("{{ vars.mapping.index }}", {% if vars.mapping.index_field_args %}
{{ vars.mapping.index_field_args|generate_list }}
{% endif %})
{% endif %}
{% if not vars.pid.skip %}
pid = {{ vars.pid.field_class|base_name }}(
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.81
version = 4.0.82
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
1 change: 1 addition & 0 deletions tests/test_datatype_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def test_prepare_datatype():
"module": "my.test.records.mappings",
"index": "my_test_record-test-1.0.0",
"file": "my/test/records/mappings/os-v2/my_test_record/test-1.0.0.json",
"index-field-args": [],
},
"marshmallow": {
"generate": True,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_model_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def test_model_saver():
"module": "test.records.mappings",
"index": "test-test-1.0.0",
"file": "test/records/mappings/os-v2/test/test-1.0.0.json",
"index-field-args": [],
},
"marshmallow": {
"generate": True,
Expand Down Expand Up @@ -616,6 +617,7 @@ def test_model_saver_invenio():
"module": "test.records.mappings",
"index": "test-test-1.0.0",
"file": "test/records/mappings/os-v2/test/test-1.0.0.json",
"index-field-args": [],
},
"permissions": {
"generate": True,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_record_builder():
class TestRecord(InvenioRecord):
model_cls = TestMetadata
schema = ConstantField("$schema", "local://test-1.0.0.json")
index = IndexField("test-test-1.0.0")
index = IndexField("test-test-1.0.0",)
pid = PIDField(
provider=TestIdProvider,
context_cls=PIDFieldContext,
Expand Down Expand Up @@ -131,7 +131,7 @@ class TestIdProvider(RecordIdProviderV2):
class TestRecord(InvenioRecord):
model_cls = TestMetadata
schema = ConstantField("$schema", "local://test-1.0.0.json")
index = IndexField("test-test-1.0.0")
index = IndexField("test-test-1.0.0",)
pid = PIDField(
provider=TestIdProvider,
context_cls=PIDFieldContext,
Expand Down

0 comments on commit 3d4d2c3

Please sign in to comment.