Skip to content

Commit

Permalink
fix(json-schema): fix single function x-reactions not work #1497
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed May 25, 2021
1 parent d5bf2ca commit ae5019d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/json-schema/src/__tests__/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,12 @@ describe('all static methods', () => {
expect(Schema.getOrderProperties()).toEqual([])
Schema.registerPatches(null)
})

test('single function x-reactions', () => {
const reactions = () => console.info('x-reactions')
const schema = new Schema({
type: 'string',
'x-reactions': reactions,
})
expect(schema.compile()['x-reactions']).toEqual(reactions)
})
5 changes: 3 additions & 2 deletions packages/json-schema/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class Schema<
Validator = any,
Message = any,
ReactionField = any
> implements ISchema {
> implements ISchema
{
parent?: Schema
name?: SchemaKey
title?: Message
Expand Down Expand Up @@ -446,7 +447,7 @@ export class Schema<
compile = (scope?: any) => {
const schema = new Schema({}, this.parent)
each(this, (value, key) => {
if (isFn(value)) return
if (isFn(value) && !key.includes('x-')) return
if (key === 'parent') return
if (!ShallowCompileKeys.includes(key)) {
schema[key] = value ? compile(value, scope) : value
Expand Down

0 comments on commit ae5019d

Please sign in to comment.