Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Schema - validate pattern for string inside an array is ignored

I have a schema defined this way:

"permissions": {
          "type": "array",
            "properties": {
               "items":
                 {
                   "$ref": "#/definitions/permissionsType"
                 }
            }
        },

and permissionsType:

"permissionsType": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9]+(:[a-zA-Z0-9][a-zA-Z0-9-]+)+$"
    },

...

I am not sure why the pattern regex is ignored.

like image 372
Adam Bielecki Avatar asked Sep 20 '25 00:09

Adam Bielecki


1 Answers

Remove the properties keyword and it will work as expected.

I'm not sure what you're trying to do with the properties keyword here. properties only applies when the instance being validated is an object. Because the instance is an array, properties is ignored. If the instance were an object, the properties keyword would apply, but it would be expecting an object with a property name "items" that matches #/definitions/permissionsType. I don't think that's what you meant. I think you wanted an array whose items all match #/definitions/permissionsType.

"permissions": {
  "type": "array",
  "items": { "$ref": "#/definitions/permissionsType" }
}
like image 103
Jason Desrosiers Avatar answered Sep 22 '25 21:09

Jason Desrosiers