From 312d84ca23fa4084dd57d1161e4b5055dbf8c7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 11 Nov 2021 11:41:42 +0100 Subject: [PATCH] metadata: run json schema validation for actuators + parameter metadata --- Tools/validate_json.py | 6 ++++++ src/lib/metadata/CMakeLists.txt | 5 +++++ src/lib/parameters/CMakeLists.txt | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/Tools/validate_json.py b/Tools/validate_json.py index 98affc3d37..b80dad3198 100755 --- a/Tools/validate_json.py +++ b/Tools/validate_json.py @@ -5,6 +5,7 @@ https://json-schema.org/""" import argparse import sys import json +import os try: from jsonschema import validate @@ -21,6 +22,8 @@ parser = argparse.ArgumentParser(description='Validate JSON file(s) against a sc parser.add_argument('json_file', nargs='+', help='JSON config file(s)') parser.add_argument('--schema-file', type=str, action='store', help='JSON schema file', required=True) +parser.add_argument('--skip-if-no-schema', dest='skip_if_no_schema', action='store_true', + help='Skip test if schema file does not exist') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Verbose Output') @@ -29,6 +32,9 @@ schema_file = args.schema_file json_files = args.json_file verbose = args.verbose +if args.skip_if_no_schema and not os.path.isfile(schema_file): + sys.exit(0) + # load the schema with open(schema_file, 'r') as stream: schema = json.load(stream) diff --git a/src/lib/metadata/CMakeLists.txt b/src/lib/metadata/CMakeLists.txt index 719c1483ca..8b48d881d2 100644 --- a/src/lib/metadata/CMakeLists.txt +++ b/src/lib/metadata/CMakeLists.txt @@ -46,6 +46,11 @@ add_custom_command(OUTPUT ${generated_actuators_metadata_file} --compress --board ${PX4_BOARD} --output-file ${generated_actuators_metadata_file} + COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/validate_json.py + --schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_information/actuators.schema.json + ${generated_actuators_metadata_file} + --skip-if-no-schema # mavlink submodule might not exist for current target if built in CI + #--verbose DEPENDS ${module_config_files} ${PX4_SOURCE_DIR}/Tools/module_config/generate_actuators_metadata.py diff --git a/src/lib/parameters/CMakeLists.txt b/src/lib/parameters/CMakeLists.txt index d9254c0826..b8f91e41be 100644 --- a/src/lib/parameters/CMakeLists.txt +++ b/src/lib/parameters/CMakeLists.txt @@ -117,6 +117,11 @@ add_custom_command(OUTPUT ${parameters_xml} ${parameters_json} ${parameters_json --overrides ${PARAM_DEFAULT_OVERRIDES} --board ${PX4_BOARD} #--verbose + COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/validate_json.py + --schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_information/parameter.schema.json + ${parameters_json} + --skip-if-no-schema # mavlink submodule might not exist for current target if built in CI + #--verbose DEPENDS ${param_src_files} ${generated_serial_params_file}