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

coerceTypes "array" is not working for query params #808

Open
daneryl opened this issue Feb 2, 2023 · 1 comment · May be fixed by #809
Open

coerceTypes "array" is not working for query params #808

daneryl opened this issue Feb 2, 2023 · 1 comment · May be fixed by #809

Comments

@daneryl
Copy link

daneryl commented Feb 2, 2023

Describe the bug
From my understanding of the documentation, the coerceTypes option is set to 'true' by default. However, I am unable to modify this setting to other options, such as 'array'.

To Reproduce

  • Create a basic openapi document with an object param that nests an array param
{
  "paths": {
    "/api/route": {
      "get": {
        "parameters": [
          {
            "in": "query",
            "name": "property",
            "schema": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "values": { "type": "array", "items": { "type": "string" } }
              }
            }
          }
        ]
      }
    }
  }
}
  • Configure coerceTypes to array
  • perform a a request like http://localhost/api/route?property[values]=value1

Actual behavior

{
 "errors": [
  {
   "path": "/query/property/values",
   "message": "must be array",
   "errorCode": "type.openapi.validation"
  }
 ]
}

Expected behavior
Pass validation and coerce the values properly to an array, as per documentation https://ajv.js.org/coercion.html

Examples and context
Not sure why but on a simpler case this is working and the value apparently is properly coerced to an array
http://localhost/api/route?property=value1

{
  "paths": {
    "/api/route": {
      "get": {
        "parameters": [
         {
            "in": "query",
            "name": "property",
            "schema": { "type": "array", "items": { "type": "string" } }
          }
        ]
      }
    }
  }
}
@daneryl daneryl linked a pull request Feb 2, 2023 that will close this issue
@lleleux
Copy link

lleleux commented Jun 6, 2023

Hi,

Any update about this issue ? I have the same problem, and I cannot find any workaround.
But I can confirm the PR #809 solve the problem. Is it possible to review and merge it ?

Thank you,

Laurent

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

Successfully merging a pull request may close this issue.

2 participants