Add --jsonschema option to the validate CLI command - #1801
Open
Moferanoluwa wants to merge 1 commit into
Open
Conversation
Currently the CLI's --schema option expects a Frictionless Table Schema
descriptor; validating directly against a JSON Schema profile requires
converting it via Schema.from_jsonschema() first, with no way to do
that from the console command.
Add a --jsonschema option that takes a path to a JSON Schema profile
and converts it through the existing Schema.from_jsonschema() mapper
before it's used to validate the resource, e.g.:
frictionless validate table.csv --jsonschema schema.json
Fixes frictionlessdata#1500
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
Fixes #1500. As noted in the issue by @roll:
This adds exactly that: a
--jsonschemaoption on thevalidateconsole command that takes a path to a JSON Schema profile, runs it through the existingSchema.from_jsonschema()mapper, and uses the resulting Table Schema to validate the resource — mirroring how--schemaalready works, just with a JSON Schema source instead.Testing/Review Recommendations
frictionless validate table.csv --jsonschema schema.jsonagainst a JSON Schema requiring an integerid, with one row containing a non-numericid— correctly reportedINVALIDwith atype-erroron the right row/field, exit code 1.VALID, exit code 0.--schema-syncpaths.frictionless/console/commands/__spec__/test_validate.pysuite: 25 passed, 4 skipped (pre-existing skips, unrelated) before my change; 26 passed, 4 skipped after addingtest_console_validate_jsonschema_1500, which follows this file's existing pattern (compares CLI JSON output against callingvalidate()directly with the equivalent Python API).ruff format --checkandruff checkpass on all changed files.data/jsonschema.jsonas a small fixture (matchingdata/table.csv'sid/namecolumns) since the existingdata/ecrin.jsonJSON Schema fixture requires adisplay_titlefield that doesn't apply here.AI Usage
Resource.schemaalready acceptsUnion[Schema, str](confirming aSchemaobject could be passed directly with no other changes needed), and adding a test.frictionless/console/common.py,frictionless/console/commands/validate.py, its test file, and one new small JSON fixture.