Skip to content

Add --jsonschema option to the validate CLI command - #1801

Open
Moferanoluwa wants to merge 1 commit into
frictionlessdata:mainfrom
Moferanoluwa:feat/validate-cli-jsonschema-option
Open

Add --jsonschema option to the validate CLI command#1801
Moferanoluwa wants to merge 1 commit into
frictionlessdata:mainfrom
Moferanoluwa:feat/validate-cli-jsonschema-option

Conversation

@Moferanoluwa

Copy link
Copy Markdown

Change Description

Fixes #1500. As noted in the issue by @roll:

It's not supported yet but I think it's a good idea something like:

frictionless validate table.csv --jsonschema <schema>

The mapper is already implemented so it will be a simple feature to add

This adds exactly that: a --jsonschema option on the validate console command that takes a path to a JSON Schema profile, runs it through the existing Schema.from_jsonschema() mapper, and uses the resulting Table Schema to validate the resource — mirroring how --schema already works, just with a JSON Schema source instead.

Testing/Review Recommendations

  • Installed the package locally (editable install) and ran it end-to-end:
    • frictionless validate table.csv --jsonschema schema.json against a JSON Schema requiring an integer id, with one row containing a non-numeric id — correctly reported INVALID with a type-error on the right row/field, exit code 1.
    • Same file with all-valid rows — VALID, exit code 0.
    • Confirmed no regression on the existing no-schema and --schema-sync paths.
  • Ran the full existing frictionless/console/commands/__spec__/test_validate.py suite: 25 passed, 4 skipped (pre-existing skips, unrelated) before my change; 26 passed, 4 skipped after adding test_console_validate_jsonschema_1500, which follows this file's existing pattern (compares CLI JSON output against calling validate() directly with the equivalent Python API).
  • ruff format --check and ruff check pass on all changed files.
  • Added data/jsonschema.json as a small fixture (matching data/table.csv's id/name columns) since the existing data/ecrin.json JSON Schema fixture requires a display_title field that doesn't apply here.

AI Usage

  • Tool: Claude Code (Claude Sonnet)
  • Type: Implementing the option, tracing how Resource.schema already accepts Union[Schema, str] (confirming a Schema object could be passed directly with no other changes needed), and adding a test.
  • Scope: frictionless/console/common.py, frictionless/console/commands/validate.py, its test file, and one new small JSON fixture.

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
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.

Cli validation against a jsonschema

1 participant