Skip to content

Commit

Permalink
Keep merging subschemas event if parent schema is not mergable (like …
Browse files Browse the repository at this point in the history
…contains)
  • Loading branch information
mokkabonna committed Jan 17, 2024
1 parent 2ee01de commit fe45971
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -407,7 +407,14 @@ function merger(rootSchema, options, totalSchemas) {
);

if (abortCalled) {
const [first, ...rest] = compacted;
const [first, ...rest] = compacted.map((value) => {
// if we are dealing with a schema, merge it standalone as a schema,
// but outside the context of the parent schema
if (schemaProps.includes(key)) {
return mergeSchemas([value], value);
}
return value;
});
merged[key] = first;
addToAllOf(
rest.map((val) => ({
37 changes: 37 additions & 0 deletions test/specs/contains.spec.js
Original file line number Diff line number Diff line change
@@ -93,6 +93,43 @@ describe('pattern', function () {
});
});

it('merges valid subschemas inside a contains', async () => {
const result = mergeAndTest(
{
contains: {
minLength: 2
},
allOf: [
{
contains: {
maxLength: 10,
allOf: [
{
maxLength: 8
}
]
}
}
]
},
null,
[['abc'], ['abc'], ['abc', 'de'], ['a'], ['abcdefgfdsafds']]
);

expect(result).to.eql({
contains: {
minLength: 2
},
allOf: [
{
contains: {
maxLength: 8
}
}
]
});
});

it('does not combine with base schema', async () => {
const result = mergeAndTest(
{

0 comments on commit fe45971

Please sign in to comment.