Skip to content

Commit 964564b

Browse files
committed
Bump version to 2.7.1 and update dist files
1 parent 8f33985 commit 964564b

File tree

5 files changed

+98
-26
lines changed

5 files changed

+98
-26
lines changed

dist/react-json-form.cjs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function getBlankArray(schema, getRef) {
241241
let type = normalizeKeyword(schema.items.type);
242242

243243
if (!type) {
244-
if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0];
244+
if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]);
245245
}
246246

247247
if (type === 'array') {
@@ -251,6 +251,14 @@ function getBlankArray(schema, getRef) {
251251
} else if (type === 'object') {
252252
while (items.length < minItems) items.push(getBlankObject(schema.items, getRef));
253253

254+
return items;
255+
} else if (type === 'oneOf') {
256+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
257+
258+
return items;
259+
} else if (type === 'anyOf') {
260+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
261+
254262
return items;
255263
}
256264

@@ -3288,23 +3296,26 @@ function validateArray(schema) {
32883296
} else {
32893297
if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return {
32903298
isValid: false,
3291-
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'"
3299+
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'"
32923300
};
32933301
}
32943302

3295-
if (schema.hasOwnProperty('oneOf')) {
3303+
if (schema.items.hasOwnProperty('oneOf')) {
32963304
validation = validateOneOf(schema.items);
32973305
if (!validation.isValid) return validation;
32983306
}
32993307

3300-
if (schema.hasOwnProperty('anyOf')) {
3308+
if (schema.items.hasOwnProperty('anyOf')) {
33013309
validation = validateAnyOf(schema.items);
33023310
if (!validation.isValid) return validation;
33033311
}
33043312

3305-
if (schema.hasOwnProperty('allOf')) {
3306-
validation = validateAllOf(schema.items);
3307-
if (!validation.isValid) return validation;
3313+
if (schema.items.hasOwnProperty('allOf')) {
3314+
// we don't support allOf inside array yet
3315+
return {
3316+
isValid: false,
3317+
msg: "Currently, 'allOf' inside array items is not supported"
3318+
};
33083319
}
33093320

33103321
return {
@@ -3366,13 +3377,18 @@ function validateSubschemas(schema, keyword) {
33663377
keyword: one of 'oneOf' or 'anyOf' or 'allOf'
33673378
Validation:
33683379
1. Must be an array
3369-
2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
3380+
2. Must have at least one subschema
3381+
3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
33703382
*/
33713383
let subschemas = schema[keyword];
33723384
if (!Array.isArray(subschemas)) return {
33733385
isValid: false,
33743386
msg: "'" + keyword + "' property must be an array"
33753387
};
3388+
if (!subschemas.length) return {
3389+
isValid: false,
3390+
msg: "'" + keyword + "' must contain at least one subschema"
3391+
};
33763392

33773393
for (let i = 0; i < subschemas.length; i++) {
33783394
let subschema = subschemas[i];
@@ -3758,6 +3774,14 @@ function DataValidator(schema) {
37583774

37593775
let next_validator = this.getValidator(next_type);
37603776

3777+
if (!next_validator) {
3778+
if (next_schema.hasOwnProperty('oneOf')) {
3779+
next_validator = this.validateOneOf;
3780+
} else if (next_schema.hasOwnProperty('anyOf')) {
3781+
next_validator = this.validateAnyOf;
3782+
} else if (next_schema.hasOwnProperty('anyOf')) ;
3783+
}
3784+
37613785
if (next_validator) {
37623786
for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i]));
37633787
} else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.');

dist/react-json-form.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-json-form.modern.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function getBlankArray(schema, getRef) {
235235
let type = normalizeKeyword(schema.items.type);
236236

237237
if (!type) {
238-
if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0];
238+
if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]);
239239
}
240240

241241
if (type === 'array') {
@@ -245,6 +245,14 @@ function getBlankArray(schema, getRef) {
245245
} else if (type === 'object') {
246246
while (items.length < minItems) items.push(getBlankObject(schema.items, getRef));
247247

248+
return items;
249+
} else if (type === 'oneOf') {
250+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
251+
252+
return items;
253+
} else if (type === 'anyOf') {
254+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
255+
248256
return items;
249257
}
250258

@@ -3282,23 +3290,26 @@ function validateArray(schema) {
32823290
} else {
32833291
if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return {
32843292
isValid: false,
3285-
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'"
3293+
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'"
32863294
};
32873295
}
32883296

3289-
if (schema.hasOwnProperty('oneOf')) {
3297+
if (schema.items.hasOwnProperty('oneOf')) {
32903298
validation = validateOneOf(schema.items);
32913299
if (!validation.isValid) return validation;
32923300
}
32933301

3294-
if (schema.hasOwnProperty('anyOf')) {
3302+
if (schema.items.hasOwnProperty('anyOf')) {
32953303
validation = validateAnyOf(schema.items);
32963304
if (!validation.isValid) return validation;
32973305
}
32983306

3299-
if (schema.hasOwnProperty('allOf')) {
3300-
validation = validateAllOf(schema.items);
3301-
if (!validation.isValid) return validation;
3307+
if (schema.items.hasOwnProperty('allOf')) {
3308+
// we don't support allOf inside array yet
3309+
return {
3310+
isValid: false,
3311+
msg: "Currently, 'allOf' inside array items is not supported"
3312+
};
33023313
}
33033314

33043315
return {
@@ -3360,13 +3371,18 @@ function validateSubschemas(schema, keyword) {
33603371
keyword: one of 'oneOf' or 'anyOf' or 'allOf'
33613372
Validation:
33623373
1. Must be an array
3363-
2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
3374+
2. Must have at least one subschema
3375+
3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
33643376
*/
33653377
let subschemas = schema[keyword];
33663378
if (!Array.isArray(subschemas)) return {
33673379
isValid: false,
33683380
msg: "'" + keyword + "' property must be an array"
33693381
};
3382+
if (!subschemas.length) return {
3383+
isValid: false,
3384+
msg: "'" + keyword + "' must contain at least one subschema"
3385+
};
33703386

33713387
for (let i = 0; i < subschemas.length; i++) {
33723388
let subschema = subschemas[i];
@@ -3752,6 +3768,14 @@ function DataValidator(schema) {
37523768

37533769
let next_validator = this.getValidator(next_type);
37543770

3771+
if (!next_validator) {
3772+
if (next_schema.hasOwnProperty('oneOf')) {
3773+
next_validator = this.validateOneOf;
3774+
} else if (next_schema.hasOwnProperty('anyOf')) {
3775+
next_validator = this.validateAnyOf;
3776+
} else if (next_schema.hasOwnProperty('anyOf')) ;
3777+
}
3778+
37553779
if (next_validator) {
37563780
for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i]));
37573781
} else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.');

dist/react-json-form.module.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function getBlankArray(schema, getRef) {
235235
let type = normalizeKeyword(schema.items.type);
236236

237237
if (!type) {
238-
if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0];
238+
if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]);
239239
}
240240

241241
if (type === 'array') {
@@ -245,6 +245,14 @@ function getBlankArray(schema, getRef) {
245245
} else if (type === 'object') {
246246
while (items.length < minItems) items.push(getBlankObject(schema.items, getRef));
247247

248+
return items;
249+
} else if (type === 'oneOf') {
250+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
251+
252+
return items;
253+
} else if (type === 'anyOf') {
254+
while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef));
255+
248256
return items;
249257
}
250258

@@ -3282,23 +3290,26 @@ function validateArray(schema) {
32823290
} else {
32833291
if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return {
32843292
isValid: false,
3285-
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'"
3293+
msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'"
32863294
};
32873295
}
32883296

3289-
if (schema.hasOwnProperty('oneOf')) {
3297+
if (schema.items.hasOwnProperty('oneOf')) {
32903298
validation = validateOneOf(schema.items);
32913299
if (!validation.isValid) return validation;
32923300
}
32933301

3294-
if (schema.hasOwnProperty('anyOf')) {
3302+
if (schema.items.hasOwnProperty('anyOf')) {
32953303
validation = validateAnyOf(schema.items);
32963304
if (!validation.isValid) return validation;
32973305
}
32983306

3299-
if (schema.hasOwnProperty('allOf')) {
3300-
validation = validateAllOf(schema.items);
3301-
if (!validation.isValid) return validation;
3307+
if (schema.items.hasOwnProperty('allOf')) {
3308+
// we don't support allOf inside array yet
3309+
return {
3310+
isValid: false,
3311+
msg: "Currently, 'allOf' inside array items is not supported"
3312+
};
33023313
}
33033314

33043315
return {
@@ -3360,13 +3371,18 @@ function validateSubschemas(schema, keyword) {
33603371
keyword: one of 'oneOf' or 'anyOf' or 'allOf'
33613372
Validation:
33623373
1. Must be an array
3363-
2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
3374+
2. Must have at least one subschema
3375+
3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword
33643376
*/
33653377
let subschemas = schema[keyword];
33663378
if (!Array.isArray(subschemas)) return {
33673379
isValid: false,
33683380
msg: "'" + keyword + "' property must be an array"
33693381
};
3382+
if (!subschemas.length) return {
3383+
isValid: false,
3384+
msg: "'" + keyword + "' must contain at least one subschema"
3385+
};
33703386

33713387
for (let i = 0; i < subschemas.length; i++) {
33723388
let subschema = subschemas[i];
@@ -3752,6 +3768,14 @@ function DataValidator(schema) {
37523768

37533769
let next_validator = this.getValidator(next_type);
37543770

3771+
if (!next_validator) {
3772+
if (next_schema.hasOwnProperty('oneOf')) {
3773+
next_validator = this.validateOneOf;
3774+
} else if (next_schema.hasOwnProperty('anyOf')) {
3775+
next_validator = this.validateAnyOf;
3776+
} else if (next_schema.hasOwnProperty('anyOf')) ;
3777+
}
3778+
37553779
if (next_validator) {
37563780
for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i]));
37573781
} else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bhch/react-json-form",
3-
"version": "2.7.0",
3+
"version": "2.7.1",
44
"description": "Create forms using JSON Schema",
55
"publishConfig": {
66
"access": "public"

0 commit comments

Comments
 (0)