Browse Source

Update from v2

shalvah 4 years ago
parent
commit
01a7a362f6

+ 21 - 0
CHANGELOG-2.x.md

@@ -12,6 +12,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Removals
 
+## 2.7.0 (Friday, 21 May 2021)
+### Modified
+- Use Laravel `public_path` rather than `public/` for assets (https://github.com/knuckleswtf/scribe/pull/214)
+### Fixed
+- Format form-data params properly in Postman collection (https://github.com/knuckleswtf/scribe/pull/198)
+- Unescape Unicode values in Postman collection (https://github.com/knuckleswtf/scribe/pull/207)
+
+## 2.6.0 (Thursday, 8 April 2021)
+### Modified
+- Try It Out: set input field type to "password" if field name contains "password" (https://github.com/knuckleswtf/scribe/pull/195)
+- Include responses in Postman Collection (https://github.com/knuckleswtf/scribe/pull/196)
+
+## 2.5.3 (Thursday, 11 February 2021)
+### Fixes
+- Properly serialize objects in PHP example request (https://github.com/knuckleswtf/scribe/commit/8059566ef39ec09ebd7eb36ecd2e65d20f0dd2bc)
+- Don't include Content-Type header in Guzzle examples (https://github.com/knuckleswtf/scribe/commit/6a1e7504ec4c5a17e4e97996536bd16398823703)
+
+## 2.5.2 (Monday, 25 January, 2021)
+### Fixes
+- Change check for legacy-style factories to check for new style instead. (https://github.com/knuckleswtf/scribe/pull/181)
+
 ## 2.5.1 (Wednesday, 16 December 2020)
 - PHP 8 support (https://github.com/knuckleswtf/scribe/pull/162)
 

+ 4 - 1
resources/views/partials/example-requests/php.blade.php

@@ -8,7 +8,10 @@ $client = new \GuzzleHttp\Client();
 $response = $client->{{ strtolower($endpoint->methods[0]) }}(
     '{{ rtrim($baseUrl, '/') . '/' . ltrim($endpoint->boundUri, '/') }}',
     [
-@if(!empty($endpoint->headers))
+@if(!empty($endpoint->headers))@php
+// We don't need the Content-Type header because Guzzle sets it automatically when you use json or multipart.
+unset($route['headers']['Content-Type']);
+@endphp
         'headers' => {!! u::printPhpValue($endpoint->headers, 8) !!},
 @endif
 @if(!empty($endpoint->cleanQueryParameters))

+ 27 - 8
src/Writing/PostmanCollectionWriter.php

@@ -140,14 +140,7 @@ class PostmanCollectionWriter
 
         switch ($inputMode) {
             case 'formdata':
-                foreach ($endpoint->cleanBodyParameters as $key => $value) {
-                    $params = [
-                        'key' => $key,
-                        'value' => $value,
-                        'type' => 'text',
-                    ];
-                    $body[$inputMode][] = $params;
-                }
+                $body[$inputMode] = $this->getFormDataParams($endpoint->cleanBodyParameters);
                 foreach ($endpoint->fileParameters as $key => $value) {
                     while (is_array($value)) { // For arrays of files, just send the first one
                         $key .= '[]';
@@ -168,6 +161,32 @@ class PostmanCollectionWriter
         return $body;
     }
 
+    /**
+     * Format form-data parameters correctly for arrays eg. data[item][index] = value
+     */
+    protected function getFormDataParams(array $array, ?string $key = null): array
+    {
+        $body = [];
+
+        foreach ($array as $index => $value) {
+            $index = $key ? ($key . '[' . $index . ']') : $index;
+
+            if (!is_array($value)) {
+                $body[] = [
+                    'key' => $index,
+                    'value' => $value,
+                    'type' => 'text',
+                ];
+
+                continue;
+            }
+
+            $body = array_merge($body, $this->getFormDataParams($value, $index));
+        }
+
+        return $body;
+    }
+
     protected function resolveHeadersForEndpoint(OutputEndpointData $endpointData)
     {
         [$where, $authParam] = $this->getAuthParamToExclude();

+ 6 - 4
src/Writing/Writer.php

@@ -156,17 +156,19 @@ class Writer
         if (!is_dir($this->laravelTypeOutputPath)) {
             mkdir($this->laravelTypeOutputPath, 0777, true);
         }
-        if (!is_dir("public/vendor/scribe")) {
-            mkdir("public/vendor/scribe", 0777, true);
+        $publicDirectory = app()->get('public_path');
+        if (!is_dir("$publicDirectory/vendor/scribe")) {
+            mkdir("$publicDirectory/vendor/scribe", 0777, true);
         }
 
+
         // Transform output HTML to a Blade view
         rename("{$this->staticTypeOutputPath}/index.html", "$this->laravelTypeOutputPath/index.blade.php");
 
         // Move assets from public/docs to public/vendor/scribe
         // We need to do this delete first, otherwise move won't work if folder exists
-        Utils::deleteDirectoryAndContents("public/vendor/scribe/");
-        rename("{$this->staticTypeOutputPath}/", "public/vendor/scribe/");
+        Utils::deleteDirectoryAndContents("$publicDirectory/vendor/scribe/");
+        rename("{$this->staticTypeOutputPath}/", "$publicDirectory/vendor/scribe/");
 
         $contents = file_get_contents("$this->laravelTypeOutputPath/index.blade.php");