浏览代码

Refactor PostmanCollectionWriter API, upgrade to v2.1, fix bug with URL path params

shalvah 4 年之前
父节点
当前提交
cc7e4cbfae

+ 1 - 1
src/Tools/ConsoleOutputUtils.php

@@ -28,7 +28,7 @@ class ConsoleOutputUtils
         }
 
         $message = "You're using $feature. This is deprecated and will be removed in the next major version.";
-        if ($shouldUse) {
+        if ($should) {
             $message .= "\nYou should $should instead.";
         }
         if ($link) {

+ 3 - 1
src/Writing/OpenAPISpecWriter.php

@@ -25,7 +25,7 @@ class OpenAPISpecWriter
 
     public function __construct(DocumentationConfig $config = null)
     {
-        $this->config = $config ?: new DocumentationConfig(config('scribe'));
+        $this->config = $config ?: new DocumentationConfig(config('scribe', []));
         $this->EMPTY = new \stdClass();
     }
 
@@ -441,6 +441,8 @@ class OpenAPISpecWriter
             case 'float':
             case 'double':
                 return 'number';
+            case 'NULL':
+                return 'null';
             default:
                 return $type;
         }

+ 44 - 56
src/Writing/PostmanCollectionWriter.php

@@ -5,6 +5,7 @@ namespace Knuckles\Scribe\Writing;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Str;
+use Knuckles\Scribe\Tools\DocumentationConfig;
 use Ramsey\Uuid\Uuid;
 use ReflectionMethod;
 use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
@@ -12,19 +13,9 @@ use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
 class PostmanCollectionWriter
 {
     /**
-     * @var Collection
+     * Postman collection schema version
      */
-    private $routeGroups;
-
-    /**
-     * @var string
-     */
-    private $baseUrl;
-
-    /**
-     * @var string
-     */
-    private $protocol;
+    const VERSION = '2.1.0';
 
     /**
      * @var array|null
@@ -32,15 +23,13 @@ class PostmanCollectionWriter
     private $auth;
 
     /**
-     * CollectionWriter constructor.
-     *
-     * @param Collection $routeGroups
+     * @var DocumentationConfig
      */
-    public function __construct(Collection $routeGroups, $baseUrl)
+    protected $config;
+
+    public function __construct(DocumentationConfig $config = null)
     {
-        $this->routeGroups = $routeGroups;
-        $this->protocol = Str::startsWith($baseUrl, 'https') ? 'https' : 'http';
-        $this->baseUrl = $this->getBaseUrl($baseUrl);
+        $this->config = $config ?: new DocumentationConfig(config('scribe', []));
         $this->auth = config('scribe.postman.auth');
 
         if ($this->auth) {
@@ -48,7 +37,7 @@ class PostmanCollectionWriter
         }
     }
 
-    public function generatePostmanCollection()
+    public function generatePostmanCollection(Collection $groupedEndpoints)
     {
         $description = config('scribe.postman.description', '');
 
@@ -59,14 +48,14 @@ class PostmanCollectionWriter
         }
 
         $collection = [
-            'variables' => [],
+            'variable' => [],
             'info' => [
                 'name' => config('scribe.title') ?: config('app.name') . ' API',
                 '_postman_id' => Uuid::uuid4()->toString(),
                 'description' => $description,
-                'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
+                'schema' => "https://schema.getpostman.com/json/collection/v".self::VERSION."/collection.json",
             ],
-            'item' => $this->routeGroups->map(function (Collection $routes, $groupName) {
+            'item' => $groupedEndpoints->map(function (Collection $routes, $groupName) {
                 return [
                     'name' => $groupName,
                     'description' => $routes->first()['metadata']['groupDescription'],
@@ -82,67 +71,64 @@ class PostmanCollectionWriter
         return $collection;
     }
 
-    protected function generateEndpointItem($route): array
+    protected function generateEndpointItem($endpoint): array
     {
-        $method = $route['methods'][0];
-
         return [
-            'name' => $route['metadata']['title'] !== '' ? $route['metadata']['title'] : $route['uri'],
+            'name' => $endpoint['metadata']['title'] !== '' ? $endpoint['metadata']['title'] : $endpoint['uri'],
             'request' => [
-                'url' => $this->makeUrlData($route),
-                'method' => $method,
-                'header' => $this->resolveHeadersForRoute($route),
-                'body' => $this->getBodyData($route),
-                'description' => $route['metadata']['description'] ?? null,
+                'url' => $this->generateUrlObject($endpoint),
+                'method' => $endpoint['methods'][0],
+                'header' => $this->resolveHeadersForEndpoint($endpoint),
+                'body' => empty($endpoint['bodyParameters']) ? null : $this->getBodyData($endpoint),
+                'description' => $endpoint['metadata']['description'] ?? null,
                 'response' => [],
             ],
         ];
     }
 
-    protected function getBodyData(array $route): array
+    protected function getBodyData(array $endpoint): array
     {
-
         $body = [];
-        $contentType = $route['headers']['Content-Type'] ?? null;
+        $contentType = $endpoint['headers']['Content-Type'] ?? null;
         switch ($contentType) {
             case 'multipart/form-data':
-                $mode = 'formdata';
+                $inputMode = 'formdata';
                 break;
             case 'application/json':
             default:
-                $mode = 'raw';
+                $inputMode = 'raw';
         }
-        $body['mode'] = $mode;
+        $body['mode'] = $inputMode;
+        $body[$inputMode] = [];
 
-        switch ($mode) {
+        switch ($inputMode) {
             case 'formdata':
-                foreach ($route['cleanBodyParameters'] as $key => $value) {
+                foreach ($endpoint['cleanBodyParameters'] as $key => $value) {
                     $params = [
                         'key' => $key,
                         'value' => $value,
                         'type' => 'text'
                     ];
-                    $body[$mode][] = $params;
+                    $body[$inputMode][] = $params;
                 }
-                foreach ($route['fileParameters'] as $key => $value) {
+                foreach ($endpoint['fileParameters'] as $key => $value) {
                     $params = [
                         'key' => $key,
                         'src' => [],
-                        'type' => 'file'
+                        'type' => 'file',
                     ];
-                    $body[$mode][] = $params;
+                    $body[$inputMode][] = $params;
                 }
                 break;
             case 'raw':
             default:
-                $body[$mode] = json_encode($route['cleanBodyParameters'], JSON_PRETTY_PRINT);
-                $body['options'][$mode]['language'] = 'json';
+                $body[$inputMode] = json_encode($endpoint['cleanBodyParameters'], JSON_PRETTY_PRINT);
         }
         return $body;
     }
 
 
-    protected function resolveHeadersForRoute($route)
+    protected function resolveHeadersForEndpoint($route)
     {
         $headers = collect($route['headers']);
 
@@ -169,7 +155,7 @@ class PostmanCollectionWriter
             ->all();
     }
 
-    protected function makeUrlData($route)
+    protected function generateUrlObject($route)
     {
         // URL Parameters are collected by the `UrlParameters` strategies, but only make sense if they're in the route
         // definition. Filter out any URL parameters that don't appear in the URL.
@@ -177,14 +163,16 @@ class PostmanCollectionWriter
             return Str::contains($route['uri'], '{' . $key . '}');
         });
 
+        $baseUrl = $this->getBaseUrl($this->config->get('postman.base_url', $this->config->get('base_url')));
         $base = [
-            'protocol' => $this->protocol,
-            'host' => $this->baseUrl,
-            // Substitute laravel/symfony query params ({example}) to Postman style, prefixed with a colon
-            'path' => preg_replace_callback('/\/{(\w+)\??}(?=\/|$)/', function ($matches) {
-                return '/:' . $matches[1];
+            'protocol' => Str::startsWith($baseUrl, 'https') ? 'https' : 'http',
+            'host' => $baseUrl,
+            // Change laravel/symfony URL params ({example}) to Postman style, prefixed with a colon
+            'path' => preg_replace_callback('/\{(\w+)\??}/', function ($matches) {
+                return ':' . $matches[1];
             }, $route['uri']),
             'query' => collect($route['queryParameters'] ?? [])->map(function ($parameterData, $key) {
+                // TODO remove: unneeded with new syntax
                 $key = rtrim($key,".*");
                 return [
                     'key' => $key,
@@ -210,10 +198,10 @@ class PostmanCollectionWriter
             return $base;
         }
 
-        $base['variable'] = $urlParams->map(function ($parameter, $key) {
+        $base['variable'] = $urlParams->map(function ($parameter, $name) {
             return [
-                'id' => $key,
-                'key' => $key,
+                'id' => $name,
+                'key' => $name,
                 'value' => urlencode($parameter['value']),
                 'description' => $parameter['description'],
             ];

+ 4 - 10
src/Writing/Writer.php

@@ -24,11 +24,6 @@ class Writer
      */
     private $baseUrl;
 
-    /**
-     * @var string
-     */
-    private $postmanBaseUrl;
-
     /**
      * @var bool
      */
@@ -84,7 +79,6 @@ class Writer
         // If no config is injected, pull from global. Makes testing easier.
         $this->config = $config ?: new DocumentationConfig(config('scribe'));
         $this->baseUrl = $this->config->get('base_url') ?? config('app.url');
-        $this->postmanBaseUrl = $this->config->get('postman.base_url') ?? $this->baseUrl;
         $this->shouldOverwrite = $shouldOverwrite;
         $this->shouldGeneratePostmanCollection = $this->config->get('postman.enabled', false);
         $this->shouldGenerateOpenAPISpec = $this->config->get('openapi.enabled', false);
@@ -206,19 +200,19 @@ class Writer
     /**
      * Generate Postman collection JSON file.
      *
-     * @param Collection $routes
+     * @param Collection $groupedEndpoints
      *
      * @return string
      */
-    public function generatePostmanCollection(Collection $routes)
+    public function generatePostmanCollection(Collection $groupedEndpoints)
     {
         /** @var PostmanCollectionWriter $writer */
         $writer = app()->makeWith(
             PostmanCollectionWriter::class,
-            ['routeGroups' => $routes, 'baseUrl' => $this->postmanBaseUrl]
+            ['config' => $this->config]
         );
 
-        $collection = $writer->generatePostmanCollection();
+        $collection = $writer->generatePostmanCollection($groupedEndpoints);
         $overrides = $this->config->get('postman.overrides', []);
         if (count($overrides)) {
             foreach ($overrides as $key => $value) {

+ 6 - 35
tests/Fixtures/collection-overridden.json

@@ -1,10 +1,10 @@
 {
-    "variables": [],
+    "variable": [],
     "info": {
         "name": "Custom API",
         "_postman_id": "",
         "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json",
+        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.1.0\/collection.json",
         "version": "3.9.9"
     },
     "item": [
@@ -33,15 +33,7 @@
                                 "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "This will be the long description.\nIt can also be multiple lines long.",
                         "response": []
                     }
@@ -67,15 +59,7 @@
                                 "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -103,12 +87,7 @@
                         ],
                         "body": {
                             "mode": "raw",
-                            "raw": "{\n    \"user_id\": 9,\n    \"room_id\": \"consequatur\",\n    \"forever\": false,\n    \"another_one\": 11613.31890586,\n    \"yet_another_param\": {\n        \"name\": \"consequatur\"\n    },\n    \"even_more_param\": [\n        11613.31890586\n    ],\n    \"book\": {\n        \"name\": \"consequatur\",\n        \"author_id\": 17,\n        \"pages_count\": 17\n    },\n    \"ids\": [\n        17\n    ],\n    \"users\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
+                            "raw": "{\n    \"user_id\": 9,\n    \"room_id\": \"consequatur\",\n    \"forever\": false,\n    \"another_one\": 11613.31890586,\n    \"yet_another_param\": {\n        \"name\": \"consequatur\"\n    },\n    \"even_more_param\": [\n        11613.31890586\n    ],\n    \"book\": {\n        \"name\": \"consequatur\",\n        \"author_id\": 17,\n        \"pages_count\": 17\n    },\n    \"ids\": [\n        17\n    ],\n    \"users\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}"
                         },
                         "description": "",
                         "response": []
@@ -166,15 +145,7 @@
                                 "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }

+ 64 - 157
tests/Fixtures/collection.json

@@ -1,10 +1,10 @@
 {
-    "variables": [],
+    "variable": [],
     "info": {
-        "name": "Laravel API",
+        "name": "GREAT API!",
         "_postman_id": "",
         "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
+        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.1.0\/collection.json"
     },
     "item": [
         {
@@ -19,14 +19,10 @@
                             "host": "localhost",
                             "path": "api\/withDescription",
                             "query": [],
-                            "raw": "http://localhost/api/withDescription"
+                            "raw": "http:\/\/localhost\/api\/withDescription"
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -34,22 +30,54 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
+                            }
+                        ],
+                        "body": null,
+                        "description": "This will be the long description.\nIt can also be multiple lines long.",
+                        "response": []
+                    }
+                },
+                {
+                    "name": "Endpoint with body form data parameters.",
+                    "request": {
+                        "url": {
+                            "protocol": "http",
+                            "host": "localhost",
+                            "path": "api\/withFormDataParams",
+                            "query": [],
+                            "raw": "http:\/\/localhost\/api\/withFormDataParams"
+                        },
+                        "method": "POST",
+                        "header": [
+                            {
+                                "key": "Custom-Header",
+                                "value": "NotSoCustom"
                             },
                             {
                                 "key": "Content-Type",
+                                "value": "multipart\/form-data"
+                            },
+                            {
+                                "key": "Accept",
                                 "value": "application\/json"
                             }
                         ],
                         "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
+                            "mode": "formdata",
+                            "formdata": [
+                                {
+                                    "key": "name",
+                                    "value": "cat.jpg",
+                                    "type": "text"
+                                },
+                                {
+                                    "key": "image",
+                                    "src": [],
+                                    "type": "file"
                                 }
-                            }
+                            ]
                         },
-                        "description": "This will be the long description.\nIt can also be multiple lines long.",
+                        "description": "",
                         "response": []
                     }
                 },
@@ -61,14 +89,10 @@
                             "host": "localhost",
                             "path": "api\/withResponseTag",
                             "query": [],
-                            "raw": "http://localhost/api/withResponseTag"
+                            "raw": "http:\/\/localhost\/api\/withResponseTag"
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -76,21 +100,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -103,35 +115,26 @@
                             "host": "localhost",
                             "path": "api\/withBodyParameters",
                             "query": [],
-                            "raw": "http://localhost/api/withBodyParameters"
+                            "raw": "http:\/\/localhost\/api\/withBodyParameters"
                         },
                         "method": "POST",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
                             },
                             {
-                                "key": "Accept",
+                                "key": "Content-Type",
                                 "value": "application\/json"
                             },
                             {
-                                "key": "Content-Type",
+                                "key": "Accept",
                                 "value": "application\/json"
                             }
                         ],
                         "body": {
                             "mode": "raw",
-                            "raw": "{\n    \"user_id\": 9,\n    \"room_id\": \"consequatur\",\n    \"forever\": false,\n    \"another_one\": 11613.31890586,\n    \"yet_another_param\": {\n        \"name\": \"consequatur\"\n    },\n    \"even_more_param\": [\n        11613.31890586\n    ],\n    \"book\": {\n        \"name\": \"consequatur\",\n        \"author_id\": 17,\n        \"pages_count\": 17\n    },\n    \"ids\": [\n        17\n    ],\n    \"users\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
+                            "raw": "{\n    \"user_id\": 9,\n    \"room_id\": \"consequatur\",\n    \"forever\": false,\n    \"another_one\": 11613.31890586,\n    \"yet_another_param\": {\n        \"name\": \"consequatur\"\n    },\n    \"even_more_param\": [\n        11613.31890586\n    ],\n    \"book\": {\n        \"name\": \"consequatur\",\n        \"author_id\": 17,\n        \"pages_count\": 17\n    },\n    \"ids\": [\n        17\n    ],\n    \"users\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}"
                         },
                         "description": "",
                         "response": []
@@ -176,14 +179,10 @@
                                     "disabled": false
                                 }
                             ],
-                            "raw": "http://localhost/api/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D"
+                            "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": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -191,21 +190,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -218,14 +205,10 @@
                             "host": "localhost",
                             "path": "api\/withAuthTag",
                             "query": [],
-                            "raw": "http://localhost/api/withAuthTag"
+                            "raw": "http:\/\/localhost\/api\/withAuthTag"
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -233,21 +216,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -260,14 +231,10 @@
                             "host": "localhost",
                             "path": "api\/withEloquentApiResource",
                             "query": [],
-                            "raw": "http://localhost/api/withEloquentApiResource"
+                            "raw": "http:\/\/localhost\/api\/withEloquentApiResource"
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -275,21 +242,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -302,14 +257,10 @@
                             "host": "localhost",
                             "path": "api\/withMultipleResponseTagsAndStatusCode",
                             "query": [],
-                            "raw": "http://localhost/api/withMultipleResponseTagsAndStatusCode"
+                            "raw": "http:\/\/localhost\/api\/withMultipleResponseTagsAndStatusCode"
                         },
                         "method": "POST",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -317,21 +268,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -350,14 +289,10 @@
                             "host": "localhost",
                             "path": "api\/withEloquentApiResourceCollectionClass",
                             "query": [],
-                            "raw": "http://localhost/api/withEloquentApiResourceCollectionClass"
+                            "raw": "http:\/\/localhost\/api\/withEloquentApiResourceCollectionClass"
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -365,21 +300,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -390,7 +313,7 @@
                         "url": {
                             "protocol": "http",
                             "host": "localhost",
-                            "path": "api\/echoesUrlParameters\/{param}-{param2}\/:param3",
+                            "path": "api\/echoesUrlParameters\/:param-:param2\/:param3",
                             "query": [
                                 {
                                     "key": "something",
@@ -399,6 +322,7 @@
                                     "disabled": false
                                 }
                             ],
+                            "raw": "http:\/\/localhost\/api\/echoesUrlParameters\/:param-:param2\/:param3?something=consequatur",
                             "variable": [
                                 {
                                     "id": "param",
@@ -412,15 +336,10 @@
                                     "value": "consequatur",
                                     "description": ""
                                 }
-                            ],
-                            "raw": "http://localhost/api/echoesUrlParameters/{param}-{param2}/:param3?something=consequatur"
+                            ]
                         },
                         "method": "GET",
                         "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
                             {
                                 "key": "Custom-Header",
                                 "value": "NotSoCustom"
@@ -428,21 +347,9 @@
                             {
                                 "key": "Accept",
                                 "value": "application\/json"
-                            },
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
                             }
                         ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
+                        "body": null,
                         "description": "",
                         "response": []
                     }
@@ -450,4 +357,4 @@
             ]
         }
     ]
-}
+}

+ 0 - 85
tests/Fixtures/collection_custom_url.json

@@ -1,85 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "Example title.",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "yourapp.app",
-                            "path": "api/test",
-                            "query": [],
-                            "raw": "http://yourapp.app/api/test"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "This will be the long description.\nIt can also be multiple lines long.",
-                        "response": []
-                    }
-                },
-                {
-                    "name": "api\/responseTag",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "yourapp.app",
-                            "path": "api/responseTag",
-                            "query": [],
-                            "raw": "http://yourapp.app/api/responseTag"
-                        },
-                        "method": "POST",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 0 - 51
tests/Fixtures/collection_with_body_parameters.json

@@ -1,51 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "Endpoint with body parameters.",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api\/withBodyParameters",
-                            "query": [],
-                            "raw": "http://localhost/api/withBodyParameters"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "{\n    \"user_id\": 9,\n    \"room_id\": \"consequatur\",\n    \"forever\": false,\n    \"another_one\": 11613.31890586,\n    \"yet_another_param\": {\n        \"name\": \"consequatur\"\n    },\n    \"even_more_param\": [\n        11613.31890586\n    ],\n    \"book\": {\n        \"name\": \"consequatur\",\n        \"author_id\": 17,\n        \"pages_count\": 17\n    },\n    \"ids\": [\n        17\n    ],\n    \"users\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 0 - 55
tests/Fixtures/collection_with_custom_headers.json

@@ -1,55 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "api\/headers",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api/headers",
-                            "query": [],
-                            "raw": "http://localhost/api/headers"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Authorization",
-                                "value": "customAuthToken"
-                            },
-                            {
-                                "key": "Custom-Header",
-                                "value": "NotSoCustom"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 0 - 57
tests/Fixtures/collection_with_form_data_parameters.json

@@ -1,57 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "Endpoint with body form data parameters.",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api\/withFormDataParams",
-                            "query": [],
-                            "raw": "http://localhost/api/withFormDataParams"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "multipart\/form-data"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "formdata",
-                            "formdata": [
-                                {
-                                    "key": "name",
-                                    "value": "cat.jpg",
-                                    "type": "text"
-                                },
-                                {
-                                    "key": "image",
-                                    "src": [],
-                                    "type": "file"
-                                }
-                            ]
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 0 - 82
tests/Fixtures/collection_with_query_parameters.json

@@ -1,82 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "api\/withQueryParameters",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api\/withQueryParameters",
-                            "query": [
-                                {
-                                    "key": "location_id",
-                                    "value": "consequatur",
-                                    "description": "The id of the location.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "user_id",
-                                    "value": "me",
-                                    "description": "The id of the user.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "page",
-                                    "value": "4",
-                                    "description": "The page number.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "filters",
-                                    "value": "consequatur",
-                                    "description": "The filters.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "url_encoded",
-                                    "value": "%2B+%5B%5D%26%3D",
-                                    "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": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 0 - 85
tests/Fixtures/collection_with_secure_url.json

@@ -1,85 +0,0 @@
-{
-    "variables": [],
-    "info": {
-        "name": "Laravel API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "Example title.",
-                    "request": {
-                        "url": {
-                            "protocol": "https",
-                            "host": "yourapp.app",
-                            "path": "api/test",
-                            "query": [],
-                            "raw": "https://yourapp.app/api/test"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "This will be the long description.\nIt can also be multiple lines long.",
-                        "response": []
-                    }
-                },
-                {
-                    "name": "api\/responseTag",
-                    "request": {
-                        "url": {
-                            "protocol": "https",
-                            "host": "yourapp.app",
-                            "path": "api/responseTag",
-                            "query": [],
-                            "raw": "https://yourapp.app/api/responseTag"
-                        },
-                        "method": "POST",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": {
-                            "mode": "raw",
-                            "raw": "[]",
-                            "options": {
-                                "raw": {
-                                    "language": "json"
-                                }
-                            }
-                        },
-                        "description": "",
-                        "response": []
-                    }
-                }
-            ]
-        }
-    ]
-}

+ 6 - 356
tests/Fixtures/openapi.yaml

@@ -14,28 +14,14 @@ paths:
             parameters:
                 -
                     in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
+                    name: Content-Type
                     description: ''
                     example: application/json
                     schema:
                         type: string
                 -
                     in: header
-                    name: Content-Type
+                    name: Accept
                     description: ''
                     example: application/json
                     schema:
@@ -51,28 +37,14 @@ paths:
             parameters:
                 -
                     in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
+                    name: Content-Type
                     description: ''
                     example: application/json
                     schema:
                         type: string
                 -
                     in: header
-                    name: Content-Type
+                    name: Accept
                     description: ''
                     example: application/json
                     schema:
@@ -108,28 +80,14 @@ paths:
             parameters:
                 -
                     in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
+                    name: Content-Type
                     description: ''
                     example: application/json
                     schema:
                         type: string
                 -
                     in: header
-                    name: Content-Type
+                    name: Accept
                     description: ''
                     example: application/json
                     schema:
@@ -251,27 +209,6 @@ paths:
                     required: false
                     schema:
                         type: string
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
                 -
                     in: header
                     name: Content-Type
@@ -279,29 +216,6 @@ paths:
                     example: application/json
                     schema:
                         type: string
-            responses: {  }
-            tags:
-                - 'Group A'
-            security: []
-    /api/withAuthTag:
-        get:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
                 -
                     in: header
                     name: Accept
@@ -309,271 +223,7 @@ paths:
                     example: application/json
                     schema:
                         type: string
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
             responses: {  }
             tags:
                 - 'Group A'
-    /api/withEloquentApiResource:
-        get:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses:
-                200:
-                    description: ''
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    data: { id: 4, name: 'Tested Again', email: a@b.com }
-                                properties:
-                                    data: { type: object, example: { id: 4, name: 'Tested Again', email: a@b.com } }
-            tags:
-                - 'Group A'
             security: []
-    /api/withMultipleResponseTagsAndStatusCode:
-        post:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses:
-                200:
-                    description: '200'
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    id: 4
-                                    name: banana
-                                    color: red
-                                    weight: '1 kg'
-                                    delicious: true
-                                    multipleResponseTagsAndStatusCodes: true
-                                properties:
-                                    id: { type: integer, example: 4 }
-                                    name: { type: string, example: banana }
-                                    color: { type: string, example: red }
-                                    weight: { type: string, example: '1 kg' }
-                                    delicious: { type: boolean, example: true }
-                                    multipleResponseTagsAndStatusCodes: { type: boolean, example: true }
-                401:
-                    description: '401'
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    message: Unauthorized
-                                properties:
-                                    message: { type: string, example: Unauthorized }
-            tags:
-                - 'Group A'
-            security: []
-    /api/withEloquentApiResourceCollectionClass:
-        get:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses:
-                200:
-                    description: ''
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    data: [{ id: 4, name: 'Tested Again', email: a@b.com }, { id: 4, name: 'Tested Again', email: a@b.com }]
-                                    links: { self: link-value }
-                                properties:
-                                    data: { type: array, example: [{ id: 4, name: 'Tested Again', email: a@b.com }, { id: 4, name: 'Tested Again', email: a@b.com }], items: { type: object } }
-                                    links: { type: object, example: { self: link-value } }
-            tags:
-                - Other😎
-            security: []
-    '/api/echoesUrlParameters/{param}-{param2}/{param3}':
-        get:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: query
-                    name: something
-                    description: ''
-                    example: consequatur
-                    required: false
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Authorization
-                    description: ''
-                    example: customAuthToken
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Custom-Header
-                    description: ''
-                    example: NotSoCustom
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses:
-                200:
-                    description: ''
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    param: '4'
-                                    param2: consequatur
-                                    param3: null
-                                    param4: null
-                                properties:
-                                    param: { type: string, example: '4' }
-                                    param2: { type: string, example: consequatur }
-                                    param3: { type: 'NULL', example: null }
-                                    param4: { type: 'NULL', example: null }
-            tags:
-                - Other😎
-            security: []
-        parameters:
-            -
-                in: path
-                name: param
-                description: ''
-                example: '4'
-                required: true
-                schema:
-                    type: string
-            -
-                in: path
-                name: param2
-                description: 'Optional parameter.'
-                required: true
-                schema:
-                    type: string
-                examples:
-                    omitted:
-                        summary: 'When the value is omitted'
-                        value: ''
-                    present:
-                        summary: 'When the value is present'
-                        value: consequatur
-            -
-                in: path
-                name: param4
-                description: 'Optional parameter.'
-                required: true
-                schema:
-                    type: string
-                examples:
-                    omitted:
-                        summary: 'When the value is omitted'
-                        value: ''

+ 3 - 124
tests/GenerateDocumentationTest.php

@@ -230,6 +230,7 @@ class GenerateDocumentationTest extends TestCase
     public function generated_postman_collection_file_is_correct()
     {
         RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
+        RouteFacade::post('/api/withFormDataParams', TestController::class . '@withFormDataParams');
         RouteFacade::get('/api/withResponseTag', TestController::class . '@withResponseTag');
         RouteFacade::post('/api/withBodyParameters', TestController::class . '@withBodyParameters');
         RouteFacade::get('/api/withQueryParameters', TestController::class . '@withQueryParameters');
@@ -238,16 +239,13 @@ class GenerateDocumentationTest extends TestCase
         RouteFacade::get('/api/withEloquentApiResourceCollectionClass', [TestController::class, 'withEloquentApiResourceCollectionClass']);
         RouteFacade::post('/api/withMultipleResponseTagsAndStatusCode', [TestController::class, 'withMultipleResponseTagsAndStatusCode']);
         RouteFacade::get('/api/echoesUrlParameters/{param}-{param2}/{param3?}', [TestController::class, 'echoesUrlParameters']);
-
         // We want to have the same values for params each time
         config(['scribe.faker_seed' => 1234]);
+        config(['scribe.title' => 'GREAT API!']);
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
         config([
             'scribe.routes.0.apply.headers' => [
-                'Authorization' => 'customAuthToken',
                 'Custom-Header' => 'NotSoCustom',
-                'Accept' => 'application/json',
-                'Content-Type' => 'application/json',
             ],
         ]);
 
@@ -288,6 +286,7 @@ class GenerateDocumentationTest extends TestCase
     public function generated_openapi_spec_file_is_correct()
     {
         RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
+        RouteFacade::post('/api/withFormDataParams', TestController::class . '@withFormDataParams');
         RouteFacade::get('/api/withResponseTag', TestController::class . '@withResponseTag');
         RouteFacade::post('/api/withBodyParameters', TestController::class . '@withBodyParameters');
         RouteFacade::get('/api/withQueryParameters', TestController::class . '@withQueryParameters');
@@ -303,10 +302,7 @@ class GenerateDocumentationTest extends TestCase
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
         config([
             'scribe.routes.0.apply.headers' => [
-                'Authorization' => 'customAuthToken',
                 'Custom-Header' => 'NotSoCustom',
-                'Accept' => 'application/json',
-                'Content-Type' => 'application/json',
             ],
         ]);
 
@@ -340,123 +336,6 @@ class GenerateDocumentationTest extends TestCase
         $this->assertEquals($fixtureCollection, $generatedCollection);
     }
 
-    /** @test */
-    public function generated_postman_collection_domain_is_correct()
-    {
-        $domain = 'http://somedomain.test';
-        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
-
-        config(['scribe.base_url' => $domain]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'));
-        $endpointUrl = $generatedCollection->item[0]->item[0]->request->url->host;
-        $this->assertTrue(Str::startsWith($endpointUrl, 'somedomain.test'));
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_have_custom_url()
-    {
-        Config::set('scribe.postman.base_url', 'http://yourapp.app');
-        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
-        RouteFacade::post('/api/responseTag', TestController::class . '@withResponseTag');
-
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_custom_url.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_have_secure_url()
-    {
-        Config::set('scribe.base_url', 'https://yourapp.app');
-        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
-        RouteFacade::post('/api/responseTag', TestController::class . '@withResponseTag');
-
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_with_secure_url.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_append_custom_http_headers()
-    {
-        RouteFacade::get('/api/headers', TestController::class . '@checkCustomHeaders');
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        config([
-            'scribe.routes.0.apply.headers' => [
-                'Authorization' => 'customAuthToken',
-                'Custom-Header' => 'NotSoCustom',
-            ],
-        ]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_with_custom_headers.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_have_query_parameters()
-    {
-        RouteFacade::get('/api/withQueryParameters', TestController::class . '@withQueryParameters');
-        // We want to have the same values for params each time
-        config(['scribe.faker_seed' => 1234]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_with_query_parameters.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_add_body_parameters()
-    {
-        RouteFacade::get('/api/withBodyParameters', TestController::class . '@withBodyParameters');
-        // We want to have the same values for params each time
-        config(['scribe.faker_seed' => 1234]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_with_body_parameters.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
-    /** @test */
-    public function generated_postman_collection_can_add_form_data_parameters()
-    {
-        RouteFacade::get('/api/withFormDataParams', TestController::class . '@withFormDataParams');
-        // We want to have the same values for params each time
-        config(['scribe.faker_seed' => 1234]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        // The Postman ID varies from call to call; erase it to make the test data reproducible.
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection_with_form_data_parameters.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
     /** @test */
     public function can_append_custom_http_headers()
     {

+ 43 - 66
tests/Unit/PostmanCollectionWriterTest.php

@@ -16,8 +16,8 @@ class PostmanCollectionWriterTest extends TestCase
             'description' => 'A fake description',
         ]);
 
-        $writer = new PostmanCollectionWriter(new Collection(), '');
-        $collection = $writer->generatePostmanCollection();
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection(new Collection());
 
         $this->assertSame('Test API', $collection['info']['name']);
         $this->assertSame('A fake description', $collection['info']['description']);
@@ -26,37 +26,13 @@ class PostmanCollectionWriterTest extends TestCase
     public function testFallbackCollectionNameIsUsed()
     {
         \Config::set('app.name', 'Fake App');
-
-        $writer = new PostmanCollectionWriter(new Collection(), '');
-        $collection = $writer->generatePostmanCollection();
+        
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection(new Collection());
 
         $this->assertSame('Fake App API', $collection['info']['name']);
     }
 
-    public function testAuthIsNotIncludedWhenNull()
-    {
-        $writer = new PostmanCollectionWriter(new Collection(), '');
-        $collection = $writer->generatePostmanCollection();
-
-        $this->assertArrayNotHasKey('auth', $collection);
-    }
-
-    public function testAuthIsIncludedVerbatim()
-    {
-        $auth = [
-            'type' => 'test',
-            'test' => ['a' => 1],
-        ];
-        \Config::set('scribe.postman', [
-            'auth' => $auth,
-        ]);
-
-        $writer = new PostmanCollectionWriter(new Collection(), '');
-        $collection = $writer->generatePostmanCollection();
-
-        $this->assertSame($auth, $collection['auth']);
-    }
-
     public function testEndpointIsParsed()
     {
         $route = $this->createMockRouteData('some/path');
@@ -64,10 +40,11 @@ class PostmanCollectionWriterTest extends TestCase
         // Ensure method is set correctly for assertion later
         $route['methods'] = ['GET'];
 
-        $collection = $this->createMockRouteGroup([$route], 'Group');
+        $endpoints = $this->createMockRouteGroup([$route], 'Group');
 
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $this->assertSame('Group', data_get($collection, 'item.0.name'), 'Group name exists');
 
@@ -84,24 +61,16 @@ class PostmanCollectionWriterTest extends TestCase
         ], data_get($item, 'request.header'), 'JSON Accept header is added');
     }
 
-    public function testHttpsProtocolIsDetected()
-    {
-        $collection = $this->createMockRouteGroup([$this->createMockRouteData('fake')]);
-        $writer = new PostmanCollectionWriter($collection, 'https://fake.localhost');
-        $collection = $writer->generatePostmanCollection();
-
-        $this->assertSame('https', data_get($collection, 'item.0.item.0.request.url.protocol'));
-    }
-
     public function testHeadersArePulledFromRoute()
     {
         $route = $this->createMockRouteData('some/path');
 
         $route['headers'] = ['X-Fake' => 'Test'];
 
-        $collection = $this->createMockRouteGroup([$route], 'Group');
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$route], 'Group');
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $this->assertContains([
             'key' => 'X-Fake',
@@ -118,10 +87,11 @@ class PostmanCollectionWriterTest extends TestCase
             'required' => true,
             'value' => 'foobar',
         ]];
-        $collection = $this->createMockRouteGroup([$fakeRoute]);
+        $endpoints = $this->createMockRouteGroup([$fakeRoute]);
 
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $item = data_get($collection, 'item.0.item.0');
         $this->assertSame('fake/{param}', $item['name'], 'Name defaults to URL path');
@@ -156,9 +126,10 @@ class PostmanCollectionWriterTest extends TestCase
         ];
         $fakeRoute['cleanQueryParameters'] = Generator::cleanParams($fakeRoute['queryParameters']);
 
-        $collection = $this->createMockRouteGroup([$fakeRoute]);
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$fakeRoute]);
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $variableData = data_get($collection, 'item.0.item.0.request.url.query');
 
@@ -187,16 +158,18 @@ class PostmanCollectionWriterTest extends TestCase
             'value' => 5,
         ]];
 
-        $collection = $this->createMockRouteGroup([$fakeRoute]);
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$fakeRoute]);
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $variableData = data_get($collection, 'item.0.item.0.request.url.query');
 
         $this->assertCount(0, $variableData);
     }
 
-    public function testQueryParametersAreDisabledWithNoValueWhenNotRequired()
+    /** @test */
+    public function query_parameters_are_disabled_with_no_value_when_notRequired()
     {
         $fakeRoute = $this->createMockRouteData('fake/path');
         $fakeRoute['queryParameters'] = [
@@ -213,9 +186,10 @@ class PostmanCollectionWriterTest extends TestCase
         ];
         $fakeRoute['cleanQueryParameters'] = Generator::cleanParams($fakeRoute['queryParameters']);
 
-        $collection = $this->createMockRouteGroup([$fakeRoute]);
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$fakeRoute]);
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $variableData = data_get($collection, 'item.0.item.0.request.url.query');
 
@@ -239,15 +213,17 @@ class PostmanCollectionWriterTest extends TestCase
      */
     public function testAuthAutoExcludesHeaderDefinitions(array $authConfig, array $expectedRemovedHeaders)
     {
-        \Config::set('scribe.postman', [
-            'auth' => $authConfig,
-        ]);
+        // todo change this test to Scribe auth
+        \Config::set('scribe.postman', ['auth' => $authConfig]);
 
         $route = $this->createMockRouteData('some/path');
         $route['headers'] = $expectedRemovedHeaders;
-        $collection = $this->createMockRouteGroup([$route], 'Group');
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$route], 'Group');
+
+        config('scribe.postman', ['auth' => $authConfig]);
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         foreach ($expectedRemovedHeaders as $key => $value) {
             $this->assertNotContains(compact('key', 'value'), data_get($collection, 'item.0.item.0.request.header'));
@@ -279,9 +255,10 @@ class PostmanCollectionWriterTest extends TestCase
 
         $route = $this->createMockRouteData('some/path');
         $route['headers'] = ['X-Authorization' => 'Test'];
-        $collection = $this->createMockRouteGroup([$route], 'Group');
-        $writer = new PostmanCollectionWriter($collection, 'fake.localhost');
-        $collection = $writer->generatePostmanCollection();
+        $endpoints = $this->createMockRouteGroup([$route], 'Group');
+        config(['scribe.base_url' => 'fake.localhost']);
+        $writer = new PostmanCollectionWriter();
+        $collection = $writer->generatePostmanCollection($endpoints);
 
         $this->assertContains([
             'key' => 'X-Authorization',