Przeglądaj źródła

Merge pull request #43 from chriserikhaugli/#40-Include-raw-in-requests.url

Resolves #40 - Include raw in requests.url
Shalvah 4 lat temu
rodzic
commit
db1e559e22

+ 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": [