Skip to content

Commit

Permalink
Update strategy stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Feb 19, 2025
1 parent a2ac416 commit c916109
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
24 changes: 12 additions & 12 deletions config/scribe.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Knuckles\Scribe\Extracting\Strategies;
use Knuckles\Scribe\Config;
use Knuckles\Scribe\Config\Defaults;
use Knuckles\Scribe\Config\AuthIn;
use function Knuckles\Scribe\Config\{removeStrategies, configureStrategy};

Expand Down Expand Up @@ -207,26 +207,26 @@
// Use removeStrategies() to remove an included strategy.
'strategies' => [
'metadata' => [
...Config\Defaults::METADATA_STRATEGIES,
],
'urlParameters' => [
...Config\Defaults::URL_PARAMETERS_STRATEGIES,
],
'queryParameters' => [
...Config\Defaults::QUERY_PARAMETERS_STRATEGIES,
...Defaults::METADATA_STRATEGIES,
],
'headers' => [
...Config\Defaults::HEADERS_STRATEGIES,
...Defaults::HEADERS_STRATEGIES,
Strategies\StaticData::withSettings(data: [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
]),
],
'urlParameters' => [
...Defaults::URL_PARAMETERS_STRATEGIES,
],
'queryParameters' => [
...Defaults::QUERY_PARAMETERS_STRATEGIES,
],
'bodyParameters' => [
...Config\Defaults::BODY_PARAMETERS_STRATEGIES,
...Defaults::BODY_PARAMETERS_STRATEGIES,
],
'responses' => configureStrategy(
Config\Defaults::RESPONSES_STRATEGIES,
Defaults::RESPONSES_STRATEGIES,
Strategies\Responses\ResponseCalls::withSettings(
only: ['GET *'],
// Recommended: disable debug mode in response calls to avoid error stack traces in responses
Expand All @@ -236,7 +236,7 @@
)
),
'responseFields' => [
...Config\Defaults::RESPONSE_FIELDS_STRATEGIES,
...Defaults::RESPONSE_FIELDS_STRATEGIES,
]
],

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/stubs/strategy.stub
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class DummyClass extends Strategy
* @link https://scribe.knuckles.wtf/laravel/advanced/plugins
* @param ExtractedEndpointData $endpointData The endpoint we are currently processing.
* Contains details about httpMethods, controller, method, route, url, etc, as well as already extracted data.
* @param array $routeRules Array of rules for the ruleset which this route belongs to.
* @param array $settings Settings to be applied to this strategy
*
* See the documentation linked above for more details about writing custom strategies.
*
* @return array|null
*/
public function __invoke(ExtractedEndpointData $endpointData, array $routeRules = []): ?array
public function __invoke(ExtractedEndpointData $endpointData, array $settings = []): ?array
{
return [];
}
Expand Down
10 changes: 5 additions & 5 deletions src/Config/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Defaults
Strategies\Metadata\GetFromMetadataAttributes::class,
];

public const HEADERS_STRATEGIES = [
Strategies\Headers\GetFromHeaderAttribute::class,
Strategies\Headers\GetFromHeaderTag::class,
];

public const URL_PARAMETERS_STRATEGIES = [
Strategies\UrlParameters\GetFromLaravelAPI::class,
Strategies\UrlParameters\GetFromUrlParamAttribute::class,
Expand All @@ -24,11 +29,6 @@ class Defaults
Strategies\QueryParameters\GetFromQueryParamTag::class,
];

public const HEADERS_STRATEGIES = [
Strategies\Headers\GetFromHeaderAttribute::class,
Strategies\Headers\GetFromHeaderTag::class,
];

public const BODY_PARAMETERS_STRATEGIES = [
Strategies\BodyParameters\GetFromFormRequest::class,
Strategies\BodyParameters\GetFromInlineValidator::class,
Expand Down
9 changes: 1 addition & 8 deletions src/Extracting/Strategies/Strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function getConfig(): DocumentationConfig

/**
* @param ExtractedEndpointData $endpointData
* @param array $settings Settings to be applied to this strategy while processing this route.
* In the past, this was "routeRules".
* @param array $settings Settings to be applied to this strategy.
*
* @return array|null
*/
Expand All @@ -47,12 +46,6 @@ public static function wrapWithSettings(
array $otherSettings = []
): array
{
if (!empty($only) && !empty($except)) {
throw new \InvalidArgumentException(
"You can not specify both \$only and \$except together in your ".static::class." settings"
);
}

return [
static::class,
['only' => $only, 'except' => $except, ...$otherSettings],
Expand Down

0 comments on commit c916109

Please sign in to comment.