Hilzu / express-openapi-validate

Express middleware to validate requests based on an OpenAPI 3 document
Apache License 2.0
75 stars 12 forks source link

Numeric query parameters #42

Closed FallingSnow closed 5 years ago

FallingSnow commented 5 years ago

Integer parameters like the one listed below will never match. It seems express passes all query parameters as strings. We could try ParseInt and isNaN on integers fields to convert them to a valid type.

      parameters:
        - in: query
          name: offset
          schema:
            type: integer
            minimum: 0
            default: 0
          example: 0
          description: Offset your search results. Used for pagination.

On a side note default doesn't seem to work.

Thanks again, hopefully I haven't missed anything this time. :P

FallingSnow commented 5 years ago

Awesome. Figured out you can just do new OpenApiValidator(openApiDocument, {ajvOptions: { coerceTypes: true }}) and it just works.