Swagger: query params on POST methods not allowed?

838 views Asked by At

I've got a POST endpoint described in Swagger and I want that endpoint to also have query parameters. We're using 1.2 swagger format because, well, legacy reasons. We use 3scale, it hosts the documents and you edit your swagger in their web UI. However, when I try to save the document it gives me the following error.

JSON Spec can not have paramType='body' and paramType='query' on the same method

I can't find anything in the swagger specs that says this is an actual limitation. Is this likely something specific to 3Scale or is this a general swagger limitation? And if the latter, can someone point me at a spec is that clarifies it?

The actual REST endpoint doesn't care, it's happy with query params on a POST. It's just getting the Swagger tool to be happy. Here's the abbreviated snippet of the swagger doc:

{
  "parameters": [
    {
      "name": "myQueryParam",
      "dataType": "string",
      "paramType": "query",
      "required": true
    },
    {
      "name": "body",
      "dataType": "string",
      "paramType": "body",
      "required": true
    }
  ],
  "httpMethod": "POST"
}
2

There are 2 answers

0
Luca Mattia Ferrari On

not sure if the error message is a generic validation error, but there a couple of error in the specification you shared:

  • it is "method" and not "httpMethod"
  • it is "type" and not "dataType"

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md

0
Evgenii On

The following example works for me, but I use required=false:

 {
        "in": "query",
        "name": "myQueryParam",
        "required": false,
        "type": "string"
 }

See also Swagger parameters in query and/or body