openapiexpress-openapi-validator

Cannot pass dynamic query parameters when using `express-openapi-validator`


The idea is taken from here stack-overflow

After adding a parameter that is supposed do allow dynamic query parameters, it gives error.

Query Example:

/pets:
    get:
      description: |
        Returns all pets
      operationId: findPets
      parameters:
        - name: params
          in: query
          required: false
          schema:
            type: object
            # If the parameter values are of specific type, e.g. string:
            # additionalProperties:
            #   type: string
            # If the parameter values can be of different types
            # (e.g. string, number, boolean, ...)
            additionalProperties: true

          # `style: form` and `explode: true` is the default serialization method
          # for query parameters, so these keywords can be omitted
          style: form
          explode: true
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

Executing a query, returns

{"message":"Cannot convert undefined or null to object"}

To Reproduce

Expected behavior It must allow all the query strings


Solution

  • This was the bug in the express-openapi-validator package.

    It is now fixed in v4.4.2

    To test out the functionality, see this example project