Skip to content

Commit e543e3e

Browse files
committed
Fix schemaSubPathMatches tester
1 parent 76a56e5 commit e543e3e

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

packages/core/src/testers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const schemaSubPathMatches = (
103103
return false;
104104
}
105105
const schemaPath = uischema.scope;
106-
let currentDataSchema: JsonSchema;
106+
let currentDataSchema: JsonSchema = schema;
107107
if (schema.type === 'object') {
108108
currentDataSchema = resolveSchema(schema, schemaPath);
109109
}

packages/core/test/testers.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2018 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -40,6 +40,7 @@ import {
4040
optionIs,
4141
or,
4242
schemaMatches,
43+
schemaSubPathMatches,
4344
schemaTypeIs,
4445
scopeEndIs,
4546
scopeEndsWith,
@@ -669,3 +670,23 @@ test('tester isObjectArrayWithNesting', t => {
669670
t.true(isObjectArrayWithNesting(uischemaOptions.generate, schema));
670671
t.true(isObjectArrayWithNesting(uischemaOptions.inline, schema));
671672
});
673+
674+
test('tester schemaSubPathMatches', t => {
675+
const schema = {
676+
title: 'Things',
677+
type: 'array',
678+
items: {
679+
type: 'number'
680+
}
681+
};
682+
const uischema: ControlElement = {
683+
type: 'Control',
684+
scope: '#'
685+
};
686+
t.true(
687+
schemaSubPathMatches('items', items => items.type === 'number')(
688+
uischema,
689+
schema
690+
)
691+
);
692+
});

packages/examples/src/1253.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@ export const uischema = {
2626

2727
const data = {};
2828

29+
const schema2 = {
30+
type: 'object',
31+
properties: {
32+
oneOrMoreThings: {
33+
oneOf: [
34+
{
35+
$ref: '#/definitions/thing'
36+
},
37+
{
38+
$ref: '#/definitions/thingArray'
39+
}
40+
]
41+
}
42+
},
43+
definitions: {
44+
thing: {
45+
title: 'Thing',
46+
type: 'string'
47+
},
48+
thingArray: {
49+
title: 'Things',
50+
type: 'array',
51+
items: {
52+
$ref: '#/definitions/thing'
53+
}
54+
}
55+
}
56+
};
57+
58+
const uischema2 = {
59+
type: 'Control',
60+
label: 'Value',
61+
scope: '#/properties/oneOrMoreThings'
62+
};
63+
2964
registerExamples([
3065
{
3166
name: 'issue-1253',
@@ -35,3 +70,13 @@ registerExamples([
3570
uischema
3671
}
3772
]);
73+
74+
registerExamples([
75+
{
76+
name: 'issue-1253-field',
77+
label: 'issue 1253 (oneOf) - missing field',
78+
data,
79+
schema: schema2,
80+
uischema: uischema2
81+
}
82+
]);

0 commit comments

Comments
 (0)