open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Option to strip out unused parameters

Open ksmithut opened this issue 9 years ago • 10 comments

This may already be included somewhere, but it would be awesome if there was an option to strip out parameters that aren't in the docs. For example:

If a query parameter age is defined, but ?age=30&foo=bar is passed, I would like req.query to only contain age.

I'm not sure which underlying express-openapi-* module would contain this, or perhaps it would be a new one.

ksmithut avatar Dec 05 '16 16:12 ksmithut

I like the idea a lot. It would probably make sense as middelware in this project for now. If you'd like to add a PR feel free.

jsdevel avatar Dec 05 '16 17:12 jsdevel

Cool, I'll take a look :) When I was attempting to build a swagger type api "thing" once upon a time, I relied on ajv to do my parsing and stripping and stuff. Might need to do something like that for body. Any favorite json-schema libraries?

ksmithut avatar Dec 05 '16 23:12 ksmithut

Any favorite json-schema libraries?

Checkout the dependencies for this project. Ideally we can leverage one of those.

jsdevel avatar Dec 05 '16 23:12 jsdevel

Cool, I'll check it out

ksmithut avatar Dec 05 '16 23:12 ksmithut

@ksmithut how are things going? Is this still an issue?

jsdevel avatar Jan 25 '17 06:01 jsdevel

I haven't had time to look into get... Got back into the swing at work and such. Feel free to close this out.

ksmithut avatar Jan 25 '17 14:01 ksmithut

I like the idea as an enhancement (labeled this as such). If you have time to add the functionality feel free!

jsdevel avatar Jan 25 '17 18:01 jsdevel

The ajv option "removeAdditional: true" does this when the schema has "additionalProperties: false". There are other options for removeAdditional

buzzware avatar Feb 13 '20 13:02 buzzware

@buzzware sounds like you can control this via the schema then? would updating the README suffice?

jsdevel avatar Feb 20 '20 18:02 jsdevel

I'm dealing with same/similar problem, need to remove additional data without throwing errors.

  • when i set "additionalProperties: false" into schema validator throw errors
  • when i add to Ajv config removeAdditional: true it removes additional data and not throws errors

Very helpful is this test https://github.com/ajv-validator/ajv/blob/ba752505cf53a136eda1c4f4b81bf9e697a42dc2/spec/options/removeAdditional.spec.ts#L27

Would be nice to have ajv options configurable for openapi-request-validator, or at least just this one removeAdditional. (using only component openapi-request-validator)

UPDATE: i want to remove additional data from body.

dkMorlok avatar Feb 17 '21 19:02 dkMorlok