commissaire icon indicating copy to clipboard operation
commissaire copied to clipboard

Port Model Validation to use jsonschema

Open ashcrow opened this issue 9 years ago • 1 comments

Our current model implementation uses a custom validation scheme which can be confusing to folks just jumping in to the code. jsonschema provides a standard way to validate data. Since our underlying transport ends up being json it seems like a perfect fit as noted by @mbarnes.

Library: https://pypi.python.org/pypi/jsonschema

Cluster Model Schema Example

Note: The example isn't tested :grin:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "status": {"type": "string"},
        "type": {"type": "string"},
        "network": {"type": "string"},
        "hostset": {
            "type": "array",
            "items": {
                "pattern": "^[a-zA-Z0-9\:\.\-_]*$",
                "type": "string"
            }
    }
}

ashcrow avatar Oct 18 '16 14:10 ashcrow

Agree. jsonschema seems like a good choice to validate data.

gbraad avatar Nov 02 '16 03:11 gbraad