# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/externallib.php
--- moodle/lib/externallib.php Base (1.17)
+++ moodle/lib/externallib.php Locally Modified (Based On 1.17)
@@ -140,9 +140,10 @@
      * each implementation method of external API.
      * @param external_description $description description of parameters
      * @param mixed $params the actual parameters
-     * @return mixed params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
+     * @param mixed $returnFullArray if true, the returned array contains all optional attribution the description even the optional attributs not in $params
+     * * @return mixed params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
      */
-    public static function validate_parameters(external_description $description, $params) {
+    public static function validate_parameters(external_description $description, $params, $returnFullArray = true) {
         if ($description instanceof external_value) {
             if (is_array($params) or is_object($params)) {
                 throw new invalid_parameter_exception('Scalar type expected, array or object received.');
@@ -154,7 +155,7 @@
                     return (bool)$params;
                 }
             }
-            return validate_param($params, $description->type, $description->allownull, 'Invalid external api parameter');
+            return validate_param($params, $description->type, $description->allownull, 'Invalid external api parameter on: '.$description->desc);
 
         } else if ($description instanceof external_single_structure) {
             if (!is_array($params)) {
@@ -167,10 +168,12 @@
                         throw new invalid_parameter_exception('Missing required key in single structure.');
                     }
                     if ($subdesc instanceof external_value) {
-                        $result[$key] = self::validate_parameters($subdesc, $subdesc->default);
+                        if ($returnFullArray) {
+                            $result[$key] = self::validate_parameters($subdesc, $subdesc->default, $returnFullArray);
                     }
+                    }
                 } else {
-                    $result[$key] = self::validate_parameters($subdesc, $params[$key]);
+                    $result[$key] = self::validate_parameters($subdesc, $params[$key], $returnFullArray);
                 }
                 unset($params[$key]);
             }
@@ -185,7 +188,7 @@
             }
             $result = array();
             foreach ($params as $param) {
-                $result[] = self::validate_parameters($description->content, $param);
+                $result[] = self::validate_parameters($description->content, $param, $returnFullArray);
             }
             return $result;
 
