Skip to content

Commit

Permalink
Switch to using fastjsonschema for schema validation. (#809)
Browse files Browse the repository at this point in the history
The main reason to do this is because jsonschema (what
we currently use) depends on referencing, which depends
on rpds-py, which has C libraries.  That means that when
using the python debug interpreter on Windows, we would
have to build a custom pip package for it to work.

In contrast, fastjsonschema is pure python and has no
dependencies.  It is also available on all of our default
platforms.  So switch to using it here so things work on
Windows debug.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette authored Jun 13, 2024
1 parent 57940a2 commit f25110b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rosidl_generator_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_index_python</test_depend>
<test_depend>python3-jsonschema</test_depend>
<test_depend>python3-fastjsonschema</test_depend>
<test_depend>rosidl_cmake</test_depend>
<test_depend>rosidl_generator_c</test_depend>
<test_depend>rosidl_generator_cpp</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
from pathlib import Path

from ament_index_python import get_package_share_directory
import jsonschema
import fastjsonschema


def test_type_hash():
"""Test all rosidl_generator_type_description output files against defined schemas."""
schema_path = (
Path(get_package_share_directory('rosidl_generator_type_description')) / 'resource' /
'HashedTypeDescription.schema.json')

with schema_path.open('r') as schema_file:
schema = json.load(schema_file)
validator = fastjsonschema.compile(schema)

generated_files_dir = Path(os.environ['GENERATED_TEST_FILE_DIR'])
validated_files = 0
Expand All @@ -36,6 +38,6 @@ def test_type_hash():
assert p.suffix == '.json'
with p.open('r') as f:
instance = json.load(f)
jsonschema.validate(instance=instance, schema=schema)
validator(instance)
validated_files += 1
assert validated_files, 'Needed to validate at least one JSON output.'

0 comments on commit f25110b

Please sign in to comment.