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

fastify: endpoint with query param as array limitation #134

Closed
Xavier-Redondo opened this issue Jan 17, 2024 · 1 comment
Closed

fastify: endpoint with query param as array limitation #134

Xavier-Redondo opened this issue Jan 17, 2024 · 1 comment
Labels
bautajs-fastify bug Something isn't working

Comments

@Xavier-Redondo
Copy link
Contributor

Xavier-Redondo commented Jan 17, 2024

Context

We define an endpoint that has a query param that is an array.

This is exemplified in this PR: #133

For this issues we are referring to the following endpoint defined in the api:

 "/array-query-param" :{
      "get": {
        "operationId": "queryParamAsArray",
        "summary": "Generates an array with all the input query params",
        "parameters": [
          {
            "name": "chickenIds",
            "in": "query",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "maxItems": 1000
            },
            "style": "form",
            "explode": true
          }
        ],
        "responses": {
             // Removed to reduce size
        }
      }
    },

According to this endpoint, these url's should be valid:

http://localhost:8080/api/array-query-param?chickenIds=2&chickenIds=3
http://localhost:8080/api/array-query-param?chickenIds=2

The first url, which has two elements, is correctly validated and we get a response.

Current behaviour

The second url, which has only one element, is not correctly validated and instead of having an array with one element we get the following validation error:

{"statusCode":400,"error":"Bad Request","message":"The request was not valid"}

with the following error log in the server:

js {"level":30,"time":1705507465376,"pid":50352,"hostname":"xxx","reqId":"req-1","res":{"statusCode":400},"err":{"type":"ValidationError","message":"The request was not valid","stack":"Validation Error: The request was not valid \n {\n \"name\": \"Validation Error\",\n \"errors\": [\n {\n \"path\": \"#/properties/chickenIds/type\",\n \"location\": \"querystring\",\n \"message\": \"must be array\",\n \"errorCode\": \"type\"\n }\n ],\n \"statusCode\": 400,\n \"message\": \"The request was not valid\"\n}","aggregateErrors":[{"type":"Object","message":"must be array","stack":"","path":"#/properties/chickenIds/type","location":"querystring","errorCode":"type"}],"name":"Validation Error","errors":[{"path":"#/properties/chickenIds/type","location":"querystring","message":"must be array","errorCode":"type"}],"statusCode":400},"msg":"The request was not valid"}

Expected behaviour

Even with one element we should treat this as an array of one element and not throw a validation error.

@Xavier-Redondo Xavier-Redondo changed the title fastify: endpoint with query param as arry limitation fastify: endpoint with query param as array limitation Jan 17, 2024
@Xavier-Redondo Xavier-Redondo self-assigned this Jan 17, 2024
@Xavier-Redondo Xavier-Redondo added the bug Something isn't working label Jan 17, 2024
@Xavier-Redondo Xavier-Redondo removed their assignment Jan 23, 2024
@franher
Copy link
Contributor

franher commented Jan 29, 2024

@Xavier-Redondo thank you for the issue. Is this duplicated with #135 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bautajs-fastify bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants