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

Set default QueryString parameters values in Express req object #47

Closed loicsikidi closed 5 years ago

loicsikidi commented 5 years ago

Hello,

Could it be possible that the library set default value(s) defined in parameters?

Today, with the version 0.4.4 of the lib. If I use the example below:

 /users:
    get:
      description: |
        Returns all users from the referential
      operationId: findUsers
      parameters:
        - name: limit
          in: query
          description: Number of items to retrieve per page. Default is 5, maximum is 50.
          required: false
          schema:
            type: integer
            format: int32
            minimum: 1
            maximum: 50
            default: 5

And this implementation :


const validator = new OpenApiValidator(openApiDocument, {ajvOptions: { coerceTypes: true }});

router.get('/', validator.validate("get", "/users"), function(req, res) {
  console.log(req.query); //the object is empty... I expect the param `limit` to be equal to 5
  res.send('success');
});

Is this feature is out of scope of the library? Is it a bug?

Thank you in advance!

Hilzu commented 5 years ago

All modifications to the request are out of scope. This library only handles validation and doesn't modify the request object at all.

loicsikidi commented 5 years ago

Ok thanks for your feedback!