Skip to content

Commit 251a274

Browse files
LucianBuzzoepicfaace
authored andcommitted
Add test and update documentation for using anyOf inside array items (#1131)
* Add test and update documentation for using anyOf inside array items Signed-off-by: Lucian <[email protected]>
1 parent ba833fa commit 251a274

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,9 +1845,9 @@ This component follows [JSON Schema](http://json-schema.org/documentation.html)
18451845
18461846
This keyword works when `items` is an array. `additionalItems: true` is not supported because there's no widget to represent an item of any type. In this case it will be treated as no additional items allowed. `additionalItems` being a valid schema is supported.
18471847
1848-
* `anyOf`, `allOf`, and `oneOf`, or multiple `types` (i.e. `"type": ["string", "array"]`
1848+
* `anyOf`, `allOf`, and `oneOf`, or multiple `types` (i.e. `"type": ["string", "array"]`)
18491849
1850-
The `anyOf` and `oneOf` keywords are supported, however, properties declared inside the `anyOf/oneOf` should not overlap with properties "outside" of the `anyOf/oneOf`.
1850+
The `anyOf` and `oneOf` keywords are supported, however, properties declared inside the `anyOf/oneOf` should not overlap with properties "outside" of the `anyOf/oneOf`.
18511851
18521852
You can also use `oneOf` with [schema dependencies](#schema-dependencies) to dynamically add schema properties based on input data.
18531853
@@ -1922,6 +1922,7 @@ $ git push --tags origin master
19221922
### Q: Does rjsf support `oneOf`, `anyOf`, multiple types in an array, etc.?
19231923
19241924
A: The `anyOf` and `oneOf` keywords are supported, however, properties declared inside the `anyOf/oneOf` should not overlap with properties "outside" of the `anyOf/oneOf`.
1925+
19251926
There is also special cased where you can use `oneOf` in [schema dependencies](#schema-dependencies), If you'd like to help improve support for these keywords, see the following issues for inspiration [#329](https://github.com/mozilla-services/react-jsonschema-form/pull/329) or [#417](https://github.com/mozilla-services/react-jsonschema-form/pull/417). See also: [#52](https://github.com/mozilla-services/react-jsonschema-form/issues/52), [#151](https://github.com/mozilla-services/react-jsonschema-form/issues/151), [#171](https://github.com/mozilla-services/react-jsonschema-form/issues/171), [#200](https://github.com/mozilla-services/react-jsonschema-form/issues/200), [#282](https://github.com/mozilla-services/react-jsonschema-form/issues/282), [#302](https://github.com/mozilla-services/react-jsonschema-form/pull/302), [#330](https://github.com/mozilla-services/react-jsonschema-form/issues/330), [#430](https://github.com/mozilla-services/react-jsonschema-form/issues/430), [#522](https://github.com/mozilla-services/react-jsonschema-form/issues/522), [#538](https://github.com/mozilla-services/react-jsonschema-form/issues/538), [#551](https://github.com/mozilla-services/react-jsonschema-form/issues/551), [#552](https://github.com/mozilla-services/react-jsonschema-form/issues/552), or [#648](https://github.com/mozilla-services/react-jsonschema-form/issues/648).
19261927
19271928
### Q: Will react-jsonschema-form support Material, Ant-Design, Foundation, or [some other specific widget library or frontend style]?

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ This component follows [JSON Schema](http://json-schema.org/documentation.html)
17431743
17441744
This keyword works when `items` is an array. `additionalItems: true` is not supported because there's no widget to represent an item of any type. In this case it will be treated as no additional items allowed. `additionalItems` being a valid schema is supported.
17451745
1746-
* `anyOf`, `allOf`, and `oneOf`, or multiple `types` (i.e. `"type": ["string", "array"]`
1746+
* `anyOf`, `allOf`, and `oneOf`, or multiple `types` (i.e. `"type": ["string", "array"]`)
17471747
17481748
The `anyOf` and `oneOf` keywords are supported, however, properties declared inside the `anyOf/oneOf` should not overlap with properties "outside" of the `anyOf/oneOf`.
17491749

playground/samples/anyOf.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ module.exports = {
66
type: "integer",
77
title: "Age",
88
},
9+
items: {
10+
type: "array",
11+
items: {
12+
type: "object",
13+
anyOf: [
14+
{
15+
properties: {
16+
foo: {
17+
type: "string",
18+
},
19+
},
20+
},
21+
{
22+
properties: {
23+
bar: {
24+
type: "string",
25+
},
26+
},
27+
},
28+
],
29+
},
30+
},
931
},
1032
anyOf: [
1133
{

test/anyOf_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,48 @@ describe("anyOf", () => {
299299

300300
expect(node.querySelector("select").value).eql("1");
301301
});
302+
303+
describe("Arrays", () => {
304+
it("should correctly render form inputs for anyOf inside array items", () => {
305+
const schema = {
306+
type: "object",
307+
properties: {
308+
items: {
309+
type: "array",
310+
items: {
311+
type: "object",
312+
anyOf: [
313+
{
314+
properties: {
315+
foo: {
316+
type: "string",
317+
},
318+
},
319+
},
320+
{
321+
properties: {
322+
bar: {
323+
type: "string",
324+
},
325+
},
326+
},
327+
],
328+
},
329+
},
330+
},
331+
};
332+
333+
const { node } = createFormComponent({
334+
schema,
335+
});
336+
337+
expect(node.querySelector(".array-item-add button")).not.eql(null);
338+
339+
Simulate.click(node.querySelector(".array-item-add button"));
340+
341+
expect(node.querySelectorAll("select")).to.have.length.of(1);
342+
343+
expect(node.querySelectorAll("input#root_foo")).to.have.length.of(1);
344+
});
345+
});
302346
});

0 commit comments

Comments
 (0)