28
28
* @subpackage Core
29
29
*/
30
30
31
+ //define("JSON_DIR", AJXP_INSTALL_PATH."/core/doc/api");
31
32
define ("JSON_DIR " , AJXP_INSTALL_PATH ."/../api " );
32
33
define ("JSON_URL " , "https://pydio.com/static-docs/api " );
34
+ define ("API_DOC_PAGE " , "https://pydio.com/en/docs/references/pydio-api#!/ " );
33
35
34
36
class PydioSdkGenerator
35
37
{
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
+
36
66
public static function analyzeRegistry ($ versionString )
37
67
{
38
68
if (!AJXP_SERVER_DEBUG ) {
@@ -96,9 +126,12 @@ public static function analyzeRegistry($versionString)
96
126
$ comment = $ callbackNode ->getAttribute ("developerComment " );
97
127
$ http = $ callbackNode ->getAttribute ("preferredHttp " );
98
128
$ 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 " ;
102
135
}
103
136
$ api = array (
104
137
"path " => $ prefix ."/ " .$ actionName . (empty ($ restParams ) ? "" : $ restParams ),
@@ -118,12 +151,14 @@ public static function analyzeRegistry($versionString)
118
151
119
152
file_put_contents ($ jsFile , "window.sdkMethods = " .json_encode ($ methods , JSON_PRETTY_PRINT ));
120
153
121
-
122
154
$ apidocs = array (
123
155
"apiVersion " => $ versionString ,
124
156
"swaggerVersion " => "1.2 " ,
125
157
"apis " => array ()
126
158
);
159
+ $ allDocs = array ();
160
+ $ markdowns = array ();
161
+
127
162
foreach ($ swaggerAPIs as $ pluginName => $ apis ){
128
163
129
164
echo ("Writing file for $ pluginName " );
@@ -138,13 +173,55 @@ public static function analyzeRegistry($versionString)
138
173
);
139
174
file_put_contents ($ swaggerJsonDir ."/ " .$ pluginName , json_encode ($ swaggerJson , JSON_PRETTY_PRINT ));
140
175
$ 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
+ );
141
186
$ apidocs ["apis " ][] = array (
142
187
"path " => JSON_URL ."/ $ versionString/ " .$ pluginName ,
143
188
"description " => $ p ->getManifestDescription ()
144
189
);
145
190
146
191
}
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.
147
202
file_put_contents ($ swaggerJsonDir ."/api-docs " , json_encode ($ apidocs , JSON_PRETTY_PRINT ));
148
203
}
149
204
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
+
150
227
}
0 commit comments