Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Schema restrictions on Value field which can be Integer or String

I am currently having a JSON schema in my code

 {
    'type' => 'object', 'required' => true, 'additionalProperties' => false,
    'properties' => {
        'variables' => {
            'type' => 'array', 'required' => true,
            'items' => {
                'type' => 'object', 'required' => true, 'additionalProperties' => false,
                'properties' => {
                    'variable' => { 'type' => 'string', 'required' => true },
                    'value' => { 'required' => true }
                    }
                }
            }
        }
}

I am trying to put some extra validations here on value field. E.g. In case on String length should not be more than 64 chars , and in case of Integer value should be in Integer limit. how should I go about defining this schema.

like image 941
user2161522 Avatar asked Oct 23 '25 21:10

user2161522


1 Answers

For positive integer less or equal to 1024:

"type": "integer",
"minimum": 0,
"maximum": 1024

For string to be not empty and not longer than 64 symbols:

"type": "string",
"pattern": "^.{1,64}$"

There are good explanations of all the guards at official site.

like image 193
Aleksei Matiushkin Avatar answered Oct 25 '25 11:10

Aleksei Matiushkin