Skip to content

Conversation

@Nathanjp91
Copy link
Contributor

@Nathanjp91 Nathanjp91 commented Dec 19, 2022

Exposes a new CLI function

darwin validate location
where location is a single file or a folder to recursively search for *.json files

glob style pattern based search
--pattern PATTERN

will print to the console each file checked and pass/fail + list of errors found on failed files
optional flags to turn off console printing for successful files
--silent
and a flag to specify an output file to save the result
--output OUTPUT

Changes to code base:
jsonschema had to be updated to support the draft202012Validator used for darwin v2 schema which was introduced in a later version than what the repo was based on. This unfortunately changes a range of tests and needed to be updated to keep in line with the Exception changes

Copy link
Contributor

@owencjones owencjones left a comment

Choose a reason for hiding this comment

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

Looks good, no required changes, except the double backticks for the Sphinx docs, the rest are just me being picky 😉

_error(str(e))
except UnrecognizableFileEncoding as e:
_error(str(e))
except UnknownAnnotationFileSchema as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

except NotFound as e:
_error(f"No dataset with name '{e.name}'")
except:
_error(f"An error has occurred, please try again later.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not your code, but f-string with no placeholders, could remove.

filename for saving to output, by default None
"""
if not files and not folder and not pattern:
# TODO insert logging here once we introduce that
Copy link
Contributor

Choose a reason for hiding this comment

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

In the meantime, this is a CLI command, so move L974 above this and

Suggested change
# TODO insert logging here once we introduce that
console.log('--files or --folder flag requires a pattern')

to give the user firm output on their issue?

https://rich.readthedocs.io/en/stable/console.html#attributes - Rich has a lot of stuff for this, and it can be handy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also pretty sure that the argparse parsing actually makes this condition impossible, but handling it is good to avoid someone breaking it in future.

except MissingSchema as e:
errors = [e]
all_errors[str(file)] = [str(error) for error in errors]
if len(errors) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as putting

if not errors:

Parameters
----------
parent_error: ValidationError
Error reported by `jsonschema`.
Copy link
Contributor

Choose a reason for hiding this comment

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

For Sphinx docs, we need to use double backticks.

Nathanjp91 and others added 3 commits January 3, 2023 12:08
Co-authored-by: Owen Jones <owencjones+github@gmail.com>
Copy link
Contributor

@rslota rslota left a comment

Choose a reason for hiding this comment

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

I'm not a fun of the --file / --folder flags tbh. It's not consistent with our other commands in CLI which detect automatically if user provided a file or a folder.
Ideally users could just do the same as they do with import, but just changing import to validate in the shell and get validation, without looking at other things they need to provide for commend to work. It feels like making user decide between file and folder is just worse UX, as it's not like the argument is ambiguous. As long it's not a pattern, we can detect if it's a folder or file. Pattern could stay more complex case, for those wanting to use it.
What do you think @Nathanjp91 @owencjones ?

Let's also amend the PR title to include ticket code and [extenal] tag please 🙏

Also, the validation doesn't feel verbose enough. For example, I made a typo in one of the fields in my 100k line JSON and I got:
Screenshot 2023-01-09 at 20 52 43
As user, I would have no clue which name this is referring to. OpenAPI is capable printing very good location of the errors and we really should include that, otherwise it's pretty hard to know which of 20k annotations contains the bug.

Copy link
Contributor

@rslota rslota left a comment

Choose a reason for hiding this comment

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

LGTM!

@Nathanjp91 Nathanjp91 merged commit 1abb259 into master Jan 19, 2023
@Nathanjp91 Nathanjp91 deleted the validation branch February 13, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants