Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to configure list params #580

Open
lukasbischof opened this issue May 31, 2024 · 1 comment
Open

Possibility to configure list params #580

lukasbischof opened this issue May 31, 2024 · 1 comment
Labels

Comments

@lukasbischof
Copy link

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?

@lsfera
Copy link

lsfera commented Nov 16, 2024

With a string array parameter, instead, there's no way the querystring is interpreted other than string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants