diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-12-01 19:25:00 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2023-12-01 19:25:00 +0100 |
commit | e4760abd52718968c47c64b76b5416a1a85af35e (patch) | |
tree | 91f5504b0404ac1a8bfacfe1c3f3df12d48f9ba4 | |
parent | ba2f79a58645be80e1d4d6738529f0f0fe375ca1 (diff) | |
download | dokuwiki-e4760abd52718968c47c64b76b5416a1a85af35e.tar.gz dokuwiki-e4760abd52718968c47c64b76b5416a1a85af35e.zip |
fix type parsing for more complex types
-rw-r--r-- | _test/tests/Remote/ApiCallTest.php | 9 | ||||
-rw-r--r-- | inc/Remote/ApiCall.php | 26 | ||||
-rw-r--r-- | inc/lang/en/openapi.md | 0 |
3 files changed, 20 insertions, 15 deletions
diff --git a/_test/tests/Remote/ApiCallTest.php b/_test/tests/Remote/ApiCallTest.php index f001ec805..43ca33f92 100644 --- a/_test/tests/Remote/ApiCallTest.php +++ b/_test/tests/Remote/ApiCallTest.php @@ -13,12 +13,13 @@ class ApiCallTest extends \DokuWikiTest * in several lines * @param string $foo First variable * @param int $bar + * @param string[] $baz * @something else * @something other * @another tag * @return string The return */ - public function dummyMethod1($foo, $bar) + public function dummyMethod1($foo, $bar, $baz) { return 'dummy'; } @@ -39,7 +40,11 @@ class ApiCallTest extends \DokuWikiTest 'bar' => [ 'type' => 'int', 'description' => '', - ] + ], + 'baz' => [ + 'type' => 'array', + 'description' => '', + ], ], $call->getArgs() ); diff --git a/inc/Remote/ApiCall.php b/inc/Remote/ApiCall.php index 3d5f192a6..1de44a18b 100644 --- a/inc/Remote/ApiCall.php +++ b/inc/Remote/ApiCall.php @@ -283,25 +283,25 @@ class ApiCall if (isset($tags['param'])) { foreach ($tags['param'] as $param) { - if (preg_match('/^(\w+)\s+\$(\w+)(\s+(.*))?$/m', $param, $m)) { - $result['args'][$m[2]] = [ - 'type' => $this->cleanTypeHint($m[1]), - 'description' => trim($m[3] ?? ''), - ]; - } + [$type, $name, $description] = array_map('trim', sexplode(' ', $param, 3, '')); + if ($name[0] !== '$') continue; + $name = substr($name, 1); + + $result['args'][$name] = [ + 'type' => $this->cleanTypeHint($type), + 'description' => $description, + ]; } unset($tags['param']); } - if (isset($tags['return'])) { $return = $tags['return'][0]; - if (preg_match('/^(\w+)(\s+(.*))?$/m', $return, $m)) { - $result['return'] = [ - 'type' => $this->cleanTypeHint($m[1]), - 'description' => trim($m[2] ?? '') - ]; - } + [$type, $description] = array_map('trim', sexplode(' ', $return, 2, '')); + $result['return'] = [ + 'type' => $this->cleanTypeHint($type), + 'description' => $description + ]; unset($tags['return']); } diff --git a/inc/lang/en/openapi.md b/inc/lang/en/openapi.md new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/inc/lang/en/openapi.md |