elixir-europe / biovalidator

JSON validator derived from AJV supporting ontology and taxonomy validation.
Apache License 2.0
19 stars 6 forks source link

[Requested feature] Providing Schema and Data in different files for a server instance #49

Closed M-casado closed 1 year ago

M-casado commented 1 year ago

Summary

A way for a user to send a REQUEST to a server with both the data and schema properties of the data.json file as independent files or arguments.

Motivation and details

In most validation attempts in our use-case, the schema is fixed from the very beginning, being a set of schemas one references. Therefore, it is more comfortable for the users if the data (data to validate) is a file on its own, and the schema can be another. This way, it is easier to organize the data files to be validated.

Furthermore, for me it seems that it would be easier to trace the validation attempts if I knew not just which data file, mixed, was used, but at the command level which schema and data files were used.

It is the same way it works for the command line interface, or even the user interface: two different arguments.

Use cases

Example 1

The schema is always the same, so I can re-use the same argument over and over, changing just the data file it refers to. If so, I would be able to use a similar command (completely made up in the example) each time, only changing the data_X.json file:

curl -F "schema=@schema.json" -F "data=@data_1.json" -H "Content-Type: application/json" -X POST "biovalidator.ega.ebi.ac.uk/validate"
curl -F "schema=@schema.json" -F "data=@data_2.json" -H "Content-Type: application/json" -X POST "biovalidator.ega.ebi.ac.uk/validate"
curl -F "schema=@schema.json" -F "data=@data_3.json" -H "Content-Type: application/json" -X POST "biovalidator.ega.ebi.ac.uk/validate"

Example 2

I have a referenced schema that is incredibly long, and it makes it difficult for me to edit the data easily, since the schema gets always in the way (visually, regular expressions, substitutions...). Having the schema in a file that I will not modify by myself, and being able to mass-produce the changes in the data files would be handy.

M-casado commented 1 year ago

Either that or the opposite: being able to give both the schema and data in a single file like one would do with the servers, in the command line mode.

It is just so that with a single batch of example JSON files one can test the server and local instances, instead of having to modify their formats to check one or the other. We could also agree, if it's troublesome to add this feature, to always have the data and schema within a single file, and for a user to do local validation they would need to set up the local server, instead of using it in "CLI mode".

theisuru commented 1 year ago

@M-casado would something like this will work?

curl 'localhost:3020/validate' -i -X POST \
-H 'Content-Type: application/json' \
-d "{
        \"schema\":$(<schema.json),
      \"data\":$(<data.json)
    }"
M-casado commented 1 year ago

Hi @theisuru, it does work. Nevertheless, we ended up adapting to Biovalidator's schema of data and schema upper level structure.

Perhaps the schema/data tip you shared may come handy some day, though.