-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Change AJV allErrors default and support user setting #955
Conversation
AJV recommends setting option `allErrors` to `false` in production. pdate `createAjv()` to respect the user's setting. Avoid introducing a breaking change by defaulting to `true` when not defined by the user. Add tests: 1. Make sure `AjvOptions` sets the value appropriately based on whether the end user defined `allErrors` or not. 2. When validating requests, make sure the number of errors reported (when multiple occur) is 1 when `allErrors` is `false`. The `allErrors` configuration for OpenAPISchemaValidator is not changed by this commit since that validation is for trusted content. Fixes cdimascio#954
@cdimascio - couple of questions for this PR:
|
@mdmower-csnw thanks for highlighting this and providing a fix. the ajv default is described as:
|
- Do not set allErrors by default **breaking change**
Thanks for the quick response @cdimascio . Changes made and PR description updated. |
@mdmower-csnw apologies for the multiple followups. since this parameter export interface OpenApiValidatorOpts {
apiSpec: DeepImmutable<OpenAPIV3.Document> | string;
validateApiSpec?: boolean;
validateResponses?: boolean | ValidateResponseOpts; // <--- In these opts
validateRequests?: boolean | ValidateRequestOpts; // <--- and these opts Also, if you're up for it, it will be fantastic if you can also add the new option usages notes to the docs here |
- Allow allErrors to be set on requests and responses independently
Thanks @cdimascio, that makes sense. I've moved the option to request and response validation options and added tests for each. A PR for related documentation is at cdimascio/express-openapi-validator-documentation#1 . |
Thank you! |
@cdimascio - could you check on the change history entry for this? https://github.com/cdimascio/express-openapi-validator/blob/master/CHANGE_HISTORY.md#2024-08-31 It doesn't look like the breaking change was recorded correctly. Also, if this was released as version 5.3.4, the versions in the documentation could use an update: cdimascio/express-openapi-validator-documentation#1 (review) |
Thanks will take a look |
BREAKING CHANGE: Request and response validation stops after the first failure. Only one error will be reported even when multiple may exist. This follows best practices from AJV:
allErrors
optionTo report all validation errors (only recommended in development), option
allErrors
can be set in express-openapi-validator request and response validation options. For example:AJV security recommendations advise that
allErrors
should not be set totrue
in production (more details in #954). UpdatecreateAjv()
so that it does not setallErrors
by default and add support for letting users defineallErrors
in request and response validation options.Added tests to ensure that the number of errors reported (when multiple are expected) is correct based on how
allErrors
is set (or unset).The
allErrors
configuration forOpenAPISchemaValidator
is not changed by this commit since that validation is for trusted content.Fixes #954