1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 use
("/list", new APIList(config
))
23 use
("/random", new APIRandom(config
))
24 use
("/search", new APISearch(config
))
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
))
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
))
41 use
("/uml/:id", new APIEntityUML(config
))
42 use
("/graph/inheritance/:id", new APIInheritanceGraph(config
))
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
))
54 # An API Handler that use a DocCommand to respond
55 abstract class APICommand
58 # Return the doc command to apply for self
59 fun command
: DocCommand is abstract
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
)
68 res
.api_json
(req
, command
.to_json
)
76 # Example: `GET /list?kind=modules?limit=10`
80 redef fun command
do return new CmdModelEntities(config
.view
)
83 # Return a random list of MEntities.
85 # Example: `GET /random?kind=modules&limit=10`
89 redef fun command
do return new CmdRandomEntities(config
.view
)
92 # Search mentities from a cmd string.
94 # Example: `GET /search?q=Arr`
98 redef fun command
do return new CmdCatalogSearch(config
.view
, config
.catalog
)
103 # Return the JSON representation of a MEntity.
105 # Example: `GET /entity/core::Array`
109 redef fun command
do return new CmdEntity(config
.view
)
112 # Return the full MDoc of a MEntity.
114 # Example: `GET /entity/core::Array/doc`
118 redef fun command
do return new CmdComment(config
.view
)
121 # List MEntity ancestors
123 # Example: `GET /ancestors/core::Array`
124 class APIEntityAncestors
127 redef fun command
do return new CmdAncestors(config
.view
)
130 # List MEntity parents
132 # Example: `GET /parents/core::Array`
133 class APIEntityParents
136 redef fun command
do return new CmdParents(config
.view
)
139 # List MEntity children
141 # Example: `GET /children/core::Array`
142 class APIEntityChildren
145 redef fun command
do return new CmdChildren(config
.view
)
148 # List MEntity descendants
150 # Example: `GET /descendants/core::Array`
151 class APIEntityDescendants
154 redef fun command
do return new CmdDescendants(config
.view
)
157 # Linearize super definitions of a MClassDef or a MPropDef if any.
159 # Example: `GET /linearization/core::Array`
160 class APIEntityLinearization
163 redef fun command
do return new CmdLinearization(config
.view
)
166 # List definitions of a MEntity.
168 # Example: `GET /defs/core::Array`
172 redef fun command
do return new CmdFeatures(config
.view
)
175 # List intro definitions of a MEntity.
177 # Example: `GET /intros/core::Array`
178 class APIEntityIntros
181 redef fun command
do return new CmdIntros(config
.view
)
184 # List redef definitions of a MEntity.
186 # Example: `GET /redefs/core::Array`
187 class APIEntityRedefs
190 redef fun command
do return new CmdRedefs(config
.view
)
193 # List all definitions accessible from a MEntity.
195 # Example: `GET /all/core::Array`
199 redef fun command
do return new CmdAllProps(config
.view
)
202 # Return the source code of MEntity.
204 # Example: `GET /code/core::Array`
208 redef fun command
do return new CmdEntityCode(config
.view
, config
.modelbuilder
)
211 # Return the UML diagram for MEntity.
213 # Example: `GET /uml/core::Array`
217 redef fun command
do return new CmdUML(config
.view
)
220 # Return the inheritance graph for MEntity.
222 # Example: `GET /inheritance/core::Array`
223 class APIInheritanceGraph
226 redef fun command
do return new CmdInheritanceGraph(config
.view
)
231 # Get all the packages from the catalog using pagination
233 # `GET /packages?p=1&n=10`: get the list of catalog by page
234 class APICatalogPackages
237 redef fun command
do return new CmdCatalogPackages(config
.view
, config
.catalog
)
240 # Get the catalog statistics
242 # `GET /stats`: return the catalog statistics
243 class APICatalogStats
246 redef fun command
do return new CmdCatalogStats(config
.view
, config
.catalog
)
249 # Get the package metadata
251 # `GET /:id/metadata`: return a paginated list of packages
252 class APIEntityMetadata
255 redef fun command
do return new CmdMetadata(config
.view
)
258 # Get all the tags from the catalog
260 # `GET /tags`: the list of tags associated with their number of packages
264 redef fun command
do return new CmdCatalogTags(config
.view
, config
.catalog
)
267 # Get the packages related to a tag
269 # `GET /tag/:tid?p=1&n=10`: return a paginated list of packages
273 redef fun command
do return new CmdCatalogTag(config
.view
, config
.catalog
)
276 # Get a person existing in the catalog
278 # `GET /person/:pid`: get the person with `pid`
279 class APICatalogPerson
282 redef fun command
do return new CmdCatalogPerson(config
.view
, config
.catalog
)
285 # Get the list of mpackages maintained by a person
287 # `GET /person/:pid/maintaining?p=1&n=10`: return a paginated list of packages
288 class APICatalogMaintaining
291 redef fun command
do return new CmdCatalogMaintaining(config
.view
, config
.catalog
)
294 # Get the list of mpackages contributed by a person
296 # `GET /person/:pid/contributing?p=1&n=10`: return a paginated list of packages
297 class APICatalogContributing
300 redef fun command
do return new CmdCatalogContributing(config
.view
, config
.catalog
)