-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,19 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {isValidPathname} from '@docusaurus/utils'; | ||
import * as Yup from 'yup'; | ||
import * as Joi from '@hapi/joi'; | ||
import {RedirectMetadata} from './types'; | ||
|
||
export const PathnameValidator = Yup.string().test({ | ||
name: 'isValidPathname', | ||
message: | ||
'${path} is not a valid pathname. Pathname should start with / and not contain any domain or query string', | ||
test: isValidPathname, | ||
}); | ||
export const PathnameValidator = Joi.string().pattern(/^\/\w*/); | ||
|
||
const RedirectSchema = Yup.object<RedirectMetadata>({ | ||
const RedirectSchema = Joi.object<RedirectMetadata>({ | ||
from: PathnameValidator.required(), | ||
to: PathnameValidator.required(), | ||
}); | ||
|
||
export function validateRedirect(redirect: RedirectMetadata) { | ||
try { | ||
RedirectSchema.validateSync(redirect, { | ||
strict: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure :) |
||
RedirectSchema.validate(redirect, { | ||
abortEarly: true, | ||
}); | ||
} catch (e) { | ||
|
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.
same problem with Joi here?