fastify / fastify/fast-json-stringify
lack of strictSchema in ajv options results in silent typos
- Dominant language
- JavaScript
- Stars
- 3.7k
- Forks
- 226
- Avg merge
- 20h 34m
- Merged PRs (30d)
- 4
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
### Issue
`strictSchema` is [set to false in the ajv options](https://github.com/fastify/fast-json-stringify/blob/9b30d17d87c11628944bc9f33c491f6df6765653/lib/validator.js#L12) (and overrides any user-provided `ajv:` options to the constructor, so it cannot be set to true by the user either).
This makes it very easily to add a schema with an error that is silently ignored.
In my case I made a typo with `additionalProperties` in a fastify response schema, which meant that additional properties were not removed from a response on serialisation that should have been.
It would seem like having strictSchema:true would be a better default? (which would be a breaking change needing a major version I suppose), or at least allow the user to set this.
I tested setting `strictSchema:true` and running the tests, and the only additional keyword used internally seems to be `kind`[1],[2], which is only used in tests.
[1]: https://github.com/fastify/fast-json-stringify/blob/9b30d17d87c11628944bc9f33c491f6df6765653/test/anyof.test.js#L206
[2]: https://github.com/fastify/fast-json-stringify/blob/9b30d17d87c11628944bc9f33c491f6df6765653/test/array.test.js#L371
Contributor guide
Assessment
This issue has not been assessed yet.