浏览代码

Turn off autocomplete in Try It Out; make sure it works for array body

shalvah 4 年之前
父节点
当前提交
579f672b57

+ 6 - 0
camel/Output/OutputEndpointData.php

@@ -150,6 +150,12 @@ class OutputEndpointData extends BaseDTO
         return count($this->fileParameters) > 0;
     }
 
+    public function isArrayBody(): bool
+    {
+        return count($this->nestedBodyParameters) === 1
+            && array_keys($this->nestedBodyParameters)[0] === "[]";
+    }
+
     public function isGet(): bool
     {
         return in_array('GET', $this->httpMethods);

+ 7 - 4
resources/js/tryitout.js

@@ -142,12 +142,15 @@ async function executeTryOut(endpointId, form) {
 
     let body;
     let setter;
-    if (form.dataset.hasfiles === "0") {
-        body = {};
-        setter = (name, value) => _.set(body, name, value);
-    } else {
+    if (form.dataset.hasfiles === "1") {
         body = new FormData();
         setter = (name, value) => body.append(name, value);
+    } else if (form.dataset.isarraybody === "1") {
+        body = [];
+        setter = (name, value) => _.set(body, name, value);
+    } else {
+        body = {};
+        setter = (name, value) => _.set(body, name, value);
     }
     const bodyParameters = form.querySelectorAll('input[data-component=body]');
     bodyParameters.forEach(el => {

+ 2 - 0
resources/views/components/field-details.blade.php

@@ -10,6 +10,8 @@
             $fullName .= '.0';
             $baseType = substr($baseType, 0, -2);
         }
+        // When the body is an array, the item names will be ".0.thing"
+        $fullName = ltrim($fullName, '.');
         switch($baseType) {
             case 'number':
             case 'integer':

+ 2 - 0
resources/views/themes/default/endpoint.blade.php

@@ -63,7 +63,9 @@
       data-path="{{ $endpoint->uri }}"
       data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
       data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
+      data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
       data-headers='@json($endpoint->headers)'
+      autocomplete="off"
       onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
     <h3>
         Request&nbsp;&nbsp;&nbsp;

+ 1 - 1
src/Commands/GenerateDocumentation.php

@@ -84,7 +84,7 @@ class GenerateDocumentation extends Command
             throw new \Exception("Can't use --force and --no-extraction together.");
         }
 
-        // Reset this map useful for tests)
+        // Reset this map (useful for tests)
         Camel::$groupFileNames = [];
     }