Skip to content

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

@Arskah

Description

@Arskah

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions