Beispiel #1
0
 def parse_json(schema_str: str):
     try:
         js = loads(schema_str)
         Draft7Validator.check_schema(js)
         assert "type" in js
         return TypedSchema(Draft7Validator(js), SchemaType.JSONSCHEMA)
     except (JSONDecodeError, SchemaError, AssertionError) as e:
         raise InvalidSchema from e
Beispiel #2
0
    def clean(self):
        """
        Validate the schema
        """
        super().clean()

        try:
            Draft7Validator.check_schema(self.data_schema)
        except SchemaError as e:
            raise ValidationError({"data_schema": e.message})

        if (type(self.data_schema) is not dict
                or "properties" not in self.data_schema
                or self.data_schema.get("type") != "object"):
            raise ValidationError({
                "data_schema":
                "Nautobot only supports context data in the form of an object and thus the "
                "JSON schema must be of type object and specify a set of properties."
            })
def test_input_schema_is_valid():
    Draft7Validator.check_schema(input_schema)