You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sources/platform/actors/development/actor_definition/input_schema/specification.md
+96-4Lines changed: 96 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -416,7 +416,7 @@ Properties:
416
416
#### Object fields validation
417
417
418
418
In the same way as in the root-level input schema, a schema can be defined for sub-properties of an object using the `properties` field.
419
-
Each sub-property within this sub-schema can define the same fields as those available at the root level of the input schema, except for the fields that apply only at the root level: `sectionCaption`, `sectionDescription`, `prefill`, `example`, and `default`.
419
+
Each sub-property within this sub-schema can define the same fields as those available at the root level of the input schema, except for the fields that apply only at the root level: `sectionCaption`and `sectionDescription`.
420
420
421
421
Validation is performed both in the UI and during actor execution via the API.
422
422
Sub-schema validation works independently of the editor selected for the parent object. It also respects the `additionalProperties` and `required` fields, allowing precise control over whether properties not defined in `properties` are permitted and which properties are mandatory.
@@ -427,7 +427,6 @@ Object sub-properties can also define their own sub-schemas recursively, without
427
427
428
428
:::
429
429
430
-
431
430
Example of an object property with sub-schema properties:
432
431
433
432
```json
@@ -472,6 +471,48 @@ In this example, the object has validation rules for its properties:
472
471
- The `timeout` and `locale` properties are required
473
472
- No additional properties beyond those defined are allowed
474
473
474
+
**Handling default and prefill values for object sub-properties**
475
+
476
+
When defining object with sub-properties, it's possible to set `default` and `prefill` values in two ways:
477
+
1.**At the parent object level**: You can provide a complete object as the `default` or `prefill` value, which will set values for all sub-properties at once.
478
+
2.**At the individual sub-property level**: You can specify `default` or `prefill` values for each sub-property separately within the `properties` definition.
479
+
480
+
When both methods are used, the values defined at the parent object level take precedence over those defined at the sub-property level.
481
+
For example, in the input schema like this:
482
+
483
+
```json
484
+
{
485
+
"title": "Configuration",
486
+
"type": "object",
487
+
"description": "Advanced configuration options",
488
+
"editor": "schemaBased",
489
+
"default": {
490
+
"timeout": 60
491
+
},
492
+
"properties": {
493
+
"locale": {
494
+
"title": "Locale",
495
+
"type": "string",
496
+
"description": "Locale identifier.",
497
+
"pattern": "^[a-z]{2,3}-[A-Z]{2}$",
498
+
"editor": "textfield",
499
+
"default": "en-US"
500
+
},
501
+
"timeout": {
502
+
"title": "Timeout",
503
+
"type": "integer",
504
+
"description": "Request timeout in seconds",
505
+
"minimum": 1,
506
+
"maximum": 300,
507
+
"editor": "number",
508
+
"default": 120
509
+
}
510
+
}
511
+
}
512
+
```
513
+
514
+
The `timeout` sub-property will have a default value of `60` (from the parent object), while the `locale` sub-property will have a default value of `"en-US"` (from its own definition).
515
+
475
516
#### `schemaBased` editor
476
517
477
518
Object with sub-schema defined can use the `schemaBased` editor, which provides a user-friendly interface for editing each property individually.
@@ -615,7 +656,9 @@ To correctly define options for multiselect, you need to define the `items` prop
615
656
#### Array items validation
616
657
617
658
Arrays in the input schema can define an `items` field to specify the type and validation rules for each item.
618
-
Each array item is validated according to its `type`. If the item is an `object`, it can define its own `properties`, `required`, and `additionalProperties` fields,
659
+
Each array item is validated according to its `type` and inside the `items` field it's also possible to define additional validation rules such as `pattern`, `minimum`, `maximum`, etc., depending on the item type.
660
+
661
+
If the item type is an `object`, it can define its own `properties`, `required`, and `additionalProperties` fields,
619
662
working in the same way as a single object field (see [Object fields validation](#object-fields-validation)).
620
663
621
664
Validation is performed both in the UI and during actor execution via the API.
@@ -664,6 +707,54 @@ In this example:
664
707
- No additional properties beyond those defined are allowed.
665
708
- The validation of each object item works the same as for a single object field (see [Object fields validation](#object-fields-validation)).
666
709
710
+
**Handling default and prefill values array with object sub-properties**
711
+
712
+
When defining an array of objects with sub-properties, it's possible to set `default` and `prefill` values in two ways:
713
+
1.**At the parent array level**: You can provide an array of complete objects as the `default` or `prefill` value, which will be used only if there is no value specified for the field.
714
+
2.**At the individual sub-property level**: You can specify `default` or `prefill` values for each sub-property within the `properties` definition of the object items. These values will be applied to each object in the array value.
715
+
716
+
For example, having an input schema like this:
717
+
718
+
```json
719
+
{
720
+
"title": "Requests",
721
+
"type": "array",
722
+
"description": "List of HTTP requests",
723
+
"editor": "schemaBased",
724
+
"default": [
725
+
{ "url": "https://apify.com", "port": 80 }
726
+
],
727
+
"items": {
728
+
"type": "object",
729
+
"properties": {
730
+
"url": {
731
+
"title": "URL",
732
+
"type": "string",
733
+
"description": "Request URL",
734
+
"editor": "textfield"
735
+
},
736
+
"port": {
737
+
"title": "Port",
738
+
"type": "integer",
739
+
"description": "Request port",
740
+
"editor": "number",
741
+
"default": 8080
742
+
}
743
+
},
744
+
"required": ["url", "port"],
745
+
"additionalProperties": false
746
+
}
747
+
}
748
+
```
749
+
750
+
If there is no value specified for the field, the array will default to containing one object:
751
+
```json
752
+
[
753
+
{ "url": "https://apify.com", "port": 80 }
754
+
]
755
+
```
756
+
However, if the user adds a new item to the array, the `port` sub-property of that new object will default to `8080`, as defined in the sub-property itself.
757
+
667
758
#### `schemaBased` editor
668
759
669
760
Arrays can use the `schemaBased` editor to provide a user-friendly interface for editing each item individually.
@@ -680,7 +771,8 @@ Example 1: Array of strings using the `schemaBased` editor:
680
771
"description": "List of URLs for the scraper to visit",
0 commit comments