doc/commands: render `commands_main` as JSON
[nit.git] / src / doc / api / api_model.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 module api_model
16
17 import api_base
18
19 redef class APIRouter
20 redef init do
21 super
22 use("/list", new APIList(config))
23 use("/random", new APIRandom(config))
24 use("/search", new APISearch(config))
25
26 use("/entity/:id", new APIEntity(config))
27 use("/doc/:id", new APIEntityDoc(config))
28 use("/code/:id", new APIEntityCode(config))
29 use("/lin/:id", new APIEntityLinearization(config))
30 use("/defs/:id", new APIEntityDefs(config))
31 use("/intros/:id", new APIEntityIntros(config))
32 use("/redefs/:id", new APIEntityRedefs(config))
33 use("/meta/:id", new APIEntityMetadata(config))
34 use("/all/:id", new APIEntityAll(config))
35
36 use("/ancestors/:id", new APIEntityAncestors(config))
37 use("/parents/:id", new APIEntityParents(config))
38 use("/children/:id", new APIEntityChildren(config))
39 use("/descendants/:id", new APIEntityDescendants(config))
40
41 use("/uml/:id", new APIEntityUML(config))
42 use("/graph/inheritance/:id", new APIInheritanceGraph(config))
43
44 use("/catalog/packages/", new APICatalogPackages(config))
45 use("/catalog/stats", new APICatalogStats(config))
46 use("/catalog/tags", new APICatalogTags(config))
47 use("/catalog/tag/:tid", new APICatalogTag(config))
48 use("/catalog/person/:pid", new APICatalogPerson(config))
49 use("/catalog/person/:pid/maintaining", new APICatalogMaintaining(config))
50 use("/catalog/person/:pid/contributing", new APICatalogContributing(config))
51
52 use("/ini/desc/:id", new APIIniDesc(config))
53 use("/ini/git/:id", new APIIniGit(config))
54 use("/ini/clone/:id", new APIIniClone(config))
55 use("/ini/issues/:id", new APIIniIssues(config))
56 use("/ini/maintainer/:id", new APIIniMaintainer(config))
57 use("/ini/contributors/:id", new APIIniContributors(config))
58 use("/ini/license/:id", new APIIniLicense(config))
59 use("/ini/license-file/:id", new APIIniLicenseFile(config))
60 use("/ini/license-content/:id", new APIIniLicenseFileContent(config))
61 use("/ini/contrib-file/:id", new APIIniContribFile(config))
62 use("/ini/contrib-content/:id", new APIIniContribFileContent(config))
63 end
64 end
65
66 # An API Handler that use a DocCommand to respond
67 abstract class APICommand
68 super APIHandler
69
70 # Return the doc command to apply for self
71 fun command: DocCommand is abstract
72
73 redef fun get(req, res) do
74 var command = self.command
75 var status = command.http_init(req)
76 if status isa CmdError then
77 res.api_error(status.http_status_code, status.to_s)
78 return
79 end
80 res.api_json(req, command.to_json)
81 end
82 end
83
84 # CmdModel
85
86 # List all mentities.
87 #
88 # Example: `GET /list?kind=modules?limit=10`
89 class APIList
90 super APICommand
91
92 redef fun command do return new CmdModelEntities(config.view)
93 end
94
95 # Return a random list of MEntities.
96 #
97 # Example: `GET /random?kind=modules&limit=10`
98 class APIRandom
99 super APICommand
100
101 redef fun command do return new CmdRandomEntities(config.view)
102 end
103
104 # Search mentities from a cmd string.
105 #
106 # Example: `GET /search?q=Arr`
107 class APISearch
108 super APIList
109
110 redef fun command do return new CmdCatalogSearch(config.view, config.catalog)
111 end
112
113 # CmdEntity
114
115 # Return the JSON representation of a MEntity.
116 #
117 # Example: `GET /entity/core::Array`
118 class APIEntity
119 super APICommand
120
121 redef fun command do return new CmdEntity(config.view)
122 end
123
124 # Return the full MDoc of a MEntity.
125 #
126 # Example: `GET /entity/core::Array/doc`
127 class APIEntityDoc
128 super APICommand
129
130 redef fun command do return new CmdComment(config.view)
131 end
132
133 # List MEntity ancestors
134 #
135 # Example: `GET /ancestors/core::Array`
136 class APIEntityAncestors
137 super APICommand
138
139 redef fun command do return new CmdAncestors(config.view)
140 end
141
142 # List MEntity parents
143 #
144 # Example: `GET /parents/core::Array`
145 class APIEntityParents
146 super APICommand
147
148 redef fun command do return new CmdParents(config.view)
149 end
150
151 # List MEntity children
152 #
153 # Example: `GET /children/core::Array`
154 class APIEntityChildren
155 super APICommand
156
157 redef fun command do return new CmdChildren(config.view)
158 end
159
160 # List MEntity descendants
161 #
162 # Example: `GET /descendants/core::Array`
163 class APIEntityDescendants
164 super APICommand
165
166 redef fun command do return new CmdDescendants(config.view)
167 end
168
169 # Linearize super definitions of a MClassDef or a MPropDef if any.
170 #
171 # Example: `GET /linearization/core::Array`
172 class APIEntityLinearization
173 super APICommand
174
175 redef fun command do return new CmdLinearization(config.view)
176 end
177
178 # List definitions of a MEntity.
179 #
180 # Example: `GET /defs/core::Array`
181 class APIEntityDefs
182 super APICommand
183
184 redef fun command do return new CmdFeatures(config.view)
185 end
186
187 # List intro definitions of a MEntity.
188 #
189 # Example: `GET /intros/core::Array`
190 class APIEntityIntros
191 super APICommand
192
193 redef fun command do return new CmdIntros(config.view)
194 end
195
196 # List redef definitions of a MEntity.
197 #
198 # Example: `GET /redefs/core::Array`
199 class APIEntityRedefs
200 super APICommand
201
202 redef fun command do return new CmdRedefs(config.view)
203 end
204
205 # List all definitions accessible from a MEntity.
206 #
207 # Example: `GET /all/core::Array`
208 class APIEntityAll
209 super APICommand
210
211 redef fun command do return new CmdAllProps(config.view)
212 end
213
214 # Return the source code of MEntity.
215 #
216 # Example: `GET /code/core::Array`
217 class APIEntityCode
218 super APICommand
219
220 redef fun command do return new CmdEntityCode(config.view, config.modelbuilder)
221 end
222
223 # Return the UML diagram for MEntity.
224 #
225 # Example: `GET /uml/core::Array`
226 class APIEntityUML
227 super APICommand
228
229 redef fun command do return new CmdUML(config.view)
230 end
231
232 # Return the inheritance graph for MEntity.
233 #
234 # Example: `GET /inheritance/core::Array`
235 class APIInheritanceGraph
236 super APICommand
237
238 redef fun command do return new CmdInheritanceGraph(config.view)
239 end
240
241 # CmdCatalog
242
243 # Get all the packages from the catalog using pagination
244 #
245 # `GET /packages?p=1&n=10`: get the list of catalog by page
246 class APICatalogPackages
247 super APICommand
248
249 redef fun command do return new CmdCatalogPackages(config.view, config.catalog)
250 end
251
252 # Get the catalog statistics
253 #
254 # `GET /stats`: return the catalog statistics
255 class APICatalogStats
256 super APICommand
257
258 redef fun command do return new CmdCatalogStats(config.view, config.catalog)
259 end
260
261 # Get the package metadata
262 #
263 # `GET /:id/metadata`: return a paginated list of packages
264 class APIEntityMetadata
265 super APICommand
266
267 redef fun command do return new CmdMetadata(config.view)
268 end
269
270 # Get all the tags from the catalog
271 #
272 # `GET /tags`: the list of tags associated with their number of packages
273 class APICatalogTags
274 super APICommand
275
276 redef fun command do return new CmdCatalogTags(config.view, config.catalog)
277 end
278
279 # Get the packages related to a tag
280 #
281 # `GET /tag/:tid?p=1&n=10`: return a paginated list of packages
282 class APICatalogTag
283 super APICommand
284
285 redef fun command do return new CmdCatalogTag(config.view, config.catalog)
286 end
287
288 # Get a person existing in the catalog
289 #
290 # `GET /person/:pid`: get the person with `pid`
291 class APICatalogPerson
292 super APICommand
293
294 redef fun command do return new CmdCatalogPerson(config.view, config.catalog)
295 end
296
297 # Get the list of mpackages maintained by a person
298 #
299 # `GET /person/:pid/maintaining?p=1&n=10`: return a paginated list of packages
300 class APICatalogMaintaining
301 super APICommand
302
303 redef fun command do return new CmdCatalogMaintaining(config.view, config.catalog)
304 end
305
306 # Get the list of mpackages contributed by a person
307 #
308 # `GET /person/:pid/contributing?p=1&n=10`: return a paginated list of packages
309 class APICatalogContributing
310 super APICommand
311
312 redef fun command do return new CmdCatalogContributing(config.view, config.catalog)
313 end
314
315 # CmdIni
316
317 # Get the package description from the ini file
318 #
319 # `GET /ini/desc/:pid`: return the package description
320 class APIIniDesc
321 super APICommand
322
323 redef fun command do return new CmdIniDescription(config.view)
324 end
325
326 # Get the package Git URL from the ini file
327 #
328 # `GET /ini/git/:pid`: return the package Git URL
329 class APIIniGit
330 super APICommand
331
332 redef fun command do return new CmdIniGitUrl(config.view)
333 end
334
335 # Get the package Git clone command from the ini file
336 #
337 # `GET /ini/clone/:pid`: return the package Git clone command
338 class APIIniClone
339 super APICommand
340
341 redef fun command do return new CmdIniCloneCommand(config.view)
342 end
343
344 # Get the package issues URL from the ini file
345 #
346 # `GET /ini/issues/:pid`: return the package issues URL
347 class APIIniIssues
348 super APICommand
349
350 redef fun command do return new CmdIniIssuesUrl(config.view)
351 end
352
353 # Get the package maintainer from the ini file
354 #
355 # `GET /ini/maintainer/:pid`: return the package maintainer
356 class APIIniMaintainer
357 super APICommand
358
359 redef fun command do return new CmdIniMaintainer(config.view)
360 end
361
362 # Get the package contributors from the ini file
363 #
364 # `GET /ini/clone/:pid`: return the package contributors
365 class APIIniContributors
366 super APICommand
367
368 redef fun command do return new CmdIniContributors(config.view)
369 end
370
371 # Get the package license from the ini file
372 #
373 # `GET /ini/clone/:pid`: return the package license
374 class APIIniLicense
375 super APICommand
376
377 redef fun command do return new CmdIniLicense(config.view)
378 end
379
380 # Get the package license file
381 #
382 # `GET /ini/license-file/:pid`: return the package license file
383 class APIIniLicenseFile
384 super APICommand
385
386 redef fun command do return new CmdLicenseFile(config.view)
387 end
388
389 # Get the package contrib file
390 #
391 # `GET /ini/contrib-file/:pid`: return the package contrib file
392 class APIIniContribFile
393 super APICommand
394
395 redef fun command do return new CmdContribFile(config.view)
396 end
397
398 # Get the package license file content
399 #
400 # `GET /ini/license-file/:pid`: return the package license file content
401 class APIIniLicenseFileContent
402 super APICommand
403
404 redef fun command do return new CmdLicenseFileContent(config.view)
405 end
406
407 # Get the package contrib file content
408 #
409 # `GET /ini/contrib-file/:pid`: return the package contrib file content
410 class APIIniContribFileContent
411 super APICommand
412
413 redef fun command do return new CmdContribFileContent(config.view)
414 end