Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
picodoth committed Jul 19, 2018
1 parent 9e16801 commit b0f7f63
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 49 deletions.
104 changes: 60 additions & 44 deletions playground/samples/anyOf.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,71 @@
module.exports = {
schema: {
"title": "Any of",
"type": "object",
"properties": {
"List of widgets": {
"type": "array",
"items": {
"anyOf": [
{
"title": "string",
"type": "string",
"default": ""
type: 'object',
definitions: {
option: {
type: 'object',
required: ['label', 'value'],
properties: {
label: {
type: 'string',
},
value: {
type: 'string',
},
},
default: { label: '', value: '' }
},
optGroup: {
type: 'object',
required: ['label', 'items'],
properties: {
label: {
type: 'string',
},
items: {
type: 'array',
items: {
$ref: '#/definitions/option',
},
},
},
default: {
label: '',
items: [],
},
},
},
properties: {
options: {
type: 'array',
title: 'Options',
items: {
anyOf: [
{
"title": "integer",
"type": "integer",
"default": 0
$ref: '#/definitions/option',
title: 'option',
},
{
"title": "array",
"type": "array",
"items": {
"anyOf": [
{
"title": "string",
"type": "string",
"default": ""
},
{
"title": "integer",
"type": "integer",
"default": 0
}
]
},
"default": [""],
}
]
}
}
}
$ref: '#/definitions/optGroup',
title: 'optGroup',
},
],
},
},
},
},
uiSchema: {},
formData: {
"List of widgets": [
27,
"Batman",
[
"Bruce",
"Wayne"
]
options: [
{ label: 'car', value: 'car' },
{ label: 'house', value: 'house' },
{
label: 'fruit',
items: [
{ label: 'apple', value: 'apple' },
{ label: 'banana', value: 'banana' },
],
},
]
}
},
};
10 changes: 5 additions & 5 deletions src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ function resolveSchemaRecursively(schema, definitions) {
let unwrappedSchema = schema;
if (schema.$ref) {
unwrappedSchema = retrieveSchema(schema, definitions);
} else if (schema.anyOf) {
unwrappedSchema.anyOf.forEach((ele, index) => {
unwrappedSchema.anyOf[index] = resolveSchemaRecursively(unwrappedSchema.anyOf[index], definitions);
});
}

if (unwrappedSchema.properties) {
Object.keys(unwrappedSchema.properties).forEach(p => {
const prop = unwrappedSchema.properties[p];
if (prop.type === "array") {
if (prop.items.anyOf) {
prop.items.anyOf.forEach((ele, index) => {
prop.items.anyOf[index] = resolveSchemaRecursively(prop.items[index], definitions);
});
} else if (prop.items.$ref) {
if (prop.items.anyOf || prop.items.$ref) {
prop.items = resolveSchemaRecursively(prop.items, definitions);
}
// else: do nothing since there is no other type pointer
Expand Down

0 comments on commit b0f7f63

Please sign in to comment.