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

Make the Catmandu::Validator part of the command line tools #274

Open
phochste opened this issue Oct 31, 2016 · 4 comments
Open

Make the Catmandu::Validator part of the command line tools #274

phochste opened this issue Oct 31, 2016 · 4 comments

Comments

@phochste
Copy link
Member

E.g. something like

$ catmandu import JSON to MongoDB with JSONSchema --schema data/myschema.json < data.json

This will send all items, after optional fixes, before being stored in MongoDB, through a JSONSchema validator and reject any records that are not valid.

@nics
Copy link
Member

nics commented Mar 20, 2017

This will probably be implemented as a fix condition

@nics
Copy link
Member

nics commented Mar 21, 2017

dev has a new Fix::Condition::validate

@nics nics closed this as completed Mar 21, 2017
@nichtich
Copy link
Member

nichtich commented Feb 22, 2018

Validation is still complicated to set up. Workflows based on validation results can be created with fixes but the basic use case "are these records valid or not (and if not why)?" is still difficult to set up. The best I could find is:

catmandu convert JSON to JSON --fix "validate('', JSONSchema, schema: schema.json); retain(errors)" < data.json

But the exit code is not set on validation error. A dedicated validate command should be useful for instance like this:

catmandu validate JSON with JSONSchema --schema schema.json < data.json

This requires a way to throw custom errors from a fix as implemented in #334. With this fix, the validate command could be a shortcut for such fix:

 validate('author', JSONSchema, schema: 'my/schema.json')
 if exists(errors) join(errors,"\n"); error($.errors) end

If no errors are found, I expect no output (Null exporter), otherwise error exit code.

@nichtich
Copy link
Member

Validating on the command line is also not feasible because the error fix will quit immediately. Validating a single record works this way:

catmandu convert Null to JSON -fix 'validate(.,Mock,reject:1);if exists(errors) join(errors,"\n");error($.errors) end' || echo ERROR

Same with validate command could be:

catmandu validate Null with Mock --reject 1 || echo ERROR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants