django-jsonform icon indicating copy to clipboard operation
django-jsonform copied to clipboard

Add schema validator

Open nicokant opened this issue 9 months ago • 1 comments

I know that this my sound crazy, but I was wondering if somewhere in the source code there is a json schema that validates that the json object/dict used in JSONField(schema=SCHEMA).

My use case is: I want to create a form that is able to output valid json schema forms for this library. Such schemas can later be referenced by other models.

class Schema(models.Model):
  name = models.CharField()
  schema = JSONField(schema=JSONFORM_SCHEMA)

def get_schema(instance):
  if not instance:
    return {}
  return instance.schema.schema

class AnotherModel(models.Model):
  schema = models.ForeignKey('Schema', on_delete=model.PROTECT)
  data = JSONField(schema=get_schema, default=dict)

nicokant avatar Mar 27 '25 09:03 nicokant

At present there's no validator the schema on the server side. However, the schema does get validated in the browser by the JS component.

But, yes, I agree that we should have a schema validator on the server. I'll try to add this but it may not happen before a couple of weeks.

bhch avatar Mar 27 '25 15:03 bhch