Forum Discussion

btalebpour's avatar
btalebpour
Occasional Contributor
2 years ago

Where to add minItems and maxItems

I am trying to force only one item for my array parameter by setting minItems and maxItems to 1 but I couldn't make it work in the UI. It still lets me add more items. I tried to put these properties on different levels but still no luck. I also tried the specs without "content" and still the same result. Here is my parameters definition:

            "parameters": [
               {
                  "in": "query",
                  "name": "find",
                  "content": {
                     "application/json": {
                        "schema": {
                           "type": "array",
                           "items": {
                              "type": "object",
                              "minItems": 1,
                              "maxItems": 1,
                              "properties": {
                                 "$match": {
                                    "type": "object",
                                    "description": "To specify conditions to filter the result.",
                                    "default": {},
                                    "properties": {
                                       "name": {
                                          "type": "string",
                                          "description": "Name of the desired import"
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            ]
 
Another issue that I faced is that the "find" param is not sent as an array. I got error 503 (socket hang up):
Sent URL:
https://.../api/contact-service/v1/imports?find=%7B%0A%20%20%22%24match%22%3A%20%7B%7D%0A%7D&count=&limit=20&skip=0
This is the decoded value for find (the same object should have been an item of an array):
{
   "$match": {
      "name": "12234"
   }
}
 
And here is the actual definition that I executed the method with:
parameters:
  - in: query
    name: find
    schema:
    type: array
    items:
      type: object
      properties:
        $match:
          type: object
          description: To specify conditions to filter the result.
          default: {}
          properties:
            anyOf:
              -  name:
                 type: string
                 description: Name of the desired import
 
You are seeing anyOf because this param will have more properties that I haven't added yet.
No RepliesBe the first to reply