-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
fix: validation example #433
fix: validation example #433
Conversation
README.md
Outdated
@@ -290,6 +290,46 @@ If you try to read from a stream and pipe to a new file, you will obtain an empt | |||
|
|||
## JSON Schema body validation | |||
|
|||
You can use `fastify-multipart` with schema validation, this is a full working example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for this new example?
We can make it consistent in this way
Still working on It |
501e34a
to
f16daae
Compare
I added a working example that i've tried in my work project |
examples/example-with-swagger.js
Outdated
fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => { | ||
return ajv.compile(schema) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go this route, then any additional schemas will need to be added to the validator instead of the normal fastify.addSchema
usage, which may not be intuitive. See the note in the validator compiler docs.
Instead of defining an entirely custom validator, would passing the custom keyword as options when initializing fastify allow users to still rely on Fastify's private AJV implementation?
- See Fastify's AJV factory docs
- See the AJV keywords option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you made a good point
as myself I didn't use addSchema()
but it's valid I will push changes
Co-authored-by: aj-gameon <113391687+aj-gameon@users.noreply.github.com> Co-authored-by: Fernando Toledo <fernando@ftoledo.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
I changed the
validation-example.js
to pass the JSON validation schema.and add a section in the
readme.md
file so people can have a quick access to make it workFixes #173