gdcc / pyDataverse

Python module for Dataverse Software (dataverse.org).
http://pydataverse.readthedocs.io/
MIT License
63 stars 41 forks source link

json Validator Fails when License is included #161

Open shlake opened 8 months ago

shlake commented 8 months ago

Bug report

dataset-finch1.json

When including license information in a dataset json file (see the above attached file), the file does not validate.

1. Describe your environment

2. Actual behaviour:

When reading in a dataset json file ds.from_json(read_file(ds_filename)) (the one attached to this issue), I get the following errors:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sah/Library/Python/3.9/lib/python/site-packages/pyDataverse/models.py", line 855, in from_json
    validate_data(json_dict, filename_schema, file_format="json")
  File "/Users/sah/Library/Python/3.9/lib/python/site-packages/pyDataverse/utils.py", line 451, in validate_data
    validate(instance=data, schema=read_json(filename_schema))
  File "/Users/sah/Library/Python/3.9/lib/python/site-packages/jsonschema/validators.py", line 1302, in validate
    raise error
jsonschema.exceptions.ValidationError: {'name': 'CC0 1.0', 'uri': 'http://creativecommons.org/publicdomain/zero/1.0'} is not of type 'string'

Failed validating 'type' in schema['properties']['datasetVersion']['properties']['license']:
    {'$id': '#/properties/datasetVersion/properties/license',
     'type': 'string'}

On instance['datasetVersion']['license']:
    {'name': 'CC0 1.0',
     'uri': 'http://creativecommons.org/publicdomain/zero/1.0'}

3. Expected behaviour:

This file does successfully create a dataset with the correct license when using the API via command line (curl). This command works:

curl -H "X-Dataverse-key:$API_TOKEN" -X POST "$SERVER_URL/api/dataverses/$PARENT/datasets" --upload-file dataset-finch1.json -H 'Content-type:application/json

pdurbin commented 8 months ago

Also discussed here: https://dataverse.zulipchat.com/#narrow/stream/378866-troubleshooting/topic/Validation.20Errors.20Creating.20a.20Dataset.20w.2F.20pyDataverse/near/399798357

Thanks, for opening this issue, Sherry!

pdurbin commented 8 months ago

Oh and on a related note, you and @JR-1991 might be interested in the new JSON Schema in this issue: