Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a parameter set and reference it?

I have multiple parameters that I want to reference, but I do not want to specify them one by one.

This snippet does not make the parameters show up:

{
    ...
    "paths": {
        "/stuff": {
            "get": {
                "description": "Gets stuff",
                "operationId": "getStuff",
                "parameters": {
                    "$ref": "#/definitions/set1"
                }
            }
        }
    },
    "parameters": {
        "a": {
            "name": "a",
            "in": "query",
            "description": "Param A",
            "required": false,
            "type": "string"
        },
        "b": {
            "name": "b",
            "in": "query",
            "description": "Param B",
            "required": false,
            "type": "string"
        }
    },
    "definitions": {
        "set1": [
            {
                "$ref": "#/parameters/a"
            },
            {
                "$ref": "#/parameters/b"
            }
       ],
       "set2": ...
    }
}

Is this possible or do I have to specify each parameter like set1, for each request?

like image 561
Arc Avatar asked Apr 29 '15 16:04

Arc


1 Answers

Indeed that's not a valid definition and as you suggested, you'd have to specify each parameter separately by referencing the global one. If your parameters are shared for all operations under a specific path, you can define those at the path level and they would be applied to all operations.

For an individual operation, you'd define it as:

"paths": {
  "/stuff": {
    "get": {
      "description": "Gets stuff",
      "operationId": "getStuff",
      "parameters": [
        {
          "$ref": "#/parameters/a"
        },
        {
          "$ref": "#/parameters/b"
        }
      ]
    }
  }
}
like image 133
Ron Avatar answered Oct 12 '22 19:10

Ron