Skip to content

Commit

Permalink
feat: add new option to disable JOI validation (#8067)
Browse files Browse the repository at this point in the history
Adds new option `joiValidation: boolean` to the payload config per
client request.

`joiValidation` defaults to `true`, when set to `false` it will bypass
the JOI validation for all collections, globals, fields etc.

NOTE: This change is not required for v3.
  • Loading branch information
JessChowdhury authored Sep 12, 2024
1 parent efc0bc9 commit 28a0650
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/payload/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const defaults: Omit<Config, 'db' | 'editor'> = {
schemaOutputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/schema.graphql`,
},
hooks: {},
joiValidation: true,
localization: false,
maxDepth: 10,
rateLimit: {
Expand Down
1 change: 1 addition & 0 deletions packages/payload/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default joi.object({
}),
i18n: joi.object(),
indexSortableFields: joi.boolean(),
joiValidation: joi.boolean(),
local: joi.boolean(),
localization: joi.alternatives().try(
joi.object().keys({
Expand Down
16 changes: 11 additions & 5 deletions packages/payload/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ export type InitOptions = {
*/
local?: boolean

/**
* A previously instantiated logger instance. Must conform to the PayloadLogger interface which uses Pino
* This allows you to bring your own logger instance and let payload use it
*/
logger?: PayloadLogger
loggerDestination?: DestinationStream
/**
* Specify options for the built-in Pino logger that Payload uses for internal logging.
*
* See Pino Docs for options: https://getpino.io/#/docs/api?id=options
*/
loggerOptions?: LoggerOptions
/**
* A previously instantiated logger instance. Must conform to the PayloadLogger interface which uses Pino
* This allows you to bring your own logger instance and let payload use it
*/
logger?: PayloadLogger

/**
* A function that is called immediately following startup that receives the Payload instance as it's only argument.
Expand Down Expand Up @@ -635,6 +635,12 @@ export type Config = {
i18n?: i18nInitOptions
/** Automatically index all sortable top-level fields in the database to improve sort performance and add database compatibility for Azure Cosmos and similar. */
indexSortableFields?: boolean
/**
* Disable JOI validation
*
* @default true // enabled by default
*/
joiValidation?: boolean
/**
* Translate your content to different languages/locales.
*
Expand Down
4 changes: 4 additions & 0 deletions packages/payload/src/config/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const validateSchema = async (
abortEarly: false,
})

if (!config?.joiValidation) {
return config
}

const nestedErrors = [
...(await validateCollections(config.collections)),
...validateGlobals(config.globals),
Expand Down

0 comments on commit 28a0650

Please sign in to comment.