Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion camel/Extraction/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class Metadata extends BaseDTO
public ?string $title;
public ?string $description;
public bool $authenticated = false;
public bool $deprecated = false;
public bool|string $deprecated = false;
}
5 changes: 0 additions & 5 deletions camel/Output/OutputEndpointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,6 @@ public function isAuthed(): bool
return $this->metadata->authenticated;
}

public function isDeprecated(): bool
{
return $this->metadata->deprecated;
}

public function hasJsonBody(): bool
{
if ($this->hasFiles() || empty($this->nestedBodyParameters))
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/badges/deprecated.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@if($deprecated)@component('scribe::components.badges.base', ['colour' => "darkgoldenrod", 'text' => 'deprecated'])
@if($deprecated !== false)
@php($text = $deprecated === true ? 'deprecated' : "deprecated:$deprecated")
@component('scribe::components.badges.base', ['colour' => 'darkgoldenrod', 'text' => $text])
@endcomponent
@endif
2 changes: 1 addition & 1 deletion resources/views/themes/default/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p>
@component('scribe::components.badges.auth', ['authenticated' => $endpoint->isAuthed()])
@endcomponent
@component('scribe::components.badges.deprecated', ['deprecated' => $endpoint->isDeprecated()])
@component('scribe::components.badges.deprecated', ['deprecated' => $endpoint->metadata->deprecated])
@endcomponent
</p>

Expand Down
8 changes: 7 additions & 1 deletion resources/views/themes/elements/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{!! rtrim($baseUrl, '/')
>requires authentication
</div>
@endif
@if($endpoint->metadata->deprecated)
@if($endpoint->metadata->deprecated === true)
<div class="sl-font-prose sl-font-semibold sl-px-1.5 sl-py-0.5 sl-text-on-primary sl-rounded-lg"
style="background-color: darkgoldenrod"
>deprecated
</div>
@endif
@if(is_string($endpoint->metadata->deprecated))
<div class="sl-font-prose sl-font-semibold sl-px-1.5 sl-py-0.5 sl-text-on-primary sl-rounded-lg"
style="background-color: darkgoldenrod"
>deprecated:{{$endpoint->metadata->deprecated}}
</div>
@endif
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Deprecated
{
public function __construct(
public ?bool $deprecated = true,
public bool|string|null $deprecated = true,
)
{
}
Expand Down
10 changes: 7 additions & 3 deletions src/Extracting/Strategies/Metadata/GetFromDocBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ protected function getAuthStatusFromDocBlock(DocBlock $methodDocBlock, ?DocBlock
: null;
}

protected function getDeprecatedStatusFromDocBlock(DocBlock $methodDocBlock, ?DocBlock $classDocBlock = null): bool
protected function getDeprecatedStatusFromDocBlock(DocBlock $methodDocBlock, ?DocBlock $classDocBlock = null): bool|string
{
foreach ($methodDocBlock->getTags() as $tag) {
if (strtolower($tag->getName()) === 'deprecated') {
return true;
return $tag->getContent() === '' ? true : $tag->getContent();
}
}

return $classDocBlock && $this->getDeprecatedStatusFromDocBlock($classDocBlock);
if ($classDocBlock instanceof DocBlock) {
return $this->getDeprecatedStatusFromDocBlock($classDocBlock);
}

return false;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Strategies/Metadata/GetFromDocBlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ public function can_fetch_metadata_from_method_and_class()
$this->assertSame('', $results['groupDescription']);
$this->assertSame('Endpoint title.', $results['title']);
$this->assertSame("", $results['description']);

$classDocblock = <<<DOCBLOCK
/**
* @authenticated
* @subgroup Scheiße
* @subgroupDescription Heilige Scheiße
* @deprecated 2025-01-01
*/
DOCBLOCK;
$results = $strategy->getMetadataFromDocBlock(new DocBlock($methodDocblock), new DocBlock($classDocblock));

$this->assertTrue($results['authenticated']);
$this->assertSame('2025-01-01', $results['deprecated']);
$this->assertSame(null, $results['groupName']);
$this->assertSame('Scheiße', $results['subgroup']);
$this->assertSame('Heilige Scheiße', $results['subgroupDescription']);
$this->assertSame('', $results['groupDescription']);
$this->assertSame('Endpoint title.', $results['title']);
$this->assertSame("", $results['description']);
}

/** @test */
Expand Down
17 changes: 17 additions & 0 deletions tests/Strategies/Metadata/GetFromMetadataAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public function can_fetch_from_authenticated_attribute_or_authenticated_paramete
$this->assertArraySubset([
"deprecated" => true,
], $results);

$endpoint = $this->endpoint(function (ExtractedEndpointData $e) {
$e->controller = new ReflectionClass(MetadataAttributesTestController6::class);
$e->method = $e->controller->getMethod('c1');
});
$results = $this->fetch($endpoint);
$this->assertArraySubset([
"deprecated" => "2023-01-01",
], $results);
}

protected function fetch($endpoint): array
Expand Down Expand Up @@ -240,3 +249,11 @@ public function c1()
{
}
}

#[Deprecated("2023-01-01")]
class MetadataAttributesTestController6
{
public function c1()
{
}
}