Skip to content

Commit

Permalink
Don't include status code in description (closes #561)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Nov 18, 2022
1 parent 67b77cb commit 8a90c2d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
7 changes: 7 additions & 0 deletions camel/Extraction/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public function __construct(array $parameters = [])

parent::__construct($parameters);
}

public function fullDescription()
{
$description = $this->status;
if ($this->description) $description .= ", {$this->description}";
return $description;
}
}
2 changes: 1 addition & 1 deletion resources/views/themes/default/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@if($endpoint->isGet() || $endpoint->hasResponses())
@foreach($endpoint->responses as $response)
<blockquote>
<p>Example response ({{$response->description ?: $response->status}}):</p>
<p>Example response ({{ $response->fullDescription() }}):</p>
</blockquote>
@if(count($response->headers))
<details class="annotation">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/themes/elements/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class="example-response-{{ $endpoint->endpointId() }}-toggle sl-text-base"
aria-label="Response sample"
onchange="switchExampleResponse('{{ $endpoint->endpointId() }}', event.target.value);">
@foreach($endpoint->responses as $index => $response)
<option value="{{ $index }}">{{ $response->description ?: $response->status }}</option>
<option value="{{ $index }}">{{ $response->fullDescription() }}</option>
@endforeach
</select></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Extracting/Strategies/Responses/UseApiResourceTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function getStatusCodeAndApiResourceClass(Tag $tag): array

$status = $fields['status'] ?: $status;
$apiResourceClass = $content;
$description = $fields['scenario'] ? "$status, {$fields['scenario']}" : "$status";
$description = $fields['scenario'] ?: "";

$isCollection = strtolower($tag->getName()) == 'apiresourcecollection';
return [(int)$status, $description, $apiResourceClass, $isCollection];
Expand Down
2 changes: 1 addition & 1 deletion src/Extracting/Strategies/Responses/UseResponseFileTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getFileResponses(array $tags): ?array
['fields' => $fields, 'content' => $filePath] = a::parseIntoContentAndFields($mainContent, ['status', 'scenario']);

$status = $fields['status'] ?: ($status ?: 200);
$description = $fields['scenario'] ? "$status, {$fields['scenario']}" : "$status";
$description = $fields['scenario'] ?: "";
$content = ResponseFileTools::getResponseContents($filePath, $json);

return [
Expand Down
2 changes: 1 addition & 1 deletion src/Extracting/Strategies/Responses/UseResponseTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getDocBlockResponses(array $tags): ?array
['fields' => $fields, 'content' => $content] = a::parseIntoContentAndFields($content, ['status', 'scenario']);

$status = $fields['status'] ?: $status;
$description = $fields['scenario'] ? "$status, {$fields['scenario']}" : "$status";
$description = $fields['scenario'] ?: "";

return ['content' => $content, 'status' => (int) $status, 'description' => $description];
}, $responseTags);
Expand Down
2 changes: 1 addition & 1 deletion tests/Strategies/Responses/UseApiResourceTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function can_parse_apiresource_tags_with_scenario_and_status_attributes()
$this->assertArraySubset([
[
'status' => 202,
'description' => '202, Success',
'description' => 'Success',
'content' => json_encode([
'data' => [
'id' => 4,
Expand Down
8 changes: 4 additions & 4 deletions tests/Strategies/Responses/UseResponseFileTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function responseFileTags()
[
[
'status' => 200,
'description' => '200',
'description' => '',
],
[
'status' => 401,
'description' => '401',
'description' => '',
],
],
],
Expand All @@ -66,11 +66,11 @@ public function responseFileTags()
[
[
'status' => 200,
'description' => '200, success',
'description' => 'success',
],
[
'status' => 401,
'description' => '401, auth problem',
'description' => 'auth problem',
],
],
],
Expand Down
8 changes: 4 additions & 4 deletions tests/Strategies/Responses/UseResponseTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public function responseTags()
[
[
'status' => 200,
'description' => '200',
'description' => '',
'content' => [
'id' => 4,
'name' => 'banana',
],
],
[
'status' => 401,
'description' => '401',
'description' => '',
'content' => [
'message' => 'Unauthorized',
],
Expand All @@ -71,15 +71,15 @@ public function responseTags()
[
[
'status' => 200,
'description' => '200, success',
'description' => 'success',
'content' => [
'id' => 4,
'name' => 'banana',
],
],
[
'status' => 401,
'description' => '401, auth problem',
'description' => 'auth problem',
'content' => [
'message' => 'Unauthorized',
],
Expand Down

0 comments on commit 8a90c2d

Please sign in to comment.