Merge: nitc: check pkg-config packages availability later
[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 end
52 end
53
54 # An API Handler that use a DocCommand to respond
55 abstract class APICommand
56 super APIHandler
57
58 # Return the doc command to apply for self
59 fun command: DocCommand is abstract
60
61 redef fun get(req, res) do
62 var command = self.command
63 var status = command.http_init(req)
64 if status isa CmdError then
65 res.api_error(status.http_status_code, status.to_s)
66 return
67 end
68 res.api_json(req, command.to_json)
69 end
70 end
71
72 # CmdModel
73
74 # List all mentities.
75 #
76 # Example: `GET /list?kind=modules?limit=10`
77 class APIList
78 super APICommand
79
80 redef fun command do return new CmdModelEntities(config.view)
81 end
82
83 # Return a random list of MEntities.
84 #
85 # Example: `GET /random?kind=modules&limit=10`
86 class APIRandom
87 super APICommand
88
89 redef fun command do return new CmdRandomEntities(config.view)
90 end
91
92 # Search mentities from a cmd string.
93 #
94 # Example: `GET /search?q=Arr`
95 class APISearch
96 super APIList
97
98 redef fun command do return new CmdCatalogSearch(config.view, config.catalog)
99 end
100
101 # CmdEntity
102
103 # Return the JSON representation of a MEntity.
104 #
105 # Example: `GET /entity/core::Array`
106 class APIEntity
107 super APICommand
108
109 redef fun command do return new CmdEntity(config.view)
110 end
111
112 # Return the full MDoc of a MEntity.
113 #
114 # Example: `GET /entity/core::Array/doc`
115 class APIEntityDoc
116 super APICommand
117
118 redef fun command do return new CmdComment(config.view)
119 end
120
121 # List MEntity ancestors
122 #
123 # Example: `GET /ancestors/core::Array`
124 class APIEntityAncestors
125 super APICommand
126
127 redef fun command do return new CmdAncestors(config.view)
128 end
129
130 # List MEntity parents
131 #
132 # Example: `GET /parents/core::Array`
133 class APIEntityParents
134 super APICommand
135
136 redef fun command do return new CmdParents(config.view)
137 end
138
139 # List MEntity children
140 #
141 # Example: `GET /children/core::Array`
142 class APIEntityChildren
143 super APICommand
144
145 redef fun command do return new CmdChildren(config.view)
146 end
147
148 # List MEntity descendants
149 #
150 # Example: `GET /descendants/core::Array`
151 class APIEntityDescendants
152 super APICommand
153
154 redef fun command do return new CmdDescendants(config.view)
155 end
156
157 # Linearize super definitions of a MClassDef or a MPropDef if any.
158 #
159 # Example: `GET /linearization/core::Array`
160 class APIEntityLinearization
161 super APICommand
162
163 redef fun command do return new CmdLinearization(config.view)
164 end
165
166 # List definitions of a MEntity.
167 #
168 # Example: `GET /defs/core::Array`
169 class APIEntityDefs
170 super APICommand
171
172 redef fun command do return new CmdFeatures(config.view)
173 end
174
175 # List intro definitions of a MEntity.
176 #
177 # Example: `GET /intros/core::Array`
178 class APIEntityIntros
179 super APICommand
180
181 redef fun command do return new CmdIntros(config.view)
182 end
183
184 # List redef definitions of a MEntity.
185 #
186 # Example: `GET /redefs/core::Array`
187 class APIEntityRedefs
188 super APICommand
189
190 redef fun command do return new CmdRedefs(config.view)
191 end
192
193 # List all definitions accessible from a MEntity.
194 #
195 # Example: `GET /all/core::Array`
196 class APIEntityAll
197 super APICommand
198
199 redef fun command do return new CmdAllProps(config.view)
200 end
201
202 # Return the source code of MEntity.
203 #
204 # Example: `GET /code/core::Array`
205 class APIEntityCode
206 super APICommand
207
208 redef fun command do return new CmdEntityCode(config.view, config.modelbuilder)
209 end
210
211 # Return the UML diagram for MEntity.
212 #
213 # Example: `GET /uml/core::Array`
214 class APIEntityUML
215 super APICommand
216
217 redef fun command do return new CmdUML(config.view)
218 end
219
220 # Return the inheritance graph for MEntity.
221 #
222 # Example: `GET /inheritance/core::Array`
223 class APIInheritanceGraph
224 super APICommand
225
226 redef fun command do return new CmdInheritanceGraph(config.view)
227 end
228
229 # CmdCatalog
230
231 # Get all the packages from the catalog using pagination
232 #
233 # `GET /packages?p=1&n=10`: get the list of catalog by page
234 class APICatalogPackages
235 super APICommand
236
237 redef fun command do return new CmdCatalogPackages(config.view, config.catalog)
238 end
239
240 # Get the catalog statistics
241 #
242 # `GET /stats`: return the catalog statistics
243 class APICatalogStats
244 super APICommand
245
246 redef fun command do return new CmdCatalogStats(config.view, config.catalog)
247 end
248
249 # Get the package metadata
250 #
251 # `GET /:id/metadata`: return a paginated list of packages
252 class APIEntityMetadata
253 super APICommand
254
255 redef fun command do return new CmdMetadata(config.view)
256 end
257
258 # Get all the tags from the catalog
259 #
260 # `GET /tags`: the list of tags associated with their number of packages
261 class APICatalogTags
262 super APICommand
263
264 redef fun command do return new CmdCatalogTags(config.view, config.catalog)
265 end
266
267 # Get the packages related to a tag
268 #
269 # `GET /tag/:tid?p=1&n=10`: return a paginated list of packages
270 class APICatalogTag
271 super APICommand
272
273 redef fun command do return new CmdCatalogTag(config.view, config.catalog)
274 end
275
276 # Get a person existing in the catalog
277 #
278 # `GET /person/:pid`: get the person with `pid`
279 class APICatalogPerson
280 super APICommand
281
282 redef fun command do return new CmdCatalogPerson(config.view, config.catalog)
283 end
284
285 # Get the list of mpackages maintained by a person
286 #
287 # `GET /person/:pid/maintaining?p=1&n=10`: return a paginated list of packages
288 class APICatalogMaintaining
289 super APICommand
290
291 redef fun command do return new CmdCatalogMaintaining(config.view, config.catalog)
292 end
293
294 # Get the list of mpackages contributed by a person
295 #
296 # `GET /person/:pid/contributing?p=1&n=10`: return a paginated list of packages
297 class APICatalogContributing
298 super APICommand
299
300 redef fun command do return new CmdCatalogContributing(config.view, config.catalog)
301 end