0
$.paths["/inventory"].get.parameters.length

i did this query to select the parameters og a get request and it works how ever i want to put a condition on the length of the array so that i can say the /inventory get requests must have 2 parms and not more; something like this :

[($.paths["/inventory"].get.parameters.length == 3)]

this last query doesn't work it's just my imagination x)

here is the json sample:

{
  "openapi" : "3.0.0",
  "servers" : [ ],
  "info" : {
    "description" : "This is a simple API",
    "version" : "1.0.0",
    "title" : "ICP basic wallet",
    "contact" : {
      "email" : "you@your-company.com"
    },
    "license" : {
      "name" : "Apache 2.0",
      "url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "tags" : [ {
    "name" : "admins",
    "description" : "Secured Admin-only calls"
  }, {
    "name" : "developers",
    "description" : "Operations available to regular developers"
  } ],
  "paths" : {
    "/inventory" : {
      "get" : {
        "tags" : [ "developers" ],
        "summary" : "searches inventory",
        "operationId" : "searchInventory",
        "description" : "By passing in the appropriate options, you can search for\navailable inventory in the system\n",
        "parameters" : [ {
          "in" : "query",
          "name" : "searchString",
          "description" : "pass an optional search string for looking up inventory",
          "required" : false,
          "schema" : {
            "type" : "string"
          }
        }, {
          "in" : "query",
          "name" : "skip",
          "description" : "number of records to skip for pagination",
          "schema" : {
            "type" : "integer",
            "format" : "int32",
            "minimum" : 0
          }
        }, {
          "in" : "query",
          "name" : "limit",
          "description" : "maximum number of records to return",
          "schema" : {
            "type" : "integer",
            "format" : "int32",
            "minimum" : 0,
            "maximum" : 50
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "search results matching criteria",
            "content" : {
              "application/json" : {
                "schema" : {
                  "type" : "array",
                  "items" : {
                    "$ref" : "#/components/schemas/InventoryItem"
                  }
                }
              }
            }
          },
          "400" : {
            "description" : "bad input parameter"
          }
        }
      },
      "post" : {
        "tags" : [ "admins" ],
        "summary" : "adds an inventory item",
        "operationId" : "addInventory",
        "description" : "Adds an item to the system",
        "responses" : {
          "201" : {
            "description" : "item created"
          },
          "400" : {
            "description" : "invalid input, object invalid"
          },
          "409" : {
            "description" : "an existing item already exists"
          }
        },
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/InventoryItem"
              }
            }
          },
          "description" : "Inventory item to add"
        }
      }
    }
  },
  "components" : {
    "schemas" : {
      "InventoryItem" : {
        "type" : "object",
        "required" : [ "id", "name", "manufacturer", "releaseDate" ],
        "properties" : {
          "id" : {
            "type" : "string",
            "format" : "uuid",
            "example" : "d290f1ee-6c54-4b01-90e6-d701748f0851"
          },
          "name" : {
            "type" : "string",
            "example" : "Widget Adapter"
          },
          "releaseDate" : {
            "type" : "string",
            "format" : "date-time",
            "example" : "2016-08-29T09:12:33.001Z"
          },
          "manufacturer" : {
            "$ref" : "#/components/schemas/Manufacturer"
          }
        }
      },
      "Manufacturer" : {
        "required" : [ "name" ],
        "properties" : {
          "name" : {
            "type" : "string",
            "example" : "ACME Corporation"
          },
          "homePage" : {
            "type" : "string",
            "format" : "url",
            "example" : "https://www.acme-corp.com"
          },
          "phone" : {
            "type" : "string",
            "example" : "408-867-5309"
          }
        },
        "type" : "object"
      }
    }
  }
}
mhido art
  • 1
  • 1

1 Answers1

0

Vanilla JS can do it like this

const parms = obj.paths["/inventory"].get.parameters

if (parms.length<3) console.log("Too little parms")
else console.log(parms.length, "are enough parameters")
<script>
  const obj = {
    "openapi": "3.0.0",
    "servers": [],
    "info": {
      "description": "This is a simple API",
      "version": "1.0.0",
      "title": "ICP basic wallet",
      "contact": {
        "email": "you@your-company.com"
      },
      "license": {
        "name": "Apache 2.0",
        "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
      }
    },
    "tags": [{
      "name": "admins",
      "description": "Secured Admin-only calls"
    }, {
      "name": "developers",
      "description": "Operations available to regular developers"
    }],
    "paths": {
      "/inventory": {
        "get": {
          "tags": ["developers"],
          "summary": "searches inventory",
          "operationId": "searchInventory",
          "description": "By passing in the appropriate options, you can search for\navailable inventory in the system\n",
          "parameters": [{
            "in": "query",
            "name": "searchString",
            "description": "pass an optional search string for looking up inventory",
            "required": false,
            "schema": {
              "type": "string"
            }
          }, {
            "in": "query",
            "name": "skip",
            "description": "number of records to skip for pagination",
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          }, {
            "in": "query",
            "name": "limit",
            "description": "maximum number of records to return",
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 0,
              "maximum": 50
            }
          }],
          "responses": {
            "200": {
              "description": "search results matching criteria",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/InventoryItem"
                    }
                  }
                }
              }
            },
            "400": {
              "description": "bad input parameter"
            }
          }
        },
        "post": {
          "tags": ["admins"],
          "summary": "adds an inventory item",
          "operationId": "addInventory",
          "description": "Adds an item to the system",
          "responses": {
            "201": {
              "description": "item created"
            },
            "400": {
              "description": "invalid input, object invalid"
            },
            "409": {
              "description": "an existing item already exists"
            }
          },
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryItem"
                }
              }
            },
            "description": "Inventory item to add"
          }
        }
      }
    },
    "components": {
      "schemas": {
        "InventoryItem": {
          "type": "object",
          "required": ["id", "name", "manufacturer", "releaseDate"],
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid",
              "example": "d290f1ee-6c54-4b01-90e6-d701748f0851"
            },
            "name": {
              "type": "string",
              "example": "Widget Adapter"
            },
            "releaseDate": {
              "type": "string",
              "format": "date-time",
              "example": "2016-08-29T09:12:33.001Z"
            },
            "manufacturer": {
              "$ref": "#/components/schemas/Manufacturer"
            }
          }
        },
        "Manufacturer": {
          "required": ["name"],
          "properties": {
            "name": {
              "type": "string",
              "example": "ACME Corporation"
            },
            "homePage": {
              "type": "string",
              "format": "url",
              "example": "https://www.acme-corp.com"
            },
            "phone": {
              "type": "string",
              "example": "408-867-5309"
            }
          },
          "type": "object"
        }
      }
    }
  }
</script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236