Bläddra i källkod

Dont include response status code in description

shalvah 3 år sedan
förälder
incheckning
a81d8785ed

+ 8 - 1
src/Writing/OpenAPISpecWriter.php

@@ -279,7 +279,14 @@ class OpenAPISpecWriter
             return trim(str_replace("<<binary>>", "", $response->content));
         }
 
-        return strval($response->description);
+        $description = strval($response->description);
+        // Don't include the status code in description; see https://github.com/knuckleswtf/scribe/issues/271
+        if (preg_match("/\d{3},\s+(.+)/", $description, $matches)) {
+            $description = $matches[1];
+        } else if ($description === strval($response->status)) {
+            $description = '';
+        }
+        return $description;
     }
 
     protected function generateResponseContentSpec(?string $responseContent, OutputEndpointData $endpoint)

+ 17 - 1
src/Writing/PostmanCollectionWriter.php

@@ -322,8 +322,24 @@ class PostmanCollectionWriter
                 'header' => $headers,
                 'code' => $response->status,
                 'body' => $response->content,
-                'name' => $response->description,
+                'name' => $this->getResponseDescription($response),
             ];
         })->toArray();
     }
+
+    protected function getResponseDescription(Response $response): string
+    {
+        if (Str::startsWith($response->content, "<<binary>>")) {
+            return trim(str_replace("<<binary>>", "", $response->content));
+        }
+
+        $description = strval($response->description);
+        // Don't include the status code in description; see https://github.com/knuckleswtf/scribe/issues/271
+        if (preg_match("/\d{3},\s+(.+)/", $description, $matches)) {
+            $description = $matches[1];
+        } else if ($description === strval($response->status)) {
+            $description = '';
+        }
+        return $description;
+    }
 }

+ 1 - 1
tests/Fixtures/openapi.yaml

@@ -62,7 +62,7 @@ paths:
                         type: string
             responses:
                 200:
-                    description: '200'
+                    description: ""
                     content:
                         application/json:
                             schema: