mobie / mobie-utils-python

Python tools for MoBIE
MIT License
9 stars 5 forks source link

Validation fuzz #108

Open martinschorb opened 1 year ago

martinschorb commented 1 year ago

Hi,

I have some trouble with one of my projects and I try to find out what went wrong, as I only used mobie-python to generate it and it now does not validate any longer.

One big issue is that the output of the validation is not very helpful. It spits out the entire schema cluttering the STDOUT and throws an error only stating what went wrong. But is missing the crucial information where (which view/source etc.) the error occurs.

File ".../jsonschema/validators.py", line 1121, in validate
    raise error
jsonschema.exceptions.ValidationError: Additional properties are not allowed ('name' was unexpected)

Failed validating 'additionalProperties' in schema['properties']['views']['properties']['default']:
    {'$id': 'https://raw.githubusercontent.com/mobie/mobie.github.io/master/schema/view.schema.json',
     '$schema': 'http://json-schema.org/draft-07/schema',
     'additionalProperties': False,
     'definitions': {'additionalTables': {'description': 'Additional '
                                                         'tables to load '
                                                         'for this '
                                                         'display. This '
                                                         'only needs to be '
...

and hundreds of more lines of schema.

Is it possible to change the output such that it provides clues on where the problem is (i.e. where this suspicious extra name can be found?

constantinpape commented 1 year ago

These error messages are generated by the jsonschema library: https://github.com/python-jsonschema/jsonschema So I only have limited control over the validation error options. I haven't really looked into whether there they provide a way to simplify the validation messages. If you find one I am happy to adopt it here. If not you would need to raise the issue in the jsonschema repo.

martinschorb commented 1 year ago

makes sense. When you know what to look for (this information On instance['views']['default']:) You can find it. Can a JSON schema be nested (pulling content from other files)? Then maybe it would not display everything but only the relevant part of the schema... (like only from transformedGrid instead of the whole view schema)

martinschorb commented 1 year ago

and to complicate things, it seems that the CLI calls for mobie-python don´t pipe their STDOUT.

mobie.validate_project -i data > val.log

produces an empty file and still spits out everything.

constantinpape commented 1 year ago

produces an empty file and still spits out everything.

You have to pipe all output:

mobie.validate_project -i data > val.log 2>&1

(This writes both the output from std:out and std:err to the same stream)

constantinpape commented 1 year ago

Can a JSON schema be nested (pulling content from other files)? Then maybe it would not display everything but only the relevant part of the schema...

Yes, that should in principle be possible and would make sense to implement. (I am personally not able to do this in the foreseeable future, but would be happy to provide pointers if you want to give it a try).