Skip to content

Commit

Permalink
Merge pull request #292 from sc-bruno/feature/deprecation-ability
Browse files Browse the repository at this point in the history
Add deprecation ability
  • Loading branch information
romalytvynenko authored Jan 9, 2024
2 parents 8b6b233 + 0f6a798 commit a377018
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Support/Generator/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Operation

public string $summary = '';

public bool $deprecated = false;

/** @var array<Security|array> */
public array $security = [];

Expand Down Expand Up @@ -111,6 +113,13 @@ public function description(string $description)
return $this;
}

public function deprecated(bool $deprecated)
{
$this->deprecated = $deprecated;

return $this;
}

public function setTags(array $tags)
{
$this->tags = array_map(fn ($t) => (string) $t, $tags);
Expand Down Expand Up @@ -141,6 +150,10 @@ public function toArray()
$result['summary'] = $this->summary;
}

if ($this->deprecated) {
$result['deprecated'] = $this->deprecated;
}

if (count($this->tags)) {
$result['tags'] = $this->tags;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Generator/Operation/OperationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

it('deprecated key is properly set', function () {
$operation = new \Dedoc\Scramble\Support\Generator\Operation('get');
$operation->deprecated(true);

$array = $operation->toArray();

expect($operation->deprecated)->toBeTrue()
->and($array)->toHaveKey('deprecated')
->and($array['deprecated'])->toBeTrue();
});

it('default deprecated key is false', function () {
$operation = new \Dedoc\Scramble\Support\Generator\Operation('get');

$array = $operation->toArray();

expect($operation->deprecated)->toBeFalse()
->and($array)->not()->toHaveKey('deprecated');
});

0 comments on commit a377018

Please sign in to comment.