@jsonforms/core 3.1.0-alpha.2 → 3.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/jsonforms-core.cjs.js +11 -6
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +9 -5
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/util/schema.d.ts +5 -0
- package/package.json +2 -2
- package/src/reducers/core.ts +8 -3
- package/src/testers/testers.ts +8 -7
- package/src/util/schema.ts +9 -0
package/lib/util/schema.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonforms/core",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.3",
|
|
4
4
|
"description": "Core module of JSON Forms",
|
|
5
5
|
"repository": "https://github.com/eclipsesource/jsonforms",
|
|
6
6
|
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"typedoc": "^0.19.2",
|
|
100
100
|
"typescript": "4.2.3"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "f8ea38f9f9dd3d46cbfde269ec43e9eb1632e428"
|
|
103
103
|
}
|
package/src/reducers/core.ts
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
UPDATE_CORE,
|
|
46
46
|
UpdateCoreAction,
|
|
47
47
|
} from '../actions';
|
|
48
|
-
import { createAjv, Reducer } from '../util';
|
|
48
|
+
import { createAjv, isOneOfEnumSchema, Reducer } from '../util';
|
|
49
49
|
import type { JsonSchema, UISchemaElement } from '../models';
|
|
50
50
|
|
|
51
51
|
export const validate = (
|
|
@@ -389,7 +389,11 @@ export const errorsAt =
|
|
|
389
389
|
|
|
390
390
|
return filter(errors, (error) => {
|
|
391
391
|
// Filter errors that match any keyword that we don't want to show in the UI
|
|
392
|
-
|
|
392
|
+
// but keep the errors for oneOf enums
|
|
393
|
+
if (
|
|
394
|
+
filteredErrorKeywords.indexOf(error.keyword) !== -1 &&
|
|
395
|
+
!isOneOfEnumSchema(error.parentSchema)
|
|
396
|
+
) {
|
|
393
397
|
return false;
|
|
394
398
|
}
|
|
395
399
|
const controlPath = getControlPath(error);
|
|
@@ -400,12 +404,13 @@ export const errorsAt =
|
|
|
400
404
|
// In the primitive case the error's data path is the same for all subschemas:
|
|
401
405
|
// It directly points to the property defining the anyOf/oneOf.
|
|
402
406
|
// The same holds true for errors on the array level (e.g. min item amount).
|
|
403
|
-
// In contrast, this comparison must not be done for errors whose parent schema defines an object
|
|
407
|
+
// In contrast, this comparison must not be done for errors whose parent schema defines an object or a oneOf enum,
|
|
404
408
|
// because the parent schema can never match the property schema (e.g. for 'required' checks).
|
|
405
409
|
const parentSchema: JsonSchema | undefined = error.parentSchema;
|
|
406
410
|
if (
|
|
407
411
|
result &&
|
|
408
412
|
!isObjectSchema(parentSchema) &&
|
|
413
|
+
!isOneOfEnumSchema(parentSchema) &&
|
|
409
414
|
combinatorPaths.findIndex((p) => instancePath.startsWith(p)) !== -1
|
|
410
415
|
) {
|
|
411
416
|
result = result && isEqual(parentSchema, schema);
|
package/src/testers/testers.ts
CHANGED
|
@@ -37,7 +37,12 @@ import type {
|
|
|
37
37
|
JsonSchema,
|
|
38
38
|
UISchemaElement,
|
|
39
39
|
} from '../models';
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
deriveTypes,
|
|
42
|
+
hasType,
|
|
43
|
+
isOneOfEnumSchema,
|
|
44
|
+
resolveSchema,
|
|
45
|
+
} from '../util';
|
|
41
46
|
|
|
42
47
|
/**
|
|
43
48
|
* Constant that indicates that a tester is not capable of handling
|
|
@@ -353,11 +358,7 @@ export const isEnumControl = and(
|
|
|
353
358
|
*/
|
|
354
359
|
export const isOneOfEnumControl = and(
|
|
355
360
|
uiTypeIs('Control'),
|
|
356
|
-
schemaMatches(
|
|
357
|
-
(schema) =>
|
|
358
|
-
schema.hasOwnProperty('oneOf') &&
|
|
359
|
-
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined)
|
|
360
|
-
)
|
|
361
|
+
schemaMatches((schema) => isOneOfEnumSchema(schema))
|
|
361
362
|
);
|
|
362
363
|
|
|
363
364
|
/**
|
|
@@ -517,7 +518,7 @@ export const isObjectArrayWithNesting = (
|
|
|
517
518
|
if (val.anyOf || val.allOf) {
|
|
518
519
|
return true;
|
|
519
520
|
}
|
|
520
|
-
if (val.oneOf && !
|
|
521
|
+
if (val.oneOf && !isOneOfEnumSchema(val)) {
|
|
521
522
|
return true;
|
|
522
523
|
}
|
|
523
524
|
if (hasType(val, 'object')) {
|
package/src/util/schema.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import find from 'lodash/find';
|
|
27
|
+
import { JsonSchema } from '../models';
|
|
27
28
|
|
|
28
29
|
export const getFirstPrimitiveProp = (schema: any) => {
|
|
29
30
|
if (schema.properties) {
|
|
@@ -38,3 +39,11 @@ export const getFirstPrimitiveProp = (schema: any) => {
|
|
|
38
39
|
}
|
|
39
40
|
return undefined;
|
|
40
41
|
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Tests whether the schema has an enum based on oneOf.
|
|
45
|
+
*/
|
|
46
|
+
export const isOneOfEnumSchema = (schema: JsonSchema) =>
|
|
47
|
+
schema?.hasOwnProperty('oneOf') &&
|
|
48
|
+
schema?.oneOf &&
|
|
49
|
+
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);
|