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

[Question] Custom format validator with constraints #142

Open
sitepark-veltrup opened this issue Sep 12, 2024 · 1 comment
Open

[Question] Custom format validator with constraints #142

sitepark-veltrup opened this issue Sep 12, 2024 · 1 comment

Comments

@sitepark-veltrup
Copy link

I would like to transfer form data in JSON. The file uploads should be specified in the Data URI schema. My JSON schema looks like this.

{
  "type" : "object",
  "properties" : {
    "upload" : {
      "type" : "string",
      "format" : "data-uri"
    }
  }
}

Here I can create my own validator via Custom Formats, which checks the format.

However, I would like to go even further and also have the validator check a maximum file size, for example, and could extend my schema for this:

{
  "type" : "object",
  "properties" : {
    "upload" : {
      "type" : "string",
      "format" : "data-uri",
      "maxFileSize" : 100000
    }
  }
}

My problem is that only the string is passed to the format validator, but I can't get to the schema and read out maxFileSize.

I have another case where I want to limit HTML to certain elements.

{
  "type" : "object",
  "properties" : {
    "text" : {
      "type" : "string",
      "format" : "html",
      "allowedElements" : ["p", "strong", "em","li", "ul", "ol"]
    }
  }
}

Is there any other way I could solve this? Or would it perhaps be a useful extension to provide the validator with the schema as well?

@sitepark-veltrup sitepark-veltrup changed the title [Question] Custom Format Validator with constraints [Question] Custom format validator with constraints Sep 12, 2024
@sorinsarca
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants