Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 6b2525a

Browse files
committed
Expand api docs generator
1 parent b341660 commit 6b2525a

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

core/src/core/classes/class.PydioSdkGenerator.php

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,41 @@
2828
* @subpackage Core
2929
*/
3030

31+
//define("JSON_DIR", AJXP_INSTALL_PATH."/core/doc/api");
3132
define("JSON_DIR", AJXP_INSTALL_PATH."/../api");
3233
define("JSON_URL", "https://pydio.com/static-docs/api");
34+
define("API_DOC_PAGE", "https://pydio.com/en/docs/references/pydio-api#!/");
3335

3436
class PydioSdkGenerator
3537
{
38+
static $apiGroups = [
39+
"fs" => ["access.fs", "index.*", "meta.*", "editor.*", "action.share", "action.powerfs"],
40+
"conf" => ["access.ajxp_conf", "action.scheduler", "action.updater"],
41+
"lifecycle" => ["conf.*", "auth.*", "gui.*", "core.*", "action.avatar"],
42+
"nonfs" => ["access.*"],
43+
"misc" => ["*"]
44+
];
45+
46+
static $apiGroupsLabels = [
47+
"fs" => "Most current operations on files and folders, their metadata, and additional sharing features.",
48+
"conf" => "Administration task : users/groups/workspaces provisionning, maintenance tasks, etc... Generally performed using /settings/ as workspace alias.",
49+
"lifecycle" => "Application objects lifecycle, like current user access rights and preferences, authentication utils, etc. As they are generally not linked to a specific workspace, these actions can be performed using /pydio/ instead of a workspace alias.",
50+
"nonfs" => "Non-standard drivers accessing to structured data like IMAP, MySQL, Apis, etc.",
51+
"misc" => "Other plugins actions."
52+
];
53+
54+
public static function findApiGroupForPlugin($pluginId){
55+
list($pType, $pName) = explode(".", $pluginId);
56+
foreach(self::$apiGroups as $groupName => $pluginPatterns){
57+
foreach($pluginPatterns as $pattern){
58+
if($pattern == "*" || $pattern == "$pType.*" || $pattern == "$pType.$pName"){
59+
return $groupName;
60+
}
61+
}
62+
}
63+
return "misc";
64+
}
65+
3666
public static function analyzeRegistry($versionString)
3767
{
3868
if(!AJXP_SERVER_DEBUG) {
@@ -96,9 +126,12 @@ public static function analyzeRegistry($versionString)
96126
$comment = $callbackNode->getAttribute("developerComment");
97127
$http = $callbackNode->getAttribute("preferredHttp");
98128
$restParams = $callbackNode->getAttribute("restParams");
99-
$prefix = "/default";
100-
if($pluginName == "access.ajxp_conf"){
101-
$prefix = "/ajxp_conf";
129+
$prefix = "/workspace_alias";
130+
$apiGroup = self::findApiGroupForPlugin($pluginName);
131+
if($apiGroup == "conf"){
132+
$prefix = "/settings";
133+
}else if($apiGroup == "lifecycle"){
134+
$prefix = "/pydio";
102135
}
103136
$api = array(
104137
"path" => $prefix."/".$actionName . (empty($restParams) ? "" : $restParams),
@@ -118,12 +151,14 @@ public static function analyzeRegistry($versionString)
118151

119152
file_put_contents($jsFile, "window.sdkMethods = ".json_encode($methods, JSON_PRETTY_PRINT));
120153

121-
122154
$apidocs = array(
123155
"apiVersion" => $versionString,
124156
"swaggerVersion" => "1.2",
125157
"apis" => array()
126158
);
159+
$allDocs = array();
160+
$markdowns = array();
161+
127162
foreach($swaggerAPIs as $pluginName => $apis){
128163

129164
echo("Writing file for $pluginName");
@@ -138,13 +173,55 @@ public static function analyzeRegistry($versionString)
138173
);
139174
file_put_contents($swaggerJsonDir."/".$pluginName, json_encode($swaggerJson, JSON_PRETTY_PRINT));
140175
$p = $pServ->findPluginById($pluginName);
176+
$apiGroup = self::findApiGroupForPlugin($pluginName);
177+
if(!isset($allDocs[$apiGroup])) {
178+
$allDocs[$apiGroup] = array();
179+
$markdowns[$apiGroup] = array();
180+
}
181+
$markdowns[$apiGroup][] = self::makeMarkdown($p, $apis);
182+
$allDocs[$apiGroup][] = array(
183+
"path" => JSON_URL."/$versionString/".$pluginName,
184+
"description" => $p->getManifestDescription()
185+
);
141186
$apidocs["apis"][] = array(
142187
"path" => JSON_URL."/$versionString/".$pluginName,
143188
"description" => $p->getManifestDescription()
144189
);
145190

146191
}
192+
foreach($allDocs as $apiGroupName => $groupApis){
193+
$groupApiDocs = array(
194+
"apiVersion" => $versionString,
195+
"swaggerVersion" => "1.2",
196+
"apis" => $groupApis
197+
);
198+
file_put_contents($swaggerJsonDir."/api-docs-".$apiGroupName, json_encode($groupApiDocs, JSON_PRETTY_PRINT));
199+
file_put_contents($swaggerJsonDir."/api-md-".$apiGroupName, self::$apiGroupsLabels[$apiGroupName]."\n\n".implode("", $markdowns[$apiGroupName]));
200+
}
201+
// Store file with all apis.
147202
file_put_contents($swaggerJsonDir."/api-docs", json_encode($apidocs, JSON_PRETTY_PRINT));
148203
}
149204

205+
/**
206+
* @param AJXP_Plugin $plugin
207+
* @param array $apis
208+
* @return string
209+
*/
210+
static public function makeMarkdown($plugin, $apis){
211+
212+
$md = "\n\n";
213+
$md .= "## ".$plugin->getManifestLabel()." ";
214+
$md .= "\n".$plugin->getManifestDescription()."\n\n";
215+
$id = $plugin->getId();
216+
foreach($apis as $index => $api) {
217+
$md .= "\n";
218+
$md .= "- **".$api["path"]."** \n";
219+
$md .= " ".$api["operations"][0]["notes"]." \n";
220+
$md .= " [Details](".API_DOC_PAGE."".$id."/".$api["operations"][0]["nickname"]."_".strtolower($api["operations"][0]["method"])."_".$index.")";
221+
}
222+
223+
return $md;
224+
225+
}
226+
150227
}

0 commit comments

Comments
 (0)