nitweb: add /api/defs/:entity to list definitions
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 7 Jun 2016 17:06:10 +0000 (13:06 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 8 Jun 2016 01:13:05 +0000 (21:13 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

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

index ef83fb6..a1a41a3 100644 (file)
@@ -101,6 +101,7 @@ class APIRouter
                use("/code/:id", new APIEntityCode(model, mainmodule, modelbuilder))
                use("/uml/:id", new APIEntityUML(model, mainmodule))
                use("/linearization/:id", new APIEntityLinearization(model, mainmodule))
+               use("/defs/:id", new APIEntityDefs(model, mainmodule))
        end
 end
 
index 5b24282..0d4c205 100644 (file)
@@ -141,6 +141,31 @@ class APIEntityLinearization
        end
 end
 
+# List definitions of a MEntity.
+#
+# Example: `GET /defs/core::Array`
+class APIEntityDefs
+       super APIHandler
+
+       redef fun get(req, res) do
+               var mentity = mentity_from_uri(req, res)
+               var arr = new JsonArray
+               if mentity isa MModule then
+                       for mclassdef in mentity.mclassdefs do arr.add mclassdef
+               else if mentity isa MClass then
+                       for mclassdef in mentity.mclassdefs do arr.add mclassdef
+               else if mentity isa MClassDef then
+                       for mpropdef in mentity.mpropdefs do arr.add mpropdef
+               else if mentity isa MProperty then
+                       for mpropdef in mentity.mpropdefs do arr.add mpropdef
+               else
+                       res.error 404
+                       return
+               end
+               res.json arr
+       end
+end
+
 # Return a UML representation of MEntity.
 #
 # Example: `GET /entity/core::Array/uml`