@@ -7,7 +7,9 @@ import { getColumnDataPropTypeShape } from "./renderDataUtils";
7
7
8
8
import JsonSchemaGroup from "../model/JsonSchemaGroup" ;
9
9
import { createOptionTargetArrayFromIndexes , getFieldValueFromSchemaGroup } from "../model/schemaUtils" ;
10
- import { isDefined , listValues } from "../model/utils" ;
10
+ import {
11
+ isDefined , listValues , commonValues , minimumValue , maximumValue
12
+ } from "../model/utils" ;
11
13
12
14
function checkIfIsRequired ( columnData , selectionColumnIndex ) {
13
15
if ( ! selectionColumnIndex ) {
@@ -33,6 +35,17 @@ function checkIfIsRequired(columnData, selectionColumnIndex) {
33
35
return checkIfIsRequired ( columnData , selectionColumnIndex - 1 ) ;
34
36
}
35
37
38
+ function containsTrueOrReduce ( allValues , reduceNonBooleans ) {
39
+ if ( ! Array . isArray ( allValues ) ) {
40
+ // return single value as-is
41
+ return allValues ;
42
+ }
43
+ if ( allValues . includes ( true ) ) {
44
+ return true ;
45
+ }
46
+ return allValues . reduce ( reduceNonBooleans ) ;
47
+ }
48
+
36
49
export const collectFormFields = ( itemSchemaGroup , columnData , selectionColumnIndex ) => {
37
50
const formFields = [ ] ;
38
51
const addFormField = ( labelText , rowValue ) => {
@@ -42,19 +55,30 @@ export const collectFormFields = (itemSchemaGroup, columnData, selectionColumnIn
42
55
} ;
43
56
const { selectedItem } = columnData [ selectionColumnIndex ] ;
44
57
const optionIndexes = typeof selectedItem === "string" ? undefined : selectedItem ;
45
- const getValue = fieldName => getFieldValueFromSchemaGroup ( itemSchemaGroup , fieldName , listValues , undefined , undefined , optionIndexes ) ;
58
+ const getValue = ( fieldName , mergeValues = listValues ) => getFieldValueFromSchemaGroup (
59
+ itemSchemaGroup , fieldName , mergeValues , undefined , undefined , optionIndexes
60
+ ) ;
46
61
47
62
addFormField ( "Title" , getValue ( "title" ) ) ;
48
63
addFormField ( "Description" , getValue ( "description" ) ) ;
49
64
50
65
addFormField ( "Required" , checkIfIsRequired ( columnData , selectionColumnIndex ) ? "Yes" : null ) ;
51
66
52
- addFormField ( "Type" , getValue ( "type" ) ) ;
53
- addFormField ( "Constant Value" , getValue ( "const" ) ) ;
54
- addFormField ( "Possible Values" , getValue ( "enum" ) ) ;
67
+ addFormField ( "Type" , getValue ( "type" , commonValues ) ) ;
68
+ const enumValues = commonValues ( getValue ( "const" , commonValues ) , getValue ( "enum" , commonValues ) ) ;
69
+ if ( isDefined ( enumValues ) ) {
70
+ if ( ! Array . isArray ( enumValues ) ) {
71
+ addFormField ( "Constant Value" , enumValues ) ;
72
+ } else if ( enumValues . length === 1 ) {
73
+ addFormField ( "Constant Value" , enumValues [ 0 ] ) ;
74
+ } else {
75
+ addFormField ( "Possible Values" , enumValues ) ;
76
+ }
77
+ }
55
78
56
- const minimum = getValue ( "minimum" ) ;
57
- const exclusiveMinimum = getValue ( "exclusiveMinimum" ) ;
79
+ // if multiple minimums are specified (in allOf parts), the highest minimum applies
80
+ const minimum = getValue ( "minimum" , maximumValue ) ;
81
+ const exclusiveMinimum = containsTrueOrReduce ( getValue ( "exclusiveMinimum" ) , maximumValue ) ;
58
82
let minValue ;
59
83
if ( isDefined ( minimum ) ) {
60
84
// according to JSON Schema Draft 4, "exclusiveMinimum" is a boolean and used in combination with "minimum"
@@ -66,8 +90,9 @@ export const collectFormFields = (itemSchemaGroup, columnData, selectionColumnIn
66
90
}
67
91
addFormField ( "Min Value" , minValue ) ;
68
92
69
- const maximum = getValue ( "maximum" ) ;
70
- const exclusiveMaximum = getValue ( "exclusiveMaximum" ) ;
93
+ // if multiple maximums are specified (in allOf parts), the lowest maximum applies
94
+ const maximum = getValue ( "maximum" , minimumValue ) ;
95
+ const exclusiveMaximum = containsTrueOrReduce ( getValue ( "exclusiveMaximum" ) , minimumValue ) ;
71
96
let maxValue ;
72
97
if ( isDefined ( maximum ) ) {
73
98
// according to JSON Schema Draft 4, "exclusiveMaximum" is a boolean and used in combination with "maximum"
@@ -86,12 +111,14 @@ export const collectFormFields = (itemSchemaGroup, columnData, selectionColumnIn
86
111
addFormField ( "Example(s)" ,
87
112
( examples && typeof examples [ 0 ] === "object" ) ? JSON . stringify ( examples ) : examples ) ;
88
113
addFormField ( "Value Pattern" , getValue ( "pattern" ) ) ;
89
- addFormField ( "Value Format" , getValue ( "format" ) ) ;
90
- addFormField ( "Min Length" , getValue ( "minLength" ) ) ;
91
- addFormField ( "Max Length" , getValue ( "maxLength" ) ) ;
92
- addFormField ( "Min Items" , getValue ( "minItems" ) ) ;
93
- addFormField ( "Max Items" , getValue ( "maxItems" ) ) ;
94
- addFormField ( "Items Unique" , getValue ( "uniqueItems" ) === true ? "Yes" : null ) ;
114
+ addFormField ( "Value Format" , getValue ( "format" , commonValues ) ) ;
115
+ // if multiple minimums are specified (in allOf parts), the highest minimum applies
116
+ addFormField ( "Min Length" , getValue ( "minLength" , maximumValue ) ) ;
117
+ // if multiple maximums are specified (in allOf parts), the lowest maximum applies
118
+ addFormField ( "Max Length" , getValue ( "maxLength" , minimumValue ) ) ;
119
+ addFormField ( "Min Items" , getValue ( "minItems" , maximumValue ) ) ;
120
+ addFormField ( "Max Items" , getValue ( "maxItems" , minimumValue ) ) ;
121
+ addFormField ( "Items Unique" , containsTrueOrReduce ( getValue ( "uniqueItems" ) ) ? "Yes" : null ) ;
95
122
96
123
return formFields ;
97
124
} ;
0 commit comments