Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added an initial schema #196

Merged
merged 3 commits into from
Feb 4, 2025
Merged

Conversation

marc-hanheide
Copy link
Member

@marc-hanheide marc-hanheide commented Feb 3, 2025

This pull request includes the addition of a new JSON schema for the topological map configuration. The schema defines the structure and validation rules for the topological map data.

Schema definition:

  • topological_navigation/config/tmap-schema.yaml: Added a new JSON schema to define the structure of the topological map configuration. The schema includes required properties such as meta, metric_map, name, nodes, and pointset, and specifies the types and validation rules for these properties.

I have used this little python code to test the validation:

(after pip install pyyaml jsonschema)

import yaml
from jsonschema import validate
import sys

def validate_yaml(schema_file, yaml_file):
    try:
        with open(schema_file, 'r') as f:
            schema = yaml.safe_load(f)
        
        with open(yaml_file, 'r') as f:
            data = yaml.safe_load(f)
            
        validate(instance=data, schema=schema)
        print("Validation successful!")
        
    except Exception as e:
        print(f"Validation error: {str(e)}")
        sys.exit(1)

if __name__ == "__main__":
    validate_yaml('schema.yaml', 'your_topo_map.yaml')

In particular, I have tested the validation against https://raw.githubusercontent.com/LCAS/environment_template/refs/heads/riseholme_park_farm_strawberry_polytunnels/config/topological/network.tmap2.yaml

This is a very forgiving schema, allowing additional elements and just ensures the basic structure of our tmap format:

Topological Map Schema Documentation

Required Top-Level Elements

The schema requires these root elements:

  • meta - Contains metadata
  • metric_map - String identifier for the metric map
  • name - String identifier for the map
  • nodes - Array of node objects
  • pointset - String identifier for the pointset

Additional properties allowed at the root level (like transformation).

Element Details

meta

Required properties:

  • last_updated - String in format "YYYY-MM-DD_HH-MM-SS"

nodes

Array of node objects, each requiring:

Node Object Structure

  1. meta object with required fields:

    • map (string)
    • node (string)
    • pointset (string)
    • Additional properties allowed
  2. node object with required fields:

    • edges (array of edge objects)
    • name (string)
    • parent_frame (string)
    • Additional properties allowed

Edge Object Structure

Each edge in the edges array requires:

  • edge_id (string)
  • node (string)
  • Additional properties allowed

Additional Property Rules

  • Root level: Additional properties allowed
  • Node objects: Additional properties allowed
  • Edge objects: Additional properties allowed
  • Meta objects: Additional properties allowed

@marc-hanheide
Copy link
Member Author

@Iranaphor @ibrahimhroob

We should use this schema, a) to better document our format, and b) to run automatic schema validation in https://github.com/LCAS/environment_template and derived repositories.

@marc-hanheide
Copy link
Member Author

should be possible to use this github workflow action: https://github.com/marketplace/actions/schema-validation-action for instance

@ibrahimhroob ibrahimhroob merged commit 3341501 into humble-dev Feb 4, 2025
2 checks passed
@ibrahimhroob ibrahimhroob deleted the marc-hanheide-patch-yaml-schema branch February 4, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants