fix(metadata): validate component metadata against current schemas (#28785)

The schema path still says component_information/, so --skip-if-no-schema makes the check a no-op. QGC only accepts parameter metadata version 1, while the schema floor rose for optional fields. Override that floor and keep emitting version 1.

Assisted-by: Grok:4.7

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-09-22 14:43:05 +12:00
1 parent 8c4262781d
commit e034dd91c5
4 files changed
+25 -2

No files matched your search

+10
View File
@@ -24,6 +24,8 @@ 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('--version-minimum', dest='version_minimum', type=int,
help='Replace the schema minimum of the top-level version field')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='Verbose Output')
@@ -39,6 +41,14 @@ if args.skip_if_no_schema and not os.path.isfile(schema_file):
with open(schema_file, 'r') as stream:
schema = json.load(stream)
if args.version_minimum is not None:
properties = schema.get('properties') if isinstance(schema, dict) else None
version_schema = properties.get('version') if isinstance(properties, dict) else None
if not isinstance(version_schema, dict) or 'minimum' not in version_schema:
print("Schema {:} has no top-level version minimum".format(schema_file))
sys.exit(1)
version_schema['minimum'] = args.version_minimum
# validate files
for json_file in json_files:
if verbose: print("Validating {:}".format(json_file))
@@ -88,12 +88,19 @@ add_custom_command(OUTPUT ${component_general_json} ${component_general_json}.xz
--compress
${comp_metadata_types}
--version-file ${PX4_BINARY_DIR}/src/lib/version/build_git_version.h
# Metadata stays at version 1 so QGC will load parameters. Schema floors rose for optional fields.
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/validate_json.py
--schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_metadata/general.schema.json
--version-minimum 1
${component_general_json}
--skip-if-no-schema # mavlink submodule might not exist for current target if built in CI
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_crc.py
${component_general_json}
${PX4_BINARY_DIR}/events/all_events.json.xz
--output ${component_information_header}
DEPENDS
generate_component_general.py
${PX4_SOURCE_DIR}/Tools/validate_json.py
${PX4_BINARY_DIR}/parameters.json.xz
parameters_xml
${PX4_BINARY_DIR}/events/all_events.json.xz
+4 -1
View File
@@ -46,8 +46,10 @@ add_custom_command(OUTPUT ${generated_actuators_metadata_file}
--compress
--board ${PX4_BOARD}
--output-file ${generated_actuators_metadata_file}
# Metadata stays at version 1 so QGC will load parameters. Schema floors rose for optional fields.
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/validate_json.py
--schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_information/actuators.schema.json
--schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_metadata/actuators.schema.json
--version-minimum 1
${generated_actuators_metadata_file}
--skip-if-no-schema # mavlink submodule might not exist for current target if built in CI
#--verbose
@@ -55,6 +57,7 @@ add_custom_command(OUTPUT ${generated_actuators_metadata_file}
${module_config_files}
${PX4_SOURCE_DIR}/Tools/module_config/generate_actuators_metadata.py
${PX4_SOURCE_DIR}/src/lib/mixer_module/output_functions.yaml
${PX4_SOURCE_DIR}/Tools/validate_json.py
COMMENT "Generating actuators.json"
)
add_custom_target(actuators_json DEPENDS ${generated_actuators_metadata_file})
+4 -1
View File
@@ -120,8 +120,10 @@ add_custom_command(OUTPUT ${parameters_xml} ${parameters_json} ${parameters_json
--board ${PX4_BOARD}
${READONLY_PARAMS_ARG}
#--verbose
# Metadata stays at version 1 so QGC will load parameters. Schema floors rose for optional fields.
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/validate_json.py
--schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_information/parameter.schema.json
--schema-file ${PX4_SOURCE_DIR}/src/modules/mavlink/mavlink/component_metadata/parameter.schema.json
--version-minimum 1
${parameters_json}
--skip-if-no-schema # mavlink submodule might not exist for current target if built in CI
#--verbose
@@ -135,6 +137,7 @@ add_custom_command(OUTPUT ${parameters_xml} ${parameters_json} ${parameters_json
px4params/xmlout.py
px4params/readonly_config.py
px_process_params.py
${PX4_SOURCE_DIR}/Tools/validate_json.py
COMMENT "Generating parameters.xml"
)
add_custom_target(parameters_xml DEPENDS ${parameters_xml})