]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/TestsApi.php
Code cleanup, bug squashing
[bookstack] / tests / Api / TestsApi.php
index 623fa6969a7128bf9652f9e50e16fa710d29ac54..1ad4d14b64e4c7137134552848b1f7c800dbed6f 100644 (file)
@@ -23,6 +23,16 @@ trait TestsApi
         return ["error" => ["code" => $code, "message" => $message]];
     }
 
+    /**
+     * Format the given (field_name => ["messages"]) array
+     * into a standard validation response format.
+     */
+    protected function validationResponse(array $messages): array
+    {
+        $err = $this->errorResponse("The given data was invalid.", 422);
+        $err['error']['validation'] = $messages;
+        return $err;
+    }
     /**
      * Get an approved API auth header.
      */