I'm using the following JSON schema which defines a list of users. I use the schema to register multiple users at a time.
I would like to know if there is a way to specify that each object in the JSON contains at least one property for registration?
Here is my schema:
{
"description":"Schema definition for the request to register",
"type":"object",
"properties":{
"registerRequests":{
"type":"array",
"items":{
"type":"object",
"properties":{
"user":{
"type":"object",
"properties":{
"age":{
"type":"integer",
"optional":true,
"minimum":1950,
"maximum":2100
},
"name":{
"type":"object",
"properties":{
"code":{
"type":"string",
"pattern":"^[\\w\\s!@#\\$%&\\-\\+=;:'\",\\.\\?\\(\\)\\\\/]{1,500}$"
},
"Desc":{
"type":"string",
"pattern":"^[\\w\\s!@#\\$%&\\-\\+=;:'\",\\.\\?\\(\\)\\\\/]{1,500}$"
}
},
"optional":true
}
}
}
}
}
}
},
"additionalProperties":false
}
My input request to register two users:
{
"registerRequests": [
{
"user": {
"age": "25",
"Desc": "Test"
}
},
{
"user": {
"age": "20"
}
}
]
}
Here I'm sending two user's information and each user object request contains at least one property. If I add a third object without any properties I want to restrict the request in the JSON itself saying at least one field is required on each user object. I'm looking for an attribute similar to pattern or optional .