fastify / fastify/help

Validation with AdditionalProperties: true by default?

Open
#820 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

Hi, I like having control on firing errors inside my routes, and i would like to do that also for the validation errors.
I see there is the option `additionalProperties: true` than can be used that won't throw an error but inject a `validationError` on the request parameter.

Is there a way to make this the default for all routes, or do I have to specify it for each route?

I've tried adding the property to my Ajv validator, but it doesn't work

```
const ajv = new Ajv({
coerceTypes: true, // change data type of data to match type keyword
useDefaults: true, // replace missing properties and items with the values from corresponding default keyword
removeAdditional: false, // remove additional properties
allErrors: false,
attachValidation: true
});

fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => {
return ajv.compile(schema);
});
```

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.