Pre-commit hooks for validating generate_parameter_library YAML parameter files against JSON schemas.
- Validates YAML parameter files against the parameter schema
- Ensures proper structure and field names
- Optional validation of
additional_constraintsfield against UI schema (for React JSON Schema Form compatibility) - Includes all units from alpha schema-form
unitConversion.ts
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/Greenroom-Robotics/generate_parameter_library_pre_commit
rev: main # Use a specific tag/version in production
hooks:
- id: validate-parameter-schemaFor validation with UI schema (validates additional_constraints JSON content):
repos:
- repo: https://github.com/Greenroom-Robotics/generate_parameter_library_pre_commit
rev: main # Use a specific tag/version in production
hooks:
- id: validate-parameter-schema-with-uiThen install the hook:
pre-commit installInstall the package:
pip install git+https://github.com/Greenroom-Robotics/generate_parameter_library_pre_commit.gitRun the validator:
validate-parameter-schema path/to/parameters.yamlWith UI schema validation:
validate-parameter-schema --ui-schema path/to/parameters.yaml- YAML syntax: Ensures the file is valid YAML
- Single root element: The YAML must have exactly one root element (the namespace)
- Required fields: Each parameter must have a
typefield - Valid types: Type must be one of the supported parameter types
- Valid field names: Only recognized fields are allowed
- Nested structure: Validates nested parameter groups and mapped parameters
- Validation syntax: Ensures validation rules follow the correct structure
- Additional constraints (optional): When
--ui-schemais used, validates thatadditional_constraintscontains valid JSON conforming to React JSON Schema Form
The alpha_ui_schema.json defines the expected format for JSON content in the additional_constraints field. This is useful when using additional_constraints for UI metadata.
my_parameter:
type: double
default_value: 100.0
description: "Control loop frequency"
additional_constraints: '{"type": "number", "units": "hertz", "minimum": 1, "maximum": 1000}'All units from alpha schema-form unitConversion.ts:
- Angle: degrees, radians
- Angular Speed: degreesPerSecond, radiansPerSecond, revolutionsPerMinute
- Angular Acceleration: degreesPerSecondSquared, radiansPerSecondSquared
- Distance: meters, kilometers, nauticalMiles, miles, feet
- Linear Speed: metersPerSecond, knots, kilometersPerHour, milesPerHour
- Linear Acceleration: metersPerSecondSquared
- Temperature: celsius, fahrenheit, kelvin
- Pressure: pascal, bar, psi, atmosphere
- Time: milliseconds, seconds, minutes, hours
- Ratio: ratio, percent
- Frequency: hertz, secondsPeriod, millisecondsPeriod
The UI schema supports all standard React JSON Schema Form properties:
type,title,description,defaultenum,enumNames,constminimum,maximum,exclusiveMinimum,exclusiveMaximum,multipleOfminLength,maxLength,pattern,formatitems,minItems,maxItems,uniqueItemsproperties,required,additionalPropertiesoneOf,anyOf,allOf,notdependencies,readOnly,writeOnly
Plus the custom units field for physical unit conversion support.
[Add your license here]