Skip to content

feat: Add afterExtracting() hook for post-processing endpoint data#1072

Merged
shalvah merged 2 commits into
knuckleswtf:v5from
s-shiryaev:after-extracting-hook
May 1, 2026
Merged

feat: Add afterExtracting() hook for post-processing endpoint data#1072
shalvah merged 2 commits into
knuckleswtf:v5from
s-shiryaev:after-extracting-hook

Conversation

@s-shiryaev
Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new lifecycle hook: Scribe::afterExtracting(). This hook allows users to make programmatic changes to extracted endpoint data after all strategies have finished their execution, but before the data is finalized. Closes #1067

Motivation

Previously, users who wanted to make small, context-aware changes to extracted data (like appending info to descriptions based on middleware or route names) had to either create a full custom strategy or use hooks intended for other purposes (like beforeResponseCall). This new hook provides a clean, "middle-ground" solution for such cases.

Changes

  • src/Tools/Globals.php: Added a static property $__afterExtracting to store the callback.
  • src/Scribe.php: Added a public static method afterExtracting(callable $callable) to allow easy registration of the hook.
  • src/Extracting/Extractor.php: Integrated the hook call at the end of processRoute(). It is called once for each route and receives the ExtractedEndpointData object.

Example Usage

In your AppServiceProvider or a dedicated Scribe bootstrap file:

use Knuckles\Scribe\Scribe;
use Knuckles\Camel\Extraction\ExtractedEndpointData;

Scribe::afterExtracting(function (ExtractedEndpointData $endpointData) {
    // Access the Laravel route and its middleware
    $middlewares = $endpointData->route->gatherMiddleware();
    
    if (in_array('auth:agent_api', $middlewares, true)) {
        $endpointData->metadata->description .= "🔒 **Requires Authentication:** `Agent`";
    } elseif (in_array('auth:api', $middlewares, true)) {
        $endpointData->metadata->description .= "🔒 **Requires Authentication:** `User`";
    }
});

@shalvah shalvah merged commit 6d2f549 into knuckleswtf:v5 May 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for afterExtracting() method

2 participants