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

Feat: replace yup with joi for cleaner validation #2962

Merged
merged 3 commits into from
Jun 22, 2020

Conversation

anshulrgoyal
Copy link
Contributor

Motivation

Replace yup with joi since joi provide better validation options out of the box

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

The existing test should be sufficient

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 18, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Jun 18, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 8d89fcb

https://deploy-preview-2962--docusaurus-2.netlify.app

@anshulrgoyal anshulrgoyal marked this pull request as ready for review June 19, 2020 12:26
@anshulrgoyal anshulrgoyal requested a review from yangshun as a code owner June 19, 2020 12:26
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

It seems one test is failing.

Otherwise Joi seems nice. Probably more powerful and widely used than Yup so I'm not against switching

Gatsby uses it internally to validate its configuration

const UserOptionsSchema = Joi.object<UserPluginOptions>({
fromExtensions: Joi.array().items(Joi.string().required().min(0)),
toExtensions: Joi.array().items(Joi.string().required().min(0)),
redirects: Joi.array().items(RedirectPluginOptionValidation) as any, // TODO Joi expect weird typing here
Copy link
Collaborator

Choose a reason for hiding this comment

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

same problem with Joi here?

from: PathnameValidator.required(),
to: PathnameValidator.required(),
});

export function validateRedirect(redirect: RedirectMetadata) {
try {
RedirectSchema.validateSync(redirect, {
strict: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about this, but wouldn't it be better to be strict by default.

Ie using convert: false with Joi, to be more strict so that if we expect a number in the conf, the user does not try to pass "42" instead of 42 for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we will be moving this validation to be done in life cycle method after the plugin is imported as done with other plugins

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure :)

@anshulrgoyal
Copy link
Contributor Author

It seems one test is failing.

Otherwise Joi seems nice. Probably more powerful and widely used than Yup so I'm not against switching

Gatsby uses it internally to validate its configuration

joi has different wording for the error so the snapshot test are failing.

@slorber
Copy link
Collaborator

slorber commented Jun 19, 2020

Then you can update the snapshots so that I can check the new error messages are decent :p and merge the PR

@slorber
Copy link
Collaborator

slorber commented Jun 22, 2020

@anshulrgoyal should we merge this before your other pr? can you resolve conflicts?

@anshulrgoyal
Copy link
Contributor Author

Yes I can

@anshulrgoyal
Copy link
Contributor Author

@slorber fixed merge conflict

@slorber slorber merged commit 2b4b6f7 into facebook:master Jun 22, 2020
@slorber
Copy link
Collaborator

slorber commented Jun 22, 2020

thanks :)

@slorber slorber added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Jun 22, 2020
@anshulrgoyal anshulrgoyal deleted the anshul/joi-validation branch June 22, 2020 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants