diff --git a/src/Support/Generator/Operation.php b/src/Support/Generator/Operation.php index f3e8ae24..65dc14ea 100644 --- a/src/Support/Generator/Operation.php +++ b/src/Support/Generator/Operation.php @@ -16,6 +16,8 @@ class Operation public string $summary = ''; + public bool $deprecated = false; + /** @var array */ public array $security = []; @@ -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); @@ -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; } diff --git a/tests/Generator/Operation/OperationTest.php b/tests/Generator/Operation/OperationTest.php new file mode 100644 index 00000000..0eb8f2c7 --- /dev/null +++ b/tests/Generator/Operation/OperationTest.php @@ -0,0 +1,21 @@ +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'); +});