Skip to content
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

Conversation

lord007tn
Copy link
Contributor

Checklist

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 work
Fixes #173

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.
Copy link
Member

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

@lord007tn
Copy link
Contributor Author

Still working on It
further in the project the Ajv validators seems to make fastify fail in some edge cases
I'm trying to find solutions and I will update it soon
with tests also

@lord007tn lord007tn force-pushed the update-validation-example-and-readme-section branch from 501e34a to f16daae Compare April 19, 2023 10:06
@lord007tn
Copy link
Contributor Author

I added a working example that i've tried in my work project
and it works fine
still lacks unit testing
i would give it a try when i have more time
you could verify it

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Comment on lines 29 to 31
fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => {
return ajv.compile(schema)
})
Copy link
Contributor

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?

Copy link
Contributor Author

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

lord007tn and others added 2 commits April 20, 2023 02:54
Co-authored-by: aj-gameon <113391687+aj-gameon@users.noreply.github.com>
Co-authored-by: Fernando Toledo <fernando@ftoledo.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 15afc65 into fastify:master May 3, 2023
15 checks passed
@renovate renovate bot mentioned this pull request Jun 28, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multipart does not work with validation and fastify-swagger
5 participants