I am trying to create a json schema and validate it using the standard validation base class. I get this error message which I can't tell what it refers to exactly.
Looking at my schema and value I don't see anywhere where I have an empty space in the parameter names and I'm not sure what the index 38 reffers to.
The schema that I provide is:
# value = {'enabled': -1, 'order_index': 0, 'width': 10}
# schema = {
'title': 'The Test column schema',
'type': 'object',
'required': ['enabled', 'order_index', 'width'],
'default': {'enabled': True, 'order_index': 0, 'width': 10},
'properties':
{'enabled':
{'title': 'Enabled',
'description': 'Display of column',
'type': 'boolean'
},
'order_index':
{'title': 'Order Index',
'description': 'Order of column to be displayed',
'type': 'number',
'minimum': 0,
'maximum': 999,
'default': 0
},
'width':
{'title': 'Width',
'description': 'Width of column to be displayed',
'type': 'number',
'minimum': 10,
'maximum': 999,
'default': 30}}}
validate_schema = JSONSchemaValidator(limit_value=schema)
validate_schema(value)
Where JSONSchemaValidator is an inheritor of the Django.BaseValidator
class JSONSchemaValidator(BaseValidator):
def compare(self, a, b):
try:
jsonschema.validate(a, b)
except jsonschema.exceptions.ValidationError as e:
raise ValidationError(
"Failed JSON schema check for %(value). {}".format(str(e)), params={"value": a}
)
CodePudding user response:
I'd change the schema default
value from True
to true
.
'default': {'enabled': true, 'order_index': 0, 'width': 10},
CodePudding user response:
As it turns out my error was not in my code but an exception in django failing to format a string.