Skip to content

Commit 4bf2ede

Browse files
committed
Rename reqyestHeaders stage to headers for consistency and change order
1 parent 9949594 commit 4bf2ede

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
## [4.0.0]
1717
### Added
18+
- Added `headers` stage (https://github.com/mpociot/laravel-apidoc-generator/pull/624)
1819
- Support for non-static docs, changed source files locations (https://github.com/mpociot/laravel-apidoc-generator/pull/608)
1920
- Support for Eloquent API resources (https://github.com/mpociot/laravel-apidoc-generator/pull/601)
2021
- `bindings` replaced by `@urlParam` annotation (https://github.com/mpociot/laravel-apidoc-generator/pull/599)

config/apidoc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@
172172
'queryParameters' => [
173173
\Mpociot\ApiDoc\Extracting\Strategies\QueryParameters\GetFromQueryParamTag::class,
174174
],
175+
'headers' => [
176+
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
177+
],
175178
'bodyParameters' => [
176179
\Mpociot\ApiDoc\Extracting\Strategies\BodyParameters\GetFromBodyParamTag::class,
177180
],

docs/plugins.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ You can use plugins to alter how the Generator fetches data about your routes. F
55
Route processing is performed in six stages:
66
- metadata (this covers route `title`, route `description`, route `groupName`, route `groupDescription`, and authentication status (`authenticated`))
77
- urlParameters
8-
- bodyParameters
98
- queryParameters
9+
- headers (headers to be added to example request and response calls)
10+
- bodyParameters
1011
- responses
11-
- requestHeaeers
1212

1313
For each stage, the Generator attempts the specified strategies to fetch data. The Generator will call of the strategies configured, progressively combining their results together before to produce the final output of that stage.
1414

@@ -64,6 +64,9 @@ The last thing to do is to register the strategy. Strategies are registered in a
6464
'queryParameters' => [
6565
\Mpociot\ApiDoc\Extracting\Strategies\QueryParameters\GetFromQueryParamTag::class,
6666
],
67+
'headers' => [
68+
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
69+
],
6770
'bodyParameters' => [
6871
\Mpociot\ApiDoc\Extracting\Strategies\BodyParameters\GetFromBodyParamTag::class,
6972
],
@@ -74,9 +77,6 @@ The last thing to do is to register the strategy. Strategies are registered in a
7477
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseApiResourceTags::class,
7578
\Mpociot\ApiDoc\Extracting\Strategies\Responses\ResponseCalls::class,
7679
],
77-
'requestHeaders' => [
78-
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
79-
],
8080
],
8181
...
8282
```
@@ -173,4 +173,4 @@ Each strategy class must implement the __invoke method with the parameters as de
173173

174174
Responses are _additive_. This means all the responses returned from each stage are added to the `responses` array. But note that the `ResponseCalls` strategy will only attempt to fetch a response if there are no responses with a status code of 2xx already.
175175

176-
- In the `requestHeaders` stage, you can return an array of headers. You may also negate existing headers by providing `false` as the header value.
176+
- In the `headers` stage, you can return an array of headers. You may also negate existing headers by providing `false` as the header value.

src/Extracting/Generator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function processRoute(Route $route, array $routeRules = [])
7272
$parsedRoute['queryParameters'] = $queryParameters;
7373
$parsedRoute['cleanQueryParameters'] = $this->cleanParams($queryParameters);
7474

75+
$headers = $this->fetchRequestHeaders($controller, $method, $route, $routeRules, $parsedRoute);
76+
$parsedRoute['headers'] = $headers;
77+
7578
$bodyParameters = $this->fetchBodyParameters($controller, $method, $route, $routeRules, $parsedRoute);
7679
$parsedRoute['bodyParameters'] = $bodyParameters;
7780
$parsedRoute['cleanBodyParameters'] = $this->cleanParams($bodyParameters);
@@ -80,9 +83,6 @@ public function processRoute(Route $route, array $routeRules = [])
8083
$parsedRoute['responses'] = $responses;
8184
$parsedRoute['showresponse'] = ! empty($responses);
8285

83-
$requestHeaders = $this->fetchRequestHeaders($controller, $method, $route, $routeRules, $parsedRoute);
84-
$parsedRoute['headers'] = $requestHeaders;
85-
8686
return $parsedRoute;
8787
}
8888

@@ -128,7 +128,7 @@ protected function fetchResponses(ReflectionClass $controller, ReflectionMethod
128128

129129
protected function fetchRequestHeaders(ReflectionClass $controller, ReflectionMethod $method, Route $route, array $rulesToApply, array $context = [])
130130
{
131-
$headers = $this->iterateThroughStrategies('requestHeaders', $context, [$route, $controller, $method, $rulesToApply]);
131+
$headers = $this->iterateThroughStrategies('headers', $context, [$route, $controller, $method, $rulesToApply]);
132132

133133
return array_filter($headers);
134134
}
@@ -145,6 +145,9 @@ protected function iterateThroughStrategies(string $stage, array $context, array
145145
'queryParameters' => [
146146
\Mpociot\ApiDoc\Extracting\Strategies\QueryParameters\GetFromQueryParamTag::class,
147147
],
148+
'headers' => [
149+
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
150+
],
148151
'bodyParameters' => [
149152
\Mpociot\ApiDoc\Extracting\Strategies\BodyParameters\GetFromBodyParamTag::class,
150153
],
@@ -155,9 +158,6 @@ protected function iterateThroughStrategies(string $stage, array $context, array
155158
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseApiResourceTags::class,
156159
\Mpociot\ApiDoc\Extracting\Strategies\Responses\ResponseCalls::class,
157160
],
158-
'requestHeaders' => [
159-
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
160-
],
161161
];
162162

163163
// Use the default strategies for the stage, unless they were explicitly set

src/Extracting/Strategies/Responses/ResponseCalls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __invoke(Route $route, \ReflectionClass $controller, \Reflection
4141
$bodyParameters = array_merge($context['cleanBodyParameters'], $rulesToApply['bodyParams'] ?? []);
4242
$queryParameters = array_merge($context['cleanQueryParameters'], $rulesToApply['queryParams'] ?? []);
4343
$urlParameters = $context['cleanUrlParameters'];
44-
$request = $this->prepareRequest($route, $rulesToApply, $urlParameters, $bodyParameters, $queryParameters, $routeRules['headers'] ?? []);
44+
$request = $this->prepareRequest($route, $rulesToApply, $urlParameters, $bodyParameters, $queryParameters, $context['headers'] ?? []);
4545

4646
try {
4747
$response = $this->makeApiCall($request);

tests/Unit/GeneratorTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ abstract class GeneratorTestCase extends TestCase
2929
'queryParameters' => [
3030
\Mpociot\ApiDoc\Extracting\Strategies\QueryParameters\GetFromQueryParamTag::class,
3131
],
32+
'headers' => [
33+
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
34+
],
3235
'bodyParameters' => [
3336
\Mpociot\ApiDoc\Extracting\Strategies\BodyParameters\GetFromBodyParamTag::class,
3437
],
@@ -39,9 +42,6 @@ abstract class GeneratorTestCase extends TestCase
3942
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseApiResourceTags::class,
4043
\Mpociot\ApiDoc\Extracting\Strategies\Responses\ResponseCalls::class,
4144
],
42-
'requestHeaders' => [
43-
\Mpociot\ApiDoc\Extracting\Strategies\RequestHeaders\GetFromRouteRules::class,
44-
],
4545
],
4646
'default_group' => 'general',
4747
];

0 commit comments

Comments
 (0)