Kaynağa Gözat

Merge pull request #196 from aaronflorey/postman-collections

Add responses to Postman Collection
Shalvah 4 yıl önce
ebeveyn
işleme
546dbbe1fe

+ 10 - 0
src/Writing/PostmanCollectionWriter.php

@@ -113,6 +113,16 @@ class PostmanCollectionWriter
         if (($endpoint['metadata']['authenticated'] ?? false) === false) {
             $endpointItem['request']['auth'] = ['type' => 'noauth'];
         }
+        
+        foreach ($endpoint['responses'] as $index => $response) {
+			$endpointItem['response'][] = [
+				'name'            => $endpointItem['name'] . ' Response #' . ($index + 1),
+				'originalRequest' => $endpointItem['request'],
+				'header'          => null,
+				'cookie'          => [],
+				'body'            => json_encode(json_decode($response['content']), JSON_PRETTY_PRINT),
+			];
+		}
 
         return $endpointItem;
     }

+ 67 - 2
tests/Fixtures/collection.json

@@ -255,7 +255,72 @@
                             "type": "noauth"
                         }
                     },
-                    "response": []
+                    "response": [
+                        {
+                            "name": "api\/echoesUrlParameters\/{param}\/{param2}\/{param3?}\/{param4?} Response #1",
+                            "originalRequest": {
+                                "url": {
+                                    "protocol": "http",
+                                    "host": "{{baseUrl}}",
+                                    "path": "api\/echoesUrlParameters\/:param\/:param2\/:param3\/:param4",
+                                    "query": [
+                                        {
+                                            "key": "something",
+                                            "value": "consequatur",
+                                            "description": "",
+                                            "disabled": false
+                                        }
+                                    ],
+                                    "raw": "http:\/\/{{baseUrl}}\/api\/echoesUrlParameters\/:param\/:param2\/:param3\/:param4?something=consequatur",
+                                    "variable": [
+                                        {
+                                            "id": "param",
+                                            "key": "param",
+                                            "value": "4",
+                                            "description": ""
+                                        },
+                                        {
+                                            "id": "param2",
+                                            "key": "param2",
+                                            "value": "consequatur",
+                                            "description": ""
+                                        },
+                                        {
+                                            "id": "param3",
+                                            "key": "param3",
+                                            "value": "consequatur",
+                                            "description": ""
+                                        },
+                                        {
+                                            "id": "param4",
+                                            "key": "param4",
+                                            "value": "",
+                                            "description": ""
+                                        }
+                                    ]
+                                },
+                                "method": "GET",
+                                "header": [
+                                    {
+                                        "key": "Custom-Header",
+                                        "value": "NotSoCustom"
+                                    },
+                                    {
+                                        "key": "Accept",
+                                        "value": "application\/json"
+                                    }
+                                ],
+                                "body": null,
+                                "description": "",
+                                "auth": {
+                                    "type": "noauth"
+                                }
+                            },
+                            "header": null,
+                            "cookie": [],
+                            "body": "{\n    \"param\": \"4\",\n    \"param2\": \"consequatur\",\n    \"param3\": \"consequatur\",\n    \"param4\": null\n}"
+                        }
+                    ]
                 }
             ]
         }
@@ -263,4 +328,4 @@
     "auth": {
         "type": "bearer"
     }
-}
+}