@@ -22,6 +22,7 @@ export function createValidationChecker(schema) {
2222 const scopes = new Map ( ) ;
2323
2424 function createScopes ( jsonSchema , key = 'root' ) {
25+ const sampleEmptyObject = buildSampleEmptyObject ( schema ) ;
2526 scopes . set ( key , createValidationsScope ( jsonSchema ) ) ;
2627 Object . entries ( jsonSchema ?. properties ?? { } )
2728 . filter ( ( [ , property ] ) => property . type === 'object' || property . type === 'array' )
@@ -31,6 +32,8 @@ export function createValidationChecker(schema) {
3132 }
3233 createScopes ( property , key ) ;
3334 } ) ;
35+
36+ validateInlineRules ( jsonSchema , sampleEmptyObject ) ;
3437 }
3538
3639 createScopes ( schema ) ;
@@ -297,15 +300,39 @@ function buildSampleEmptyObject(schema = {}) {
297300 return sample ;
298301}
299302
300- function checkRuleIntegrity ( rule , id , data ) {
303+ function validateInlineRules ( jsonSchema , sampleEmptyObject ) {
304+ const properties = ( jsonSchema ?. properties || jsonSchema ?. items ?. properties ) ?? { } ;
305+ Object . entries ( properties )
306+ . filter ( ( [ , property ] ) => property [ 'x-jsf-computedAttributes' ] !== undefined )
307+ . forEach ( ( [ fieldName , property ] ) => {
308+ Object . entries ( property [ 'x-jsf-computedAttributes' ] )
309+ . filter ( ( [ , value ] ) => typeof value === 'object' )
310+ . forEach ( ( [ key , { rule } ] ) => {
311+ checkRuleIntegrity (
312+ rule ,
313+ fieldName ,
314+ sampleEmptyObject ,
315+ ( item ) =>
316+ `"${ item . var } " in inline rule in property "${ fieldName } .x-jsf-computedAttributes.${ key } " does not exist as a JSON schema property.`
317+ ) ;
318+ } ) ;
319+ } ) ;
320+ }
321+
322+ function checkRuleIntegrity (
323+ rule ,
324+ id ,
325+ data ,
326+ errorMessage = ( item ) => `"${ item . var } " in rule "${ id } " does not exist as a JSON schema property.`
327+ ) {
301328 Object . values ( rule ?? { } ) . map ( ( subRule ) => {
302329 if ( ! Array . isArray ( subRule ) && subRule !== null && subRule !== undefined ) return ;
303330 subRule . map ( ( item ) => {
304331 const isVar = item !== null && typeof item === 'object' && Object . hasOwn ( item , 'var' ) ;
305332 if ( isVar ) {
306333 const exists = jsonLogic . apply ( { var : removeIndicesFromPath ( item . var ) } , data ) ;
307334 if ( exists === null ) {
308- throw Error ( `" ${ item . var } " in rule " ${ id } " does not exist as a JSON schema property.` ) ;
335+ throw Error ( errorMessage ( item ) ) ;
309336 }
310337 } else {
311338 checkRuleIntegrity ( item , id , data ) ;
0 commit comments