-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[open-formulieren/open-forms#3597] Switch to a zod validation for jso…
…nLogic
- Loading branch information
Showing
5 changed files
with
40 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import {IntlShape} from 'react-intl'; | ||
import {z} from 'zod'; | ||
|
||
import {buildCommonSchema, jsonSchema, optionSchema} from '@/registry/validation'; | ||
import {BuilderContextType} from '@/context'; | ||
import {buildCommonSchema, itemsExpressionSchema, optionSchema} from '@/registry/validation'; | ||
|
||
// z.object(...).or(z.object(...)) based on openForms.dataSrc doesn't seem to work, | ||
// looks like the union validation only works if the discriminator is in the top level | ||
// object :( | ||
// so we mark each aspect as optional so that *when* it is provided, we can run the | ||
// validation | ||
const buildValuesSchema = (intl: IntlShape) => | ||
const buildValuesSchema = (intl: IntlShape, builderContext: BuilderContextType) => | ||
z.object({ | ||
values: optionSchema(intl).array().min(1).optional(), | ||
openForms: z.object({ | ||
dataSrc: z.union([z.literal('manual'), z.literal('variable')]), | ||
// TODO: wire up infernologic type checking | ||
itemsExpression: jsonSchema.optional(), | ||
itemsExpression: itemsExpressionSchema(builderContext).optional(), | ||
}), | ||
}); | ||
|
||
const schema = (intl: IntlShape) => buildCommonSchema(intl).and(buildValuesSchema(intl)); | ||
const schema = (intl: IntlShape, builderContext: BuilderContextType) => | ||
buildCommonSchema(intl).and(buildValuesSchema(intl, builderContext)); | ||
|
||
export default schema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import {IntlShape} from 'react-intl'; | ||
import {z} from 'zod'; | ||
|
||
import {buildCommonSchema, jsonSchema, optionSchema} from '@/registry/validation'; | ||
import {BuilderContextType} from '@/context'; | ||
import {buildCommonSchema, itemsExpressionSchema, optionSchema} from '@/registry/validation'; | ||
|
||
// z.object(...).or(z.object(...)) based on openForms.dataSrc doesn't seem to work, | ||
// looks like the union validation only works if the discriminator is in the top level | ||
// object :( | ||
// so we mark each aspect as optional so that *when* it is provided, we can run the | ||
// validation | ||
const buildValuesSchema = (intl: IntlShape) => | ||
const buildValuesSchema = (intl: IntlShape, builderContext: BuilderContextType) => | ||
z.object({ | ||
values: optionSchema(intl).array().min(1).optional(), | ||
openForms: z.object({ | ||
dataSrc: z.union([z.literal('manual'), z.literal('variable')]), | ||
// TODO: wire up infernologic type checking | ||
itemsExpression: jsonSchema.optional(), | ||
itemsExpression: itemsExpressionSchema(builderContext).optional(), | ||
}), | ||
}); | ||
|
||
const schema = (intl: IntlShape) => buildCommonSchema(intl).and(buildValuesSchema(intl)); | ||
const schema = (intl: IntlShape, builderContext: BuilderContextType) => | ||
buildCommonSchema(intl).and(buildValuesSchema(intl, builderContext)); | ||
|
||
export default schema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters