imposter icon indicating copy to clipboard operation
imposter copied to clipboard

Possibility to configure list params

Open lukasbischof opened this issue 1 year ago • 1 comments

When I have an OpenAPI spec that accepts a list as parameter:

{
  "openapi": "3.1.0",
  "info": { [...] },
  "paths": {
    "/test": {
      "get": {
        "summary": "Some request",
        "operationId": "test",
        "parameters": [
          {
            "name": "ids",
            "in": "query",
            "description": "All the IDs",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "responses": { [...] }
      }
    }
  }
}

using a configuration that validates the requests:

---
plugin: openapi
specFile: test.json

validation:
  request: true

resources:
  - path: /test
    method: GET
    response:
      scriptFile: script.js  # Content: console.log(context.request.queryParams);

The only way I can make the list parameter work as expected is by wrapping it in [] braces:

curl -v 'http://localhost:8080/test?ids=\[1,2\]'

Other list types like the ones specified in https://www.rfc-editor.org/rfc/rfc6570#section-3.2.9 or the commonly used param[]= style either don't pass the validation, raise an error or don't parse the list as expected

curl -v 'http://localhost:8080/test?ids=1,2'
# => Exception Unable to parse JSON - Unexpected character (',' (code 44)): Expected space separating root-level values
#        at [Source: (String)"1,2"; line: 1, column: 3]

curl -v "http://localhost:8080/test?ids=1&ids=2"
# => logs: {ids=2} --> 1 is missing

curl -v "http://localhost:8080/test?ids[]=1&ids[]=2"
# => Validation error: Query parameter 'ids' is required on path '/test' but not found in request.

Is there a way that I can support the other styles without getting a validation issue?

lukasbischof avatar May 31 '24 13:05 lukasbischof