Skip to content

Commit

Permalink
Resolves knuckleswtf#40 - Include raw in requests.url
Browse files Browse the repository at this point in the history
Fixes import to Insomnia
  • Loading branch information
Chris Erik Haugli committed Jun 18, 2020
1 parent f315b80 commit f5ac11a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/Writing/PostmanCollectionWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ protected function makeUrlData($route)
})->values()->toArray(),
];

// Create raw url-parameter (Insomnia uses this on import)
$query = collect($base['query'] ?? [])->map(function ($array) {
return $array['key'].'='.$array['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()) {
Expand Down
27 changes: 18 additions & 9 deletions tests/Fixtures/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withDescription",
"query": []
"query": [],
"raw": "http://localhost/api/withDescription"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -59,7 +60,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withResponseTag",
"query": []
"query": [],
"raw": "http://localhost/api/withResponseTag"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -100,7 +102,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withBodyParameters",
"query": []
"query": [],
"raw": "http://localhost/api/withBodyParameters"
},
"method": "POST",
"header": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -213,7 +217,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withAuthTag",
"query": []
"query": [],
"raw": "http://localhost/api/withAuthTag"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -254,7 +259,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withEloquentApiResource",
"query": []
"query": [],
"raw": "http://localhost/api/withEloquentApiResource"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -295,7 +301,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withMultipleResponseTagsAndStatusCode",
"query": []
"query": [],
"raw": "http://localhost/api/withMultipleResponseTagsAndStatusCode"
},
"method": "POST",
"header": [
Expand Down Expand Up @@ -342,7 +349,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withEloquentApiResourceCollectionClass",
"query": []
"query": [],
"raw": "http://localhost/api/withEloquentApiResourceCollectionClass"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -404,7 +412,8 @@
"value": "consequatur",
"description": ""
}
]
],
"raw": "http://localhost/api/echoesUrlParameters/{param}-{param2}/:param3?something=consequatur"
},
"method": "GET",
"header": [
Expand Down
6 changes: 4 additions & 2 deletions tests/Fixtures/collection_custom_url.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "http",
"host": "yourapp.app",
"path": "api/test",
"query": []
"query": [],
"raw": "http://yourapp.app/api/test"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -51,7 +52,8 @@
"protocol": "http",
"host": "yourapp.app",
"path": "api/responseTag",
"query": []
"query": [],
"raw": "http://yourapp.app/api/responseTag"
},
"method": "POST",
"header": [
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/collection_with_body_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withBodyParameters",
"query": []
"query": [],
"raw": "http://localhost/api/withBodyParameters"
},
"method": "GET",
"header": [
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/collection_with_custom_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "http",
"host": "localhost",
"path": "api/headers",
"query": []
"query": [],
"raw": "http://localhost/api/headers"
},
"method": "GET",
"header": [
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/collection_with_form_data_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "http",
"host": "localhost",
"path": "api\/withFormDataParams",
"query": []
"query": [],
"raw": "http://localhost/api/withFormDataParams"
},
"method": "GET",
"header": [
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/collection_with_query_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 4 additions & 2 deletions tests/Fixtures/collection_with_secure_url.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"protocol": "https",
"host": "yourapp.app",
"path": "api/test",
"query": []
"query": [],
"raw": "https://yourapp.app/api/test"
},
"method": "GET",
"header": [
Expand Down Expand Up @@ -51,7 +52,8 @@
"protocol": "https",
"host": "yourapp.app",
"path": "api/responseTag",
"query": []
"query": [],
"raw": "https://yourapp.app/api/responseTag"
},
"method": "POST",
"header": [
Expand Down

0 comments on commit f5ac11a

Please sign in to comment.