Skip to content

Commit 0097eab

Browse files
Normalize script input; update OpenAPI types
- Update OpenAPI annotations in ScriptController to declare 'data' and 'config' as objects instead of arrays. - Add getRequestArray() to normalize script inputs: decode JSON strings to arrays, detect list payloads and unwrap single-element list objects (e.g. [{}] or [{"key":"value"}) to an associative object, and return an empty array for unsupported forms. This prevents the script microservice from rejecting list-shaped payloads (422) and enforces consistent request shapes.
1 parent d231f1e commit 0097eab

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

ProcessMaker/Http/Controllers/Api/ScriptController.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,11 @@ public function index(Request $request)
159159
* @OA\JsonContent(
160160
* @OA\Property(
161161
* property="data",
162-
* type="array",
163-
* @OA\Items (type="object"),
162+
* type="object",
164163
* ),
165164
* @OA\Property(
166165
* property="config",
167-
* type="array",
168-
* @OA\Items (type="object"),
166+
* type="object",
169167
* ),
170168
* @OA\Property(
171169
* property="code",
@@ -215,13 +213,11 @@ public function preview(Request $request, Script $script)
215213
* @OA\JsonContent(
216214
* @OA\Property(
217215
* property="data",
218-
* type="array",
219-
* @OA\Items (type="object"),
216+
* type="object",
220217
* ),
221218
* @OA\Property(
222219
* property="config",
223-
* type="array",
224-
* @OA\Items (type="object"),
220+
* type="object",
225221
* ),
226222
* @OA\Property(
227223
* property="sync",
@@ -562,16 +558,28 @@ public function close(Script $script)
562558
return response([], 204);
563559
}
564560

561+
/**
562+
* Normalize script input before executing the script.
563+
* Script data and config must be an object (associative array), the script
564+
* microservice rejects list payloads like [{}] with a 422.
565+
*/
565566
private function getRequestArray($value): array
566567
{
567-
if (is_array($value)) {
568-
return $value;
568+
if (is_string($value)) {
569+
$value = json_decode($value, true);
569570
}
570571

571-
if (is_string($value)) {
572-
return json_decode($value, true) ?: [];
572+
$result = [];
573+
574+
if (is_array($value)) {
575+
if (!array_is_list($value)) {
576+
$result = $value;
577+
} elseif (count($value) === 1 && is_array($value[0])) {
578+
// Unwrap [{}] or [{"key": "value"}] to object form; ignore other lists.
579+
$result = $value[0];
580+
}
573581
}
574582

575-
return [];
583+
return $result;
576584
}
577585
}

0 commit comments

Comments
 (0)