This commit is contained in:
Adria Navarro 2024-11-29 13:07:24 +01:00
parent 96916a469d
commit ccbf282c69
1 changed files with 7 additions and 2 deletions

View File

@ -1,11 +1,16 @@
import { Ctx } from "@budibase/types" import { features } from "@budibase/backend-core"
import { Ctx, FeatureFlag } from "@budibase/types"
import { AnyZodObject } from "zod" import { AnyZodObject } from "zod"
import { fromZodError } from "zod-validation-error" import { fromZodError } from "zod-validation-error"
function validate(schema: AnyZodObject, property: "body" | "params") { function validate(schema: AnyZodObject, property: "body" | "params") {
// Return a Koa middleware function // Return a Koa middleware function
return (ctx: Ctx, next: any) => { return async (ctx: Ctx, next: any) => {
if (!(await features.flags.isEnabled(FeatureFlag.USE_ZOD_VALIDATOR))) {
return next()
}
if (!schema) { if (!schema) {
return next() return next()
} }