Skip to content

Commit

Permalink
Add support for custom endpoint metadata definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Dec 7, 2021
1 parent 27c377b commit f7d767b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions camel/Extraction/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Knuckles\Camel\Extraction;


use Knuckles\Camel\BaseDTO;

class Metadata extends BaseDTO
Expand All @@ -28,4 +27,6 @@ class Metadata extends BaseDTO
public ?string $description;

public bool $authenticated = false;
}

public array $custom = [];
}
15 changes: 15 additions & 0 deletions tests/Fixtures/TestCustomEndpointMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Knuckles\Scribe\Tests\Fixtures;

use Knuckles\Camel\Extraction\ExtractedEndpointData;
use Knuckles\Scribe\Extracting\Strategies\Strategy;

class TestCustomEndpointMetadata extends Strategy
{
public function __invoke(ExtractedEndpointData $endpointData, array $routeRules): ?array
{
$endpointData->metadata->custom['myProperty'] = 'some custom metadata';
return null;
}
}
9 changes: 9 additions & 0 deletions tests/Unit/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ExtractorTest extends TestCase
'strategies' => [
'metadata' => [
\Knuckles\Scribe\Extracting\Strategies\Metadata\GetFromDocBlocks::class,
\Knuckles\Scribe\Tests\Fixtures\TestCustomEndpointMetadata::class,
],
'urlParameters' => [
\Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromLaravelAPI::class,
Expand Down Expand Up @@ -264,6 +265,14 @@ public function can_use_closure_in_routes_uses()
$this->assertSame('Name of the location', $parsed->bodyParameters['name']->description);
}

/** @test */
public function endpoint_metadata_supports_custom_declarations()
{
$route = $this->createRoute('POST', '/api/test', 'dummy');
$parsed = $this->generator->processRoute($route);
$this->assertSame('some custom metadata', $parsed->metadata->custom['myProperty']);
}

public function createRoute(string $httpMethod, string $path, string $controllerMethod, $register = false, $class = TestController::class)
{
return new Route([$httpMethod], $path, ['uses' => $class . "@$controllerMethod"]);
Expand Down

0 comments on commit f7d767b

Please sign in to comment.