Skip to content

Commit e94dc4e

Browse files
committed
Use default strategies for each stage if not specified
1 parent 18938eb commit e94dc4e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

docs/plugins.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ Route processing is performed in four stages:
88
- queryParameters
99
- responses
1010

11-
For each stage, the Generator attempts one or more configured 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.
11+
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.
12+
13+
There are a number of strategies inccluded with the package, so you don't have to set up anything to get it working.
14+
15+
> Note: The included ResponseCalls strategy is designed to stop if a response has already been gotten from any other strategy.
1216
1317
## Strategies
1418
To create a strategy, create a class that extends `\Mpociot\ApiDoc\Strategies\Strategy`.

src/Tools/Generator.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,26 @@ protected function fetchResponses(ReflectionClass $controller, ReflectionMethod
120120

121121
protected function iterateThroughStrategies(string $stage, array $context, array $arguments)
122122
{
123-
$strategies = $this->config->get("strategies.$stage", []);
123+
$defaultStrategies = [
124+
'metadata' => [
125+
\Mpociot\ApiDoc\Strategies\Metadata\GetFromDocBlocks::class,
126+
],
127+
'bodyParameters' => [
128+
\Mpociot\ApiDoc\Strategies\BodyParameters\GetFromBodyParamTag::class,
129+
],
130+
'queryParameters' => [
131+
\Mpociot\ApiDoc\Strategies\QueryParameters\GetFromQueryParamTag::class,
132+
],
133+
'responses' => [
134+
\Mpociot\ApiDoc\Strategies\Responses\UseResponseTag::class,
135+
\Mpociot\ApiDoc\Strategies\Responses\UseResponseFileTag::class,
136+
\Mpociot\ApiDoc\Strategies\Responses\UseTransformerTags::class,
137+
\Mpociot\ApiDoc\Strategies\Responses\ResponseCalls::class,
138+
]
139+
];
140+
141+
// Use the default strategies for the stage, unless they were explicitly set
142+
$strategies = $this->config->get("strategies.$stage", $defaultStrategies[$stage]);
124143
$context[$stage] = $context[$stage] ?? [];
125144
foreach ($strategies as $strategyClass) {
126145
$strategy = new $strategyClass($stage, $this->config);

0 commit comments

Comments
 (0)