Skip to content

Commit dd21160

Browse files
committed
feat(input_schema): Add enumSuggestedValues property to input schema
1 parent 721e028 commit dd21160

File tree

4 files changed

+351
-61
lines changed

4 files changed

+351
-61
lines changed

packages/input_schema/src/input_schema.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,17 @@ function validateFieldAgainstSchemaDefinition(
174174
}
175175

176176
// If there are more matching definitions then we need to get the right one.
177-
// If the definition contains "enum" property then it's enum type.
178-
if ((fieldSchema as StringFieldDefinition).enum) {
179-
const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();
180-
if (!definition) throw new Error('Input schema validation failed to find "enum property" definition');
181-
validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}`);
182-
return;
183-
}
184177
// If the definition contains "resourceType" property then it's resource type.
185178
if ((fieldSchema as CommonResourceFieldDefinition<unknown>).resourceType) {
186179
const definition = matchingDefinitions.filter((item) => !!item.properties.resourceType).pop();
187180
if (!definition) throw new Error('Input schema validation failed to find "resource property" definition');
188181
validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}`);
189182
return;
190183
}
184+
191185
// Otherwise we use the other definition.
192-
const definition = matchingDefinitions.filter((item) => !item.properties.enum && !item.properties.resourceType).pop();
193-
if (!definition) throw new Error('Input schema validation failed to find other than "enum property" definition');
186+
const definition = matchingDefinitions.filter((item) => !item.properties.resourceType).pop();
187+
if (!definition) throw new Error('Input schema validation failed to find other than "resource property" definition');
194188

195189
validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}`);
196190
}

packages/input_schema/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export type StringFieldDefinition = CommonFieldDefinition<string> & {
1616
minLength?: number;
1717
maxLength?: number;
1818
enum?: readonly string[]; // required if editor is 'select'
19-
enumTitles?: readonly string[]
19+
enumTitles?: readonly string[];
20+
enumSuggestedValues?: readonly string[];
2021
isSecret?: boolean;
2122
// Used for 'datepicker' editor, absolute is considered as default value
2223
dateType?: 'absolute' | 'relative' | 'absoluteOrRelative';

packages/json_schemas/schemas/input.schema.json

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"^": {
3636
"oneOf": [
3737
{ "$ref": "#/definitions/stringProperty" },
38-
{ "$ref": "#/definitions/stringEnumProperty" },
3938
{ "$ref": "#/definitions/arrayProperty" },
4039
{ "$ref": "#/definitions/objectProperty" },
4140
{ "$ref": "#/definitions/integerProperty" },
@@ -52,43 +51,6 @@
5251
"additionalProperties": false,
5352
"required": ["title", "type", "properties", "schemaVersion"],
5453
"definitions": {
55-
"stringEnumProperty": {
56-
"title": "Enum property",
57-
"type": "object",
58-
"unevaluatedProperties": false,
59-
"properties": {
60-
"type": { "enum": ["string"] },
61-
"editor": { "enum": ["select"] },
62-
"title": { "type": "string" },
63-
"description": { "type": "string" },
64-
"prefill": { "type": "string" },
65-
"example": { "type": "string" },
66-
"nullable": { "type": "boolean" },
67-
"sectionCaption": { "type": "string" },
68-
"sectionDescription": { "type": "string" },
69-
"enum": {
70-
"type": "array",
71-
"items": { "type": "string" },
72-
"minItems": 1,
73-
"uniqueItems": true
74-
},
75-
"enumTitles": {
76-
"type": "array",
77-
"items": { "type": "string" },
78-
"minItems": 1
79-
}
80-
},
81-
"required": ["type", "title", "description", "enum"],
82-
"if": {
83-
"properties": { "nullable": { "const": false } }
84-
},
85-
"then": {
86-
"properties": { "default": { "type": "string" } }
87-
},
88-
"else": {
89-
"properties": { "default": { "type": ["string", "null"] } }
90-
}
91-
},
9254
"stringProperty": {
9355
"title": "String property",
9456
"type": "object",
@@ -98,17 +60,13 @@
9860
"title": { "type": "string" },
9961
"description": { "type": "string" },
10062
"nullable": { "type": "boolean" },
101-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "fileupload"] },
63+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "select", "fileupload", "hidden"] },
10264
"isSecret": { "type": "boolean" }
10365
},
10466
"required": ["type", "title", "description", "editor"],
10567
"if": {
10668
"properties": {
107-
"isSecret": {
108-
"not": {
109-
"const": true
110-
}
111-
}
69+
"isSecret": { "not": { "const": true } }
11270
}
11371
},
11472
"then": {
@@ -142,7 +100,7 @@
142100
},
143101
"else": {
144102
"properties": {
145-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
103+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "select", "fileupload", "hidden"] }
146104
}
147105
}
148106
},
@@ -156,6 +114,37 @@
156114
"else": {
157115
"properties": { "default": { "type": ["string", "null"] } }
158116
}
117+
},
118+
{
119+
"if": {
120+
"properties": {
121+
"editor": { "const": "select" }
122+
}
123+
},
124+
"then": {
125+
"properties": {
126+
"enum": {
127+
"type": "array",
128+
"items": { "type": "string" },
129+
"minItems": 1,
130+
"uniqueItems": true
131+
},
132+
"enumSuggestedValues": {
133+
"type": "array",
134+
"items": { "type": "string" },
135+
"minItems": 1
136+
},
137+
"enumTitles": {
138+
"type": "array",
139+
"items": { "type": "string" },
140+
"minItems": 1
141+
}
142+
},
143+
"oneOf": [
144+
{ "required": ["enum"] },
145+
{ "required": ["enumSuggestedValues"] }
146+
]
147+
}
159148
}
160149
]
161150
},
@@ -694,7 +683,7 @@
694683
"nullable": { "type": "boolean" },
695684
"minLength": { "type": "integer" },
696685
"maxLength": { "type": "integer" },
697-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "fileupload"] }
686+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "select", "fileupload", "hidden"] }
698687
},
699688
"required": ["type", "title", "description"],
700689
"allOf": [
@@ -712,7 +701,7 @@
712701
},
713702
"else": {
714703
"properties": {
715-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
704+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "select", "fileupload", "hidden"] }
716705
}
717706
}
718707
},
@@ -726,6 +715,37 @@
726715
"else": {
727716
"properties": { "default": { "type": ["string", "null"] } }
728717
}
718+
},
719+
{
720+
"if": {
721+
"properties": {
722+
"editor": { "const": "select" }
723+
}
724+
},
725+
"then": {
726+
"properties": {
727+
"enum": {
728+
"type": "array",
729+
"items": { "type": "string" },
730+
"minItems": 1,
731+
"uniqueItems": true
732+
},
733+
"enumSuggestedValues": {
734+
"type": "array",
735+
"items": { "type": "string" },
736+
"minItems": 1
737+
},
738+
"enumTitles": {
739+
"type": "array",
740+
"items": { "type": "string" },
741+
"minItems": 1
742+
}
743+
},
744+
"oneOf": [
745+
{ "required": ["enum"] },
746+
{ "required": ["enumSuggestedValues"] }
747+
]
748+
}
729749
}
730750
]
731751
},
@@ -1048,7 +1068,6 @@
10481068
"^": {
10491069
"oneOf": [
10501070
{ "$ref": "#/definitions/subSchemaStringProperty" },
1051-
{ "$ref": "#/definitions/subSchemaStringEnumProperty" },
10521071
{ "$ref": "#/definitions/subSchemaArrayProperty" },
10531072
{ "$ref": "#/definitions/subSchemaObjectProperty" },
10541073
{ "$ref": "#/definitions/subSchemaIntegerProperty" },
@@ -1137,9 +1156,17 @@
11371156
"enumTitles": {
11381157
"type": "array",
11391158
"items": { "type": "string" }
1159+
},
1160+
"enumSuggestedValues": {
1161+
"type": "array",
1162+
"items": { "type": "string" },
1163+
"minItems": 1
11401164
}
11411165
},
1142-
"required": ["type", "enum"]
1166+
"oneOf": [
1167+
{ "required": ["type", "enum"] },
1168+
{ "required": ["type", "enumSuggestedValues"] }
1169+
]
11431170
},
11441171
"arrayItemsKeyValue": {
11451172
"title": "Utils: Array items keyValue definition",
@@ -1470,7 +1497,6 @@
14701497
"^": {
14711498
"oneOf": [
14721499
{ "$ref": "#/definitions/subSchemaStringProperty" },
1473-
{ "$ref": "#/definitions/subSchemaStringEnumProperty" },
14741500
{ "$ref": "#/definitions/subSchemaArrayProperty" },
14751501
{ "$ref": "#/definitions/subSchemaObjectProperty" },
14761502
{ "$ref": "#/definitions/subSchemaIntegerProperty" },

0 commit comments

Comments
 (0)