Skip to content

Commit

Permalink
Improve isObjectArray by using deriveType
Browse files Browse the repository at this point in the history
* isObjectArray is using deriveType
* add additional test cases
  • Loading branch information
eneufeld committed Apr 21, 2019
1 parent 7453f15 commit 83e9544
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/core/src/testers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,10 @@ export const isDateTimeControl = and(
export const isObjectArray = and(
schemaMatches(
schema =>
!isEmpty(schema) &&
schema.type === 'array' &&
!isEmpty(schema.items) &&
deriveType(schema) === 'array' &&
!Array.isArray(schema.items) // we don't care about tuples
),
schemaSubPathMatches('items', schema => schema.type === 'object')
schemaSubPathMatches('items', schema => deriveType(schema) === 'object')
);

/**
Expand Down
39 changes: 39 additions & 0 deletions packages/core/test/testers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,45 @@ test('tester isObjectArrayControl', t => {
}
};
t.true(isObjectArrayControl(control, schema));
const schema_noType: JsonSchema = {
type: 'object',
properties: {
foo: {
items: {
type: 'object',
properties: {
x: { type: 'integer' },
y: { type: 'integer' }
}
}
}
}
};
t.true(isObjectArrayControl(control, schema_noType));
const schema_innerAllOf: JsonSchema = {
type: 'object',
properties: {
foo: {
type: 'array',
items: {
allOf: [
{
properties: {
x: { type: 'integer' }
}
},
{
properties: {
y: { type: 'integer' }
}
},

]
}
}
}
};
t.true(isObjectArrayControl(control, schema_innerAllOf));
});

test('isBooleanControl', t => {
Expand Down

0 comments on commit 83e9544

Please sign in to comment.