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

A query parameter of type array fails a minItems: validation when omitted even though parameter optional #418

Open
vulcanfan opened this issue Sep 15, 2021 · 1 comment

Comments

@vulcanfan
Copy link

Hi,

I'm having some trouble with the following snippet under get: and parameters:

        - name: group-id
          in: query
          description: Group IDs
          schema:
            type: array
            items:
              $ref: '#/components/schemas/GroupId'
            minItems: 1
          style: form
          explode: false

The parameter is optional (no required: true). Yet when the parameter is omitted completely from the query parameter list in a HTTP Request then validation fails with the error 'Min items is 1'. Even though the parameter itself is optional.

Looking at the code, in ValidateParameter() in validate_request.go there is a test 'if value == nil' before checking parameter.Required. However if a query parameter such as above is missing completely then 'value' still gets decoded as the empty slice []interface{}, which is different to being nil in Go. So the 'test == nil' fails, the Required flag is not checked and it moves on to checking MinItems when it shouldn't in this case I don't believe, thus generating the validation error.

Is my interpretation correct here?

Many thanks

@fenollp
Copy link
Collaborator

fenollp commented Sep 16, 2021

Is my interpretation correct here?

There's only one way to be sure ;)

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

2 participants