Skip to content

Commit

Permalink
feat(json-schema): x-compile-omitted supports x-validator (#4072)
Browse files Browse the repository at this point in the history
  • Loading branch information
zynyy authored Jan 29, 2024
1 parent d11080a commit 4dc50bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
56 changes: 56 additions & 0 deletions packages/json-schema/src/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,62 @@ test('patchSchemaCompile demand initialized', () => {
dataSource: [22],
})
})

test('patchSchemaCompile x-compile-omitted', () => {
const targetState = {
title: '',
validator: [],
}
patchSchemaCompile(
targetState as any,
{
title: '132',
'x-validator': [
{
remoteCheckUniq: '{{field.value}}',
},
],
version: '1.2.3',
},
{
field: {
value: 888,
},
}
)
expect(targetState).toEqual({
title: '132',
validator: [{ remoteCheckUniq: 888 }],
})

const targetOmitState = {
title: '',
validator: [],
}
patchSchemaCompile(
targetOmitState as any,
{
title: '132',
'x-compile-omitted': ['x-validator'],
'x-validator': [
{
remoteCheckUniq: '{{field.value}}',
},
],
version: '1.2.3',
},
{
field: {
value: 888,
},
}
)
expect(targetOmitState).toEqual({
title: '132',
validator: [{ remoteCheckUniq: '{{field.value}}' }],
})
})

test('registerCompiler', () => {
registerCompiler(() => {
return 'compiled'
Expand Down
6 changes: 5 additions & 1 deletion packages/json-schema/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ export const traverseSchema = (
visitor: (value: any, path: any[], omitCompile?: boolean) => void
) => {
if (schema['x-validator'] !== undefined) {
visitor(schema['x-validator'], ['x-validator'])
visitor(
schema['x-validator'],
['x-validator'],
schema['x-compile-omitted']?.includes('x-validator')
)
}
const seenObjects = []
const root = schema
Expand Down

0 comments on commit 4dc50bc

Please sign in to comment.