ソースを参照

Merge remote-tracking branch 'origin/master'

shalvah 4 年 前
コミット
4ba456b4e9

+ 2 - 2
.github/ISSUE_TEMPLATE/bug_report.md

@@ -22,8 +22,8 @@ instead of...
 
 **My environment:**
  - PHP version: 
- - Laravel version:
- - Scribe Version
+ - Framework (Laravel/Lumen) and version: 
+ - Scribe Version: 
 
 **My Scribe config (minus the comments):**
 

+ 2 - 1
.github/ISSUE_TEMPLATE/question.md

@@ -1,10 +1,11 @@
 ---
 name: Question
 about: Got a question about how to achieve something?
-title: How do I...?
+title: ''
 labels: question
 assignees: ''
 
 ---
 
 - [x] I've read the [documentation](https://scribe.rtfd.io) and I can't find details on how to achieve this.
+

+ 8 - 0
CHANGELOG.md

@@ -12,6 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Removed
 
+## 1.2.0 (Sunday, 5 July, 2020)
+### Added
+- Include raw request URL in Postman collection (https://github.com/knuckleswtf/scribe/pull/43)
+
+## 1.1.1 (Friday, 3 July, 2020)
+### Fixed
+- Support HEAD-only endpoints (https://github.com/knuckleswtf/scribe/pull/54)
+
 ## 1.1.0 (Monday, 1 June, 2020)
 ### Modified
 - Added ability to set postman base_url independently (https://github.com/knuckleswtf/scribe/pull/31)

+ 9 - 1
src/Extracting/Generator.php

@@ -43,7 +43,15 @@ class Generator
      */
     public function getMethods(Route $route)
     {
-        return array_diff($route->methods(), ['HEAD']);
+        $methods = $route->methods();
+
+        // Laravel adds an automatic "HEAD" endpoint for each GET request, so we'll strip that out,
+        // but not if there's only one method (means it was intentional)
+        if (count($methods) === 1) {
+            return $methods;
+        }
+
+        return array_diff($methods, ['HEAD']);
     }
 
     /**

+ 6 - 1
src/Tools/ConsoleOutputUtils.php

@@ -61,7 +61,12 @@ class ConsoleOutputUtils
      */
     public static function getRouteRepresentation(Route $route): string
     {
-        $routeMethods = implode(',', array_diff($route->methods(), ['HEAD']));
+        $methods = $route->methods();
+        if (count($methods) > 1) {
+            $methods = array_diff($route->methods(), ['HEAD']);
+        }
+
+        $routeMethods = implode(',', $methods);
         $routePath = $route->uri();
         return "[$routeMethods] $routePath";
     }

+ 8 - 0
src/Writing/PostmanCollectionWriter.php

@@ -183,6 +183,14 @@ class PostmanCollectionWriter
             })->values()->toArray(),
         ];
 
+        // Create raw url-parameter (Insomnia uses this on import)
+        $query = collect($base['query'] ?? [])->map(function ($queryParamData) {
+            return $queryParamData['key'].'='.$queryParamData['value'];
+        })->implode('&');
+        $base['raw'] = sprintf('%s://%s/%s%s',
+            $base['protocol'], $base['host'], $base['path'], $query ? '?'.$query : null
+        );
+
         // If there aren't any url parameters described then return what we've got
         /** @var $urlParams Collection */
         if ($urlParams->isEmpty()) {

+ 18 - 9
tests/Fixtures/collection.json

@@ -18,7 +18,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withDescription",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withDescription"
                         },
                         "method": "GET",
                         "header": [
@@ -59,7 +60,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withResponseTag",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withResponseTag"
                         },
                         "method": "GET",
                         "header": [
@@ -100,7 +102,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withBodyParameters",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withBodyParameters"
                         },
                         "method": "POST",
                         "header": [
@@ -172,7 +175,8 @@
                                     "description": "Used for testing that URL parameters will be URL-encoded where needed.",
                                     "disabled": false
                                 }
-                            ]
+                            ],
+                            "raw": "http://localhost/api/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D"
                         },
                         "method": "GET",
                         "header": [
@@ -213,7 +217,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withAuthTag",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withAuthTag"
                         },
                         "method": "GET",
                         "header": [
@@ -254,7 +259,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withEloquentApiResource",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withEloquentApiResource"
                         },
                         "method": "GET",
                         "header": [
@@ -295,7 +301,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withMultipleResponseTagsAndStatusCode",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withMultipleResponseTagsAndStatusCode"
                         },
                         "method": "POST",
                         "header": [
@@ -342,7 +349,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withEloquentApiResourceCollectionClass",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withEloquentApiResourceCollectionClass"
                         },
                         "method": "GET",
                         "header": [
@@ -404,7 +412,8 @@
                                     "value": "consequatur",
                                     "description": ""
                                 }
-                            ]
+                            ],
+                            "raw": "http://localhost/api/echoesUrlParameters/{param}-{param2}/:param3?something=consequatur"
                         },
                         "method": "GET",
                         "header": [

+ 4 - 2
tests/Fixtures/collection_custom_url.json

@@ -18,7 +18,8 @@
                             "protocol": "http",
                             "host": "yourapp.app",
                             "path": "api/test",
-                            "query": []
+                            "query": [],
+                            "raw": "http://yourapp.app/api/test"
                         },
                         "method": "GET",
                         "header": [
@@ -51,7 +52,8 @@
                             "protocol": "http",
                             "host": "yourapp.app",
                             "path": "api/responseTag",
-                            "query": []
+                            "query": [],
+                            "raw": "http://yourapp.app/api/responseTag"
                         },
                         "method": "POST",
                         "header": [

+ 2 - 1
tests/Fixtures/collection_with_body_parameters.json

@@ -18,7 +18,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withBodyParameters",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withBodyParameters"
                         },
                         "method": "GET",
                         "header": [

+ 2 - 1
tests/Fixtures/collection_with_custom_headers.json

@@ -18,7 +18,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api/headers",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/headers"
                         },
                         "method": "GET",
                         "header": [

+ 2 - 1
tests/Fixtures/collection_with_form_data_parameters.json

@@ -18,7 +18,8 @@
                             "protocol": "http",
                             "host": "localhost",
                             "path": "api\/withFormDataParams",
-                            "query": []
+                            "query": [],
+                            "raw": "http://localhost/api/withFormDataParams"
                         },
                         "method": "GET",
                         "header": [

+ 2 - 1
tests/Fixtures/collection_with_query_parameters.json

@@ -49,7 +49,8 @@
                                     "description": "Used for testing that URL parameters will be URL-encoded where needed.",
                                     "disabled": false
                                 }
-                            ]
+                            ],
+                            "raw": "http://localhost/api/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D"
                         },
                         "method": "GET",
                         "header": [

+ 4 - 2
tests/Fixtures/collection_with_secure_url.json

@@ -18,7 +18,8 @@
                             "protocol": "https",
                             "host": "yourapp.app",
                             "path": "api/test",
-                            "query": []
+                            "query": [],
+                            "raw": "https://yourapp.app/api/test"
                         },
                         "method": "GET",
                         "header": [
@@ -51,7 +52,8 @@
                             "protocol": "https",
                             "host": "yourapp.app",
                             "path": "api/responseTag",
-                            "query": []
+                            "query": [],
+                            "raw": "https://yourapp.app/api/responseTag"
                         },
                         "method": "POST",
                         "header": [

+ 14 - 0
tests/GenerateDocumentationTest.php

@@ -70,6 +70,20 @@ class GenerateDocumentationTest extends TestCase
     }
 
     /** @test */
+    public function can_process_traditional_laravel_head_routes()
+    {
+        RouteFacade::addRoute('HEAD', '/api/test', TestController::class . '@withEndpointDescription');
+
+        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
+        $output = $this->artisan('scribe:generate');
+
+        $this->assertStringContainsString('Processed route: [HEAD] api/test', $output);
+    }
+
+    /**
+     * @test
+     * @see https://github.com/knuckleswtf/scribe/issues/53
+     */
     public function can_process_closure_routes()
     {
         RouteFacade::get('/api/closure', function () {