nitweb: add /api/linearization/:full_name service
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 7 Jun 2016 13:37:33 +0000 (09:37 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 7 Jun 2016 15:56:36 +0000 (11:56 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/nitweb.nit
src/web/model_api.nit

index 13e3dce..ef83fb6 100644 (file)
@@ -100,6 +100,7 @@ class APIRouter
                use("/entity/:id", new APIEntity(model, mainmodule))
                use("/code/:id", new APIEntityCode(model, mainmodule, modelbuilder))
                use("/uml/:id", new APIEntityUML(model, mainmodule))
+               use("/linearization/:id", new APIEntityLinearization(model, mainmodule))
        end
 end
 
index 080dcb2..5b24282 100644 (file)
@@ -120,6 +120,26 @@ class APIEntity
        end
 end
 
+# Linearize super definitions of a MClassDef or a MPropDef if any.
+#
+# Example: `GET /entity/core::Array/linearization`
+class APIEntityLinearization
+       super APIHandler
+
+       redef fun get(req, res) do
+               var mentity = mentity_from_uri(req, res)
+               if mentity == null then
+                       res.error 404
+                       return
+               end
+               var lin = mentity.collect_linearization(mainmodule)
+               if lin == null then
+                       res.error 404
+                       return
+               end
+               res.json new JsonArray.from(lin)
+       end
+end
 
 # Return a UML representation of MEntity.
 #