nitweb: api serves full mdoc
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 17 Jun 2017 20:04:58 +0000 (16:04 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 15 Aug 2017 18:15:45 +0000 (14:15 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/web/api_model.nit

index 31077c4..d81a3a7 100644 (file)
@@ -26,6 +26,7 @@ redef class APIRouter
                use("/search", new APISearch(config))
                use("/random", new APIRandom(config))
                use("/entity/:id", new APIEntity(config))
+               use("/entity/:id/doc", new APIEntityDoc(config))
                use("/code/:id", new APIEntityCode(config))
                use("/uml/:id", new APIEntityUML(config))
                use("/linearization/:id", new APIEntityLinearization(config))
@@ -147,6 +148,26 @@ class APIEntity
        end
 end
 
+# Return the full MDoc of a MEntity.
+#
+# Example: `GET /entity/core::Array/doc`
+class APIEntityDoc
+       super APIHandler
+
+       redef fun get(req, res) do
+               var mentity = mentity_from_uri(req, res)
+               if mentity == null then return
+
+               var obj = new JsonObject
+               var mdoc = mentity.mdoc_or_fallback
+               if mdoc != null then
+                       obj["documentation"] = mdoc.html_documentation.write_to_string
+                       obj["location"] = mdoc.location
+               end
+               res.json obj
+       end
+end
+
 # List ancestors, parents, child and descendants of MEntity
 #
 # Example: `GET /entity/core::Array/inheritance`