From d761d890a044e0608b2f2936e28a3c5e57f9c67d Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Tue, 1 Oct 2024 16:11:23 +0300 Subject: [PATCH] add scope field to ApiDoc --- Annotation/ApiDoc.php | 13 +++++++++ Extractor/ApiDocExtractor.php | 5 +++- Tests/Formatter/SimpleFormatterTest.php | 1 + Tests/Formatter/testFormat-result.php | 27 +++++++++++++++++++ Tests/Formatter/testFormat-result_1.php | 36 +++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index d45dfe0..86d5b64 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -175,6 +175,8 @@ class ApiDoc */ private $tags = []; + private ?string $scope = null; + public function __construct(array $data) { $this->resource = !empty($data['resource']) ? $data['resource'] : false; @@ -664,6 +666,16 @@ class ApiDoc return $this->method; } + public function setScope(string $scope): void + { + $this->scope = $scope; + } + + public function getScope(): ?string + { + return $this->scope; + } + /** * @return array */ @@ -742,6 +754,7 @@ class ApiDoc $data['authentication'] = $this->authentication; $data['authenticationRoles'] = $this->authenticationRoles; $data['deprecated'] = $this->deprecated; + $data['scope'] = $this->scope; return $data; } diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 752438a..ae4e1ab 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -506,10 +506,13 @@ class ApiDocExtractor if (isset($v['children'])) { if (isset($v['class'])) { foreach ($v['children'] as $key => $item) { - $array[$k]['children'][$key]['parentClass'] = $v['class']; + if (empty($item['parentClass'] ?? null)) { + $array[$k]['children'][$key]['parentClass'] = $v['class']; + } $array[$k]['children'][$key]['field'] = $key; } } + $array[$k]['children'] = $this->setParentClasses($array[$k]['children']); } } diff --git a/Tests/Formatter/SimpleFormatterTest.php b/Tests/Formatter/SimpleFormatterTest.php index d9b3c5e..ce2da43 100644 --- a/Tests/Formatter/SimpleFormatterTest.php +++ b/Tests/Formatter/SimpleFormatterTest.php @@ -62,6 +62,7 @@ class SimpleFormatterTest extends WebTestCase 'authentication' => false, 'authenticationRoles' => [], 'deprecated' => false, + 'scope' => null, ]; $this->assertEquals($expected, $result); diff --git a/Tests/Formatter/testFormat-result.php b/Tests/Formatter/testFormat-result.php index 098ef8e..de5b26b 100644 --- a/Tests/Formatter/testFormat-result.php +++ b/Tests/Formatter/testFormat-result.php @@ -1114,6 +1114,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'views' => [ 'default', 'test', @@ -1128,6 +1129,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 2 => [ 'method' => 'ANY', @@ -1145,6 +1147,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 3 => [ 'method' => 'ANY', @@ -1156,6 +1159,7 @@ With multiple lines.', 1 => 'ROLE_FOOBAR', ], 'deprecated' => false, + 'scope' => null, ], 4 => [ 'method' => 'POST', @@ -1422,6 +1426,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 5 => [ 'method' => 'GET', @@ -1456,6 +1461,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 6 => [ 'method' => 'ANY', @@ -1490,6 +1496,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 7 => [ 'method' => 'GET', @@ -1509,6 +1516,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'resourceDescription' => 'Popo', 'section' => 'Popo', ], @@ -1538,6 +1546,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'resourceDescription' => 'Popo', 'section' => 'Popo', ], @@ -1558,6 +1567,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'resourceDescription' => 'Popo', 'section' => 'Popo', ], @@ -1586,6 +1596,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'resourceDescription' => 'Popo', 'section' => 'Popo', ], @@ -1622,6 +1633,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, 'resourceDescription' => 'Popo', 'section' => 'Popo', ], @@ -1889,6 +1901,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 13 => [ 'method' => 'GET', @@ -1915,6 +1928,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 14 => [ 'method' => 'ANY', @@ -1924,6 +1938,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 15 => [ 'method' => 'ANY', @@ -1940,6 +1955,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 16 => [ 'method' => 'GET', @@ -1949,6 +1965,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => true, + 'scope' => null, ], 17 => [ 'method' => 'POST', @@ -1968,6 +1985,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 18 => [ 'method' => 'GET', @@ -1984,6 +2002,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 19 => [ 'method' => 'GET', @@ -1999,6 +2018,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 20 => [ 'method' => 'GET', @@ -2034,6 +2054,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 22 => [ 'method' => 'ANY', @@ -2135,6 +2156,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 23 => [ 'method' => 'ANY', @@ -2182,6 +2204,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 24 => [ 'method' => 'ANY', @@ -2283,6 +2306,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 25 => [ 'method' => 'POST', @@ -2292,6 +2316,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 26 => [ 'method' => 'POST', @@ -2301,6 +2326,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 27 => [ 'authentication' => false, @@ -2309,6 +2335,7 @@ With multiple lines.', 'https' => false, 'authenticationRoles' => [], 'deprecated' => false, + 'scope' => null, 'requirements' => [ '_format' => [ 'requirement' => '', diff --git a/Tests/Formatter/testFormat-result_1.php b/Tests/Formatter/testFormat-result_1.php index 28f6076..a92292e 100644 --- a/Tests/Formatter/testFormat-result_1.php +++ b/Tests/Formatter/testFormat-result_1.php @@ -290,6 +290,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 1 => [ 'method' => 'PUT|PATCH', @@ -312,6 +313,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], '/api/resources' => [ @@ -383,6 +385,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 1 => [ 'method' => 'POST', @@ -821,6 +824,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 2 => [ 'method' => 'DELETE', @@ -843,6 +847,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 3 => [ 'method' => 'GET', @@ -865,6 +870,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], '/tests' => [ @@ -896,6 +902,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 1 => [ 'method' => 'POST', @@ -956,6 +963,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], '/tests2' => [ @@ -979,6 +987,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], 'TestResource' => [ @@ -993,6 +1002,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], 'others' => [ @@ -1031,6 +1041,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 1 => [ 'method' => 'ANY', @@ -1048,6 +1059,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 2 => [ 'method' => 'ANY', @@ -1059,6 +1071,7 @@ With multiple lines.', 1 => 'ROLE_FOOBAR', ], 'deprecated' => false, + 'scope' => null, ], 3 => [ 'method' => 'POST', @@ -1325,6 +1338,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 4 => [ 'method' => 'GET', @@ -1357,6 +1371,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 5 => [ 'method' => 'ANY', @@ -1391,6 +1406,7 @@ And, it supports multilines until the first \'@\' char.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 6 => [ 'method' => 'ANY', @@ -1656,6 +1672,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 7 => [ 'method' => 'GET', @@ -1682,6 +1699,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 8 => [ 'method' => 'ANY', @@ -1691,6 +1709,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 9 => [ 'method' => 'GET', @@ -1701,6 +1720,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 10 => [ 'method' => 'ANY', @@ -1717,6 +1737,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 11 => [ 'method' => 'GET', @@ -1726,6 +1747,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => true, + 'scope' => null, ], 12 => [ 'method' => 'POST', @@ -1745,6 +1767,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 13 => [ 'method' => 'GET', @@ -1761,6 +1784,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 14 => [ 'method' => 'GET', @@ -1776,6 +1800,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 15 => [ 'method' => 'GET', @@ -1792,6 +1817,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 16 => [ 'method' => 'POST', @@ -1811,6 +1837,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 17 => [ 'method' => 'GET', @@ -1826,6 +1853,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 18 => [ 'method' => 'GET', @@ -1841,6 +1869,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 19 => [ 'method' => 'GET', @@ -1855,6 +1884,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 20 => [ 'method' => 'ANY', @@ -1974,6 +2004,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 21 => [ 'method' => 'ANY', @@ -2021,6 +2052,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 22 => [ 'method' => 'ANY', @@ -2140,6 +2172,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 23 => [ 'method' => 'POST', @@ -2149,6 +2182,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 24 => [ 'method' => 'POST', @@ -2158,6 +2192,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], 25 => [ 'method' => 'GET', @@ -2174,6 +2209,7 @@ With multiple lines.', 'authenticationRoles' => [ ], 'deprecated' => false, + 'scope' => null, ], ], ];