0

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"
}
Chris Kessel
  • 5,583
  • 4
  • 36
  • 55
  • 1
    As far as I know, it's just a limitation from the Swagger Specification side. They also restrict passing a request body in a GET method. I don't see the point in having such restrictions cause use cases vary and it might not be enough to send in the required params as query params especially due to it's limitation in size. – Debargha Roy Oct 11 '20 at 16:48

2 Answers2

0

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

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

Evgenii
  • 3,283
  • 3
  • 27
  • 32