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

Array query parameters wrapped in anyOf do not work for single element queries #2675

Open
Arskah opened this issue Mar 13, 2025 · 0 comments

Comments

@Arskah
Copy link

Arskah commented Mar 13, 2025

If array query parameter is wrapped inside anyOf, it does not behave similar to non-wrapped parameter when querying for single elements.

https://github.com/Arskah/prism-anyof-single-array/blob/main/schema/api.json

  "paths": {
    "/users": {
      "get": {
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "array",
                  "uniqueItems": true,
                  "items": {
                    "type": "string"
                  },
                  "minItems": 1,
                  "maxItems": 500,
                  "title": "Id"
                }
              ]
            }
          }
        ],
...

Current Behavior

Querying a single element throws UNPROCESSABLE_ENTITY

{
  "type": "https://stoplight.io/prism/errors#UNPROCESSABLE_ENTITY",
  "title": "Invalid request",
  "status": 422,
  "detail": "Your request is not valid and no HTTP validation response was found in the spec, so Prism is generating this error for you.",
  "validation": [
    {
      "location": [
        "query",
        "id"
      ],
      "severity": "Error",
      "code": "type",
      "message": "Request query parameter id must be array"
    },
    {
      "location": [
        "query",
        "id"
      ],
      "severity": "Error",
      "code": "anyOf",
      "message": "Request query parameter id must match a schema in anyOf"
    }
  ]
}

Expected Behavior

?id=1 should validate as an array, similar to unwrapped array.

Possible Workaround/Solution

One can query single array element with ?id[]=1 format.

Steps to Reproduce

https://github.com/Arskah/prism-anyof-single-array

Repro steps in README.

Environment

@Arskah Arskah changed the title Array query parameters wrapped in anyOf do not work for single element arrays Array query parameters wrapped in anyOf do not work for single element queries Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant