Skip to content

Commit

Permalink
jsonschemavalidate: Add format checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Nov 9, 2022
1 parent 6bf7b83 commit 8c2dbd3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- JSONSchema validate:
- Add format checkers

## [0.3.0] - 2022-11-08

### Added
Expand Down
5 changes: 4 additions & 1 deletion libcoveofds/jsonschemavalidate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from jsonschema import FormatChecker
from jsonschema.exceptions import ValidationError as JSONSchemaExceptionsValidationError
from jsonschema.validators import Draft202012Validator

Expand All @@ -9,7 +10,9 @@ def __init__(self, schema: OFDSSchema):
self._schema = schema

def validate(self, json_data: dict) -> list:
validator = Draft202012Validator(schema=self._schema.get_package_schema())
validator = Draft202012Validator(
schema=self._schema.get_package_schema(), format_checker=FormatChecker()
)
output = []
for e in validator.iter_errors(json_data):
output.append(ValidationError(e, json_data, self._schema))
Expand Down
1 change: 1 addition & 0 deletions make_expected_test_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ libcoveofds jtogj --outputmetafilename tests/fixtures/json_to_geojson/no_geometr

# JSON Schema validate
libcoveofds jsv tests/fixtures/jsonschemavalidate/basic_1.input.json > tests/fixtures/jsonschemavalidate/basic_1.expected.json
libcoveofds jsv tests/fixtures/jsonschemavalidate/bad_uuid_1.input.json > tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json

# Python validate
# TODO
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"message": "'1' is not a 'uuid'",
"path": [
"networks",
0,
"id"
],
"schema_path": [
"properties",
"networks",
"items",
"properties",
"id",
"format"
],
"validator": "format",
"data_ids": {
"network_id": "1"
}
}
]
13 changes: 13 additions & 0 deletions tests/fixtures/jsonschemavalidate/bad_uuid_1.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"networks": [
{
"id": "1",
"links": [
{
"rel": "describedby",
"href": "https://raw.githubusercontent.com/Open-Telecoms-Data/open-fibre-data-standard/0__1__0__beta/schema/network-schema.json"
}
]
}
]
}
2 changes: 2 additions & 0 deletions tests/test_jsonschemavalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
JSONSCHEMAVALIDATE_FILES = [
# basic example
("basic_1"),
# Bad data
("bad_uuid_1"),
]


Expand Down

0 comments on commit 8c2dbd3

Please sign in to comment.