2

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 .

4

1 回答 1

0

好的,对此的回答很晚,但是...

直到并包括草案 v3,没有。

使用 v4 草案(即将发布),是的:"minProperties": 1.

于 2013-01-09T11:43:41.310 回答