@jsonforms/core 3.1.0-alpha.2 → 3.1.0-beta.0

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-beta.0",
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": "a5fdca6fb6afa9820eabe8051401785675f53ad7"
103
103
  }
@@ -38,7 +38,7 @@ const distinct = (
38
38
 
39
39
  return properties.filter((item) => {
40
40
  const discriminatorValue = discriminator(item);
41
- if (known.hasOwnProperty(discriminatorValue)) {
41
+ if (Object.prototype.hasOwnProperty.call(known, discriminatorValue)) {
42
42
  return false;
43
43
  } else {
44
44
  known[discriminatorValue] = true;
@@ -155,13 +155,17 @@ export const generateJsonSchema = (
155
155
  (optionName: string): boolean | string[] => {
156
156
  switch (optionName) {
157
157
  case ADDITIONAL_PROPERTIES:
158
- if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
158
+ if (
159
+ Object.prototype.hasOwnProperty.call(options, ADDITIONAL_PROPERTIES)
160
+ ) {
159
161
  return options[ADDITIONAL_PROPERTIES];
160
162
  }
161
163
 
162
164
  return true;
163
165
  case REQUIRED_PROPERTIES:
164
- if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
166
+ if (
167
+ Object.prototype.hasOwnProperty.call(options, REQUIRED_PROPERTIES)
168
+ ) {
165
169
  return options[REQUIRED_PROPERTIES](props);
166
170
  }
167
171
 
@@ -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 = (
@@ -90,7 +90,10 @@ const initState: JsonFormsCore = {
90
90
  };
91
91
 
92
92
  const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
93
- if (schema.hasOwnProperty('id') || schema.hasOwnProperty('$id')) {
93
+ if (
94
+ Object.prototype.hasOwnProperty.call(schema, 'id') ||
95
+ Object.prototype.hasOwnProperty.call(schema, '$id')
96
+ ) {
94
97
  ajv.removeSchema(schema);
95
98
  }
96
99
  return ajv;
@@ -389,7 +392,11 @@ export const errorsAt =
389
392
 
390
393
  return filter(errors, (error) => {
391
394
  // Filter errors that match any keyword that we don't want to show in the UI
392
- if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
395
+ // but keep the errors for oneOf enums
396
+ if (
397
+ filteredErrorKeywords.indexOf(error.keyword) !== -1 &&
398
+ !isOneOfEnumSchema(error.parentSchema)
399
+ ) {
393
400
  return false;
394
401
  }
395
402
  const controlPath = getControlPath(error);
@@ -400,12 +407,13 @@ export const errorsAt =
400
407
  // In the primitive case the error's data path is the same for all subschemas:
401
408
  // It directly points to the property defining the anyOf/oneOf.
402
409
  // 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
410
+ // In contrast, this comparison must not be done for errors whose parent schema defines an object or a oneOf enum,
404
411
  // because the parent schema can never match the property schema (e.g. for 'required' checks).
405
412
  const parentSchema: JsonSchema | undefined = error.parentSchema;
406
413
  if (
407
414
  result &&
408
415
  !isObjectSchema(parentSchema) &&
416
+ !isOneOfEnumSchema(parentSchema) &&
409
417
  combinatorPaths.findIndex((p) => instancePath.startsWith(p)) !== -1
410
418
  ) {
411
419
  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
@@ -320,17 +325,23 @@ export const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));
320
325
 
321
326
  export const isAllOfControl = and(
322
327
  uiTypeIs('Control'),
323
- schemaMatches((schema) => schema.hasOwnProperty('allOf'))
328
+ schemaMatches((schema) =>
329
+ Object.prototype.hasOwnProperty.call(schema, 'allOf')
330
+ )
324
331
  );
325
332
 
326
333
  export const isAnyOfControl = and(
327
334
  uiTypeIs('Control'),
328
- schemaMatches((schema) => schema.hasOwnProperty('anyOf'))
335
+ schemaMatches((schema) =>
336
+ Object.prototype.hasOwnProperty.call(schema, 'anyOf')
337
+ )
329
338
  );
330
339
 
331
340
  export const isOneOfControl = and(
332
341
  uiTypeIs('Control'),
333
- schemaMatches((schema) => schema.hasOwnProperty('oneOf'))
342
+ schemaMatches((schema) =>
343
+ Object.prototype.hasOwnProperty.call(schema, 'oneOf')
344
+ )
334
345
  );
335
346
 
336
347
  /**
@@ -341,8 +352,12 @@ export const isOneOfControl = and(
341
352
  export const isEnumControl = and(
342
353
  uiTypeIs('Control'),
343
354
  or(
344
- schemaMatches((schema) => schema.hasOwnProperty('enum')),
345
- schemaMatches((schema) => schema.hasOwnProperty('const'))
355
+ schemaMatches((schema) =>
356
+ Object.prototype.hasOwnProperty.call(schema, 'enum')
357
+ ),
358
+ schemaMatches((schema) =>
359
+ Object.prototype.hasOwnProperty.call(schema, 'const')
360
+ )
346
361
  )
347
362
  );
348
363
 
@@ -353,11 +368,7 @@ export const isEnumControl = and(
353
368
  */
354
369
  export const isOneOfEnumControl = and(
355
370
  uiTypeIs('Control'),
356
- schemaMatches(
357
- (schema) =>
358
- schema.hasOwnProperty('oneOf') &&
359
- (schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined)
360
- )
371
+ schemaMatches((schema) => isOneOfEnumSchema(schema))
361
372
  );
362
373
 
363
374
  /**
@@ -517,7 +528,7 @@ export const isObjectArrayWithNesting = (
517
528
  if (val.anyOf || val.allOf) {
518
529
  return true;
519
530
  }
520
- if (val.oneOf && !isOneOfEnumControl(uischema, val, context)) {
531
+ if (val.oneOf && !isOneOfEnumSchema(val)) {
521
532
  return true;
522
533
  }
523
534
  if (hasType(val, 'object')) {
@@ -591,9 +602,9 @@ export const isRangeControl = and(
591
602
  or(schemaTypeIs('number'), schemaTypeIs('integer')),
592
603
  schemaMatches(
593
604
  (schema) =>
594
- schema.hasOwnProperty('maximum') &&
595
- schema.hasOwnProperty('minimum') &&
596
- schema.hasOwnProperty('default')
605
+ Object.prototype.hasOwnProperty.call(schema, 'maximum') &&
606
+ Object.prototype.hasOwnProperty.call(schema, 'minimum') &&
607
+ Object.prototype.hasOwnProperty.call(schema, 'default')
597
608
  ),
598
609
  optionIs('slider', true)
599
610
  );
@@ -49,7 +49,10 @@ export const resolveData = (instance: any, dataPath: string): any => {
49
49
  const dataPathSegments = dataPath.split('.');
50
50
 
51
51
  return dataPathSegments.reduce((curInstance, decodedSegment) => {
52
- if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
52
+ if (
53
+ !curInstance ||
54
+ !Object.prototype.hasOwnProperty.call(curInstance, decodedSegment)
55
+ ) {
53
56
  return undefined;
54
57
  }
55
58
 
@@ -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,12 @@ 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 &&
48
+ Object.prototype.hasOwnProperty.call(schema, 'oneOf') &&
49
+ schema.oneOf &&
50
+ (schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);