Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/jsonschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
},
"required": ["id", "name"]
}
15 changes: 14 additions & 1 deletion frictionless/console/commands/__spec__/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion frictionless/console/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -136,7 +141,7 @@ def console_validate(
bytes=bytes,
fields=fields,
rows=rows,
schema=schema,
schema=schema_obj,
basepath=basepath,
detector=detector_obj,
)
Expand Down
5 changes: 5 additions & 0 deletions frictionless/console/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down