diff --git a/data/jsonschema.json b/data/jsonschema.json new file mode 100644 index 0000000000..f355d8c704 --- /dev/null +++ b/data/jsonschema.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "id": { "type": "integer" }, + "name": { "type": "string" } + }, + "required": ["id", "name"] +} diff --git a/frictionless/console/commands/__spec__/test_validate.py b/frictionless/console/commands/__spec__/test_validate.py index 7e71bfd7a9..41f40a0ec0 100644 --- a/frictionless/console/commands/__spec__/test_validate.py +++ b/frictionless/console/commands/__spec__/test_validate.py @@ -3,7 +3,7 @@ import pytest import yaml -from frictionless import Detector, Dialect, validate +from frictionless import Detector, Dialect, Schema, validate from frictionless.console import console from .conftest import create_runner @@ -69,6 +69,19 @@ def test_console_validate_field_names(): assert no_time(json.loads(actual.stdout)) == no_time(expect.to_descriptor()) +def test_console_validate_jsonschema_1500(): + actual = runner.invoke( + console, + "validate data/table.csv --json --jsonschema data/jsonschema.json", + ) + expect = validate( + "data/table.csv", + schema=Schema.from_jsonschema("data/jsonschema.json"), + ) + assert actual.exit_code == 0 + assert no_time(json.loads(actual.stdout)) == no_time(expect.to_descriptor()) + + def test_console_validate_field_missing_values(): actual = runner.invoke( console, diff --git a/frictionless/console/commands/validate.py b/frictionless/console/commands/validate.py index 41d5cbc7f9..8cef072a53 100644 --- a/frictionless/console/commands/validate.py +++ b/frictionless/console/commands/validate.py @@ -6,6 +6,7 @@ from rich.table import Table from ...resource import Resource +from ...schema import Schema from ...system import system from .. import common, helpers from ..console import console @@ -25,6 +26,7 @@ def console_validate( innerpath: str = common.innerpath, compression: str = common.compression, schema: str = common.schema, + jsonschema: str = common.jsonschema, hash: str = common.hash, bytes: int = common.bytes, fields: int = common.fields, @@ -121,6 +123,9 @@ def console_validate( skip_errors=skip_errors, ) + # Create schema + schema_obj = Schema.from_jsonschema(jsonschema) if jsonschema else schema + # Create resource resource = Resource( source=helpers.create_source(source), @@ -136,7 +141,7 @@ def console_validate( bytes=bytes, fields=fields, rows=rows, - schema=schema, + schema=schema_obj, basepath=basepath, detector=detector_obj, ) diff --git a/frictionless/console/common.py b/frictionless/console/common.py index 2cb4e21c0e..1e29633072 100644 --- a/frictionless/console/common.py +++ b/frictionless/console/common.py @@ -126,6 +126,11 @@ help="Specify a path to a schema", ) +jsonschema = Option( + default=None, + help="Specify a path to a JSON Schema profile (converted to a Table Schema)", +) + # Checklist checklist = Option(