Skip to content

Commit dc40a32

Browse files
authored
feat(input_schema): Add enumSuggestedValues property to input schema (#569)
Solves apify/apify-core#24101 - adds support for `enumSuggestedValues` property, that can be used instead of `enum` and it: - wouldn't trigger enum validation, value can be anything - would be used only on FE to render select which would accept inserting custom value I put this to `stringProperty`, accepting now `select` editor (only if `enumSuggestedValues` is specified), because it supports also other validation keywords (`pattern`,...) which makes totally sense to put another constraints on the custom value. (But there's no reason to allow these additional validation keywords when using `enum`.) Other things works still the same - `enum` can be defined only if `editor` is not defined or is `select` - `enumSuggestedValues` can be defined only if `editor` is `select`. - only one of `enum` or `enumSuggestedValues` can (must) be defined if `editor` is `select` - it works the same for arrays Draft with changes to make this work in UI is ready here: apify/apify-core#24164
1 parent 7847948 commit dc40a32

File tree

3 files changed

+335
-12
lines changed

3 files changed

+335
-12
lines changed

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: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,13 @@
9898
"title": { "type": "string" },
9999
"description": { "type": "string" },
100100
"nullable": { "type": "boolean" },
101-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "fileupload"] },
101+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "select", "fileupload", "hidden"] },
102102
"isSecret": { "type": "boolean" }
103103
},
104104
"required": ["type", "title", "description", "editor"],
105105
"if": {
106106
"properties": {
107-
"isSecret": {
108-
"not": {
109-
"const": true
110-
}
111-
}
107+
"isSecret": { "not": { "const": true } }
112108
}
113109
},
114110
"then": {
@@ -142,7 +138,7 @@
142138
},
143139
"else": {
144140
"properties": {
145-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
141+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "select", "fileupload", "hidden"] }
146142
}
147143
}
148144
},
@@ -156,6 +152,30 @@
156152
"else": {
157153
"properties": { "default": { "type": ["string", "null"] } }
158154
}
155+
},
156+
{
157+
"if": {
158+
"required": ["editor"],
159+
"properties": {
160+
"editor": { "const": "select" }
161+
}
162+
},
163+
"then": {
164+
"properties": {
165+
"enumSuggestedValues": {
166+
"type": "array",
167+
"items": { "type": "string" },
168+
"minItems": 1,
169+
"uniqueItems": true
170+
},
171+
"enumTitles": {
172+
"type": "array",
173+
"items": { "type": "string" },
174+
"minItems": 1
175+
}
176+
},
177+
"required": ["enumSuggestedValues"]
178+
}
159179
}
160180
]
161181
},
@@ -694,7 +714,7 @@
694714
"nullable": { "type": "boolean" },
695715
"minLength": { "type": "integer" },
696716
"maxLength": { "type": "integer" },
697-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "fileupload"] }
717+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "datepicker", "select", "fileupload", "hidden"] }
698718
},
699719
"required": ["type", "title", "description"],
700720
"allOf": [
@@ -712,7 +732,7 @@
712732
},
713733
"else": {
714734
"properties": {
715-
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
735+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "select", "fileupload", "hidden"] }
716736
}
717737
}
718738
},
@@ -726,6 +746,30 @@
726746
"else": {
727747
"properties": { "default": { "type": ["string", "null"] } }
728748
}
749+
},
750+
{
751+
"if": {
752+
"required": ["editor"],
753+
"properties": {
754+
"editor": { "const": "select" }
755+
}
756+
},
757+
"then": {
758+
"properties": {
759+
"enumSuggestedValues": {
760+
"type": "array",
761+
"items": { "type": "string" },
762+
"minItems": 1,
763+
"uniqueItems": true
764+
},
765+
"enumTitles": {
766+
"type": "array",
767+
"items": { "type": "string" },
768+
"minItems": 1
769+
}
770+
},
771+
"required": ["enumSuggestedValues"]
772+
}
729773
}
730774
]
731775
},
@@ -1137,9 +1181,18 @@
11371181
"enumTitles": {
11381182
"type": "array",
11391183
"items": { "type": "string" }
1184+
},
1185+
"enumSuggestedValues": {
1186+
"type": "array",
1187+
"items": { "type": "string" },
1188+
"minItems": 1,
1189+
"uniqueItems": true
11401190
}
11411191
},
1142-
"required": ["type", "enum"]
1192+
"oneOf": [
1193+
{ "required": ["type", "enum"] },
1194+
{ "required": ["type", "enumSuggestedValues"] }
1195+
]
11431196
},
11441197
"arrayItemsKeyValue": {
11451198
"title": "Utils: Array items keyValue definition",

0 commit comments

Comments
 (0)