aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-12-07 12:54:08 +0100
committerAndreas Gohr <andi@splitbrain.org>2023-12-07 12:55:31 +0100
commit2956a9ba81d2e26a61f332306903981b3fbcf858 (patch)
tree5fdc4eaf1fa8f3d88a3feba74477fa43e062fd5f
parentc09b6b3a383b5b1a86a8def700b3a1551c4deb7f (diff)
downloaddokuwiki-2956a9ba81d2e26a61f332306903981b3fbcf858.tar.gz
dokuwiki-2956a9ba81d2e26a61f332306903981b3fbcf858.zip
OpenAPI Gen: @link tag, examples for known params
-rw-r--r--inc/Remote/ApiCall.php28
-rw-r--r--inc/Remote/OpenAPIGenerator.php41
2 files changed, 65 insertions, 4 deletions
diff --git a/inc/Remote/ApiCall.php b/inc/Remote/ApiCall.php
index 1de44a18b..3f4902c24 100644
--- a/inc/Remote/ApiCall.php
+++ b/inc/Remote/ApiCall.php
@@ -26,6 +26,9 @@ class ApiCall
/** @var string The description of the method */
protected string $description = '';
+ /** @var array[] The parsed tags */
+ protected $tags;
+
/**
* Make the given method available as an API call
*
@@ -176,6 +179,30 @@ class ApiCall
}
/**
+ * Returns the docblock tags that have not been processed specially
+ *
+ * @return array[]
+ */
+ public function getTags()
+ {
+ return $this->tags;
+ }
+
+ /**
+ * Returns any data that is available in the given docblock tag
+ *
+ * @param string $tag
+ * @return string[] returns an empty array if no such tags exists
+ */
+ public function getTag($tag)
+ {
+ if(isset($this->tags[$tag])) {
+ return $this->tags[$tag];
+ }
+ return [];
+ }
+
+ /**
* Fill in the metadata
*
* This uses Reflection to inspect the method signature and doc block
@@ -193,6 +220,7 @@ class ApiCall
$docInfo = $this->parseDocBlock($reflect->getDocComment());
$this->summary = $docInfo['summary'];
$this->description = $docInfo['description'];
+ $this->tags = $docInfo['tags'];
foreach ($reflect->getParameters() as $parameter) {
$name = $parameter->name;
diff --git a/inc/Remote/OpenAPIGenerator.php b/inc/Remote/OpenAPIGenerator.php
index 3724100bb..be10eb635 100644
--- a/inc/Remote/OpenAPIGenerator.php
+++ b/inc/Remote/OpenAPIGenerator.php
@@ -3,6 +3,8 @@
namespace dokuwiki\Remote;
+use dokuwiki\Utf8\PhpString;
+
class OpenAPIGenerator
{
@@ -81,10 +83,19 @@ class OpenAPIGenerator
$retType = $this->fixTypes($call->getReturn()['type']);
$retExample = $this->generateExample('result', $retType);
+ $description = $call->getDescription();
+ $links = $call->getTag('link');
+ if ($links) {
+ $description .= "\n\n**See also:**";
+ foreach ($links as $link) {
+ $description .= "\n\n* " . $this->generateLink($link);
+ }
+ }
+
return [
'operationId' => $method,
'summary' => $call->getSummary(),
- 'description' => $call->getDescription(),
+ 'description' => $description,
'requestBody' => [
'required' => true,
'content' => [
@@ -151,7 +162,7 @@ class OpenAPIGenerator
$props[$name] = [
'type' => $type,
'description' => $info['description'],
- 'examples' => [ $example ],
+ 'examples' => [$example],
];
}
return $schema;
@@ -182,11 +193,33 @@ class OpenAPIGenerator
case 'boolean':
return true;
case 'string':
- return 'some-'.$name;
+ if($name === 'page') return 'playground:playground';
+ if($name === 'media') return 'wiki:dokuwiki-128.png';
+ return 'some-' . $name;
case 'array':
- return ['some-'.$name, 'other-'.$name];
+ return ['some-' . $name, 'other-' . $name];
default:
return new \stdClass();
}
}
+
+ /**
+ * Generates a markdown link from a dokuwiki.org URL
+ *
+ * @param $url
+ * @return mixed|string
+ */
+ protected function generateLink($url)
+ {
+ if (preg_match('/^https?:\/\/(www\.)?dokuwiki\.org\/(.+)$/', $url, $match)) {
+ $name = $match[2];
+
+ $name = str_replace(['_', '#', ':'], [' ', ' ', ' '], $name);
+ $name = PhpString::ucwords($name);
+
+ return "[$name]($url)";
+ } else {
+ return $url;
+ }
+ }
}