Skip to content

Commit

Permalink
Dont include response status code in description
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Aug 21, 2021
1 parent 8b3e06b commit a81d878
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Writing/OpenAPISpecWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,14 @@ protected function getResponseDescription(Response $response): string
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)
Expand Down
18 changes: 17 additions & 1 deletion src/Writing/PostmanCollectionWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,24 @@ private function getResponses(OutputEndpointData $endpoint): array
'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;
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ paths:
type: string
responses:
200:
description: '200'
description: ""
content:
application/json:
schema:
Expand Down

0 comments on commit a81d878

Please sign in to comment.