@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.
@@ -1 +1,6 @@
1
+ import { JsonSchema } from '../models';
1
2
  export declare const getFirstPrimitiveProp: (schema: any) => string;
3
+ /**
4
+ * Tests whether the schema has an enum based on oneOf.
5
+ */
6
+ export declare const isOneOfEnumSchema: (schema: JsonSchema) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/core",
3
- "version": "3.1.0-alpha.2",
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": "1e1ccad5f7ebfaf80412c8af3e422faebb12d0d5"
102
+ "gitHead": "f8ea38f9f9dd3d46cbfde269ec43e9eb1632e428"
103
103
  }
@@ -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
- if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
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);
@@ -37,7 +37,12 @@ import type {
37
37
  JsonSchema,
38
38
  UISchemaElement,
39
39
  } from '../models';
40
- import { deriveTypes, hasType, resolveSchema } from '../util';
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 && !isOneOfEnumControl(uischema, val, context)) {
521
+ if (val.oneOf && !isOneOfEnumSchema(val)) {
521
522
  return true;
522
523
  }
523
524
  if (hasType(val, 'object')) {
@@ -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);