Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a mapping for the fields.Method #175

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions invenio_administration/marshmallow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
fields.Date: "date",
fields.TimeDelta: "timedelta",
fields.Decimal: "decimal",
# TODO: This is needed for the is_current_user in the administration
# of the user resources. It might be better to implement also a handler for this.
# See https://github.com/inveniosoftware/invenio-administration/issues/174
fields.Method: None,
Copy link
Member

@ppanero ppanero Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: how does jsonschema behaves with None or null as type? This value will be used below

schema_dict[field].update({
                    "type": custom_mapping[field_type_name],
                })

We might need to add a check in the jsonify_schema function. Or tests....

(edit) if fails...

>>> from jsonschema import validate
>>>
>>> schema = {
...       "type" : "object",
...       "properties" : {
...           "price" : {"type" : "number"},
...           "name" : {"type" : None},
...       },
...   }
>>>
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ppanero/.virtualenvs/invenio-rdm-migrator/lib/python3.9/site-packages/jsonschema/validators.py", line 1117, in validate
    cls.check_schema(schema)
  File "/Users/ppanero/.virtualenvs/invenio-rdm-migrator/lib/python3.9/site-packages/jsonschema/validators.py", line 231, in check_schema
    raise exceptions.SchemaError.create_from(error)
jsonschema.exceptions.SchemaError: None is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['allOf'][1]['properties']['properties']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['type']:
    {'anyOf': [{'$ref': '#/$defs/simpleTypes'},
               {'items': {'$ref': '#/$defs/simpleTypes'},
                'minItems': 1,
                'type': 'array',
                'uniqueItems': True}]}

On schema['properties']['name']['type']:
    None

# invenio fields
invenio_fields.SanitizedUnicode: "string",
invenio_fields.links.Links: "array",
Expand Down