Skip to content

Greenroom-Robotics/generate_parameter_library_pre_commit

Repository files navigation

Generate Parameter Library Pre-commit Hooks

Pre-commit hooks for validating generate_parameter_library YAML parameter files against JSON schemas.

Features

  • Validates YAML parameter files against the parameter schema
  • Ensures proper structure and field names
  • Optional validation of additional_constraints field against UI schema (for React JSON Schema Form compatibility)
  • Includes all units from alpha schema-form unitConversion.ts

Installation

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-schema

For 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-ui

Then install the hook:

pre-commit install

Standalone Usage

Install the package:

pip install git+https://github.com/Greenroom-Robotics/generate_parameter_library_pre_commit.git

Run the validator:

validate-parameter-schema path/to/parameters.yaml

With UI schema validation:

validate-parameter-schema --ui-schema path/to/parameters.yaml

What It Validates

  1. YAML syntax: Ensures the file is valid YAML
  2. Single root element: The YAML must have exactly one root element (the namespace)
  3. Required fields: Each parameter must have a type field
  4. Valid types: Type must be one of the supported parameter types
  5. Valid field names: Only recognized fields are allowed
  6. Nested structure: Validates nested parameter groups and mapped parameters
  7. Validation syntax: Ensures validation rules follow the correct structure
  8. Additional constraints (optional): When --ui-schema is used, validates that additional_constraints contains valid JSON conforming to React JSON Schema Form

Alpha UI Schema

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.

Example

my_parameter:
  type: double
  default_value: 100.0
  description: "Control loop frequency"
  additional_constraints: '{"type": "number", "units": "hertz", "minimum": 1, "maximum": 1000}'

Supported Units

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

React JSON Schema Form Compatibility

The UI schema supports all standard React JSON Schema Form properties:

  • type, title, description, default
  • enum, enumNames, const
  • minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf
  • minLength, maxLength, pattern, format
  • items, minItems, maxItems, uniqueItems
  • properties, required, additionalProperties
  • oneOf, anyOf, allOf, not
  • dependencies, readOnly, writeOnly

Plus the custom units field for physical unit conversion support.

License

[Add your license here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages