/why-doc

why?doc: A simple API docs generator for simple APIs.

Primary LanguageHTML

Archived, not general enough >:)


why?doc

A simple API docs generator for simple APIs.

Usage (example with Hono)

Import:

import {
  genDocs,
  WhyDoc,
} from "https://raw.githubusercontent.com/blobbybilb/why-doc/main/doc.ts"

Initialize:

const doc = WhyDoc({
  title: "Test API Docs",
  basePath: "/api", // optional
})

Then, instead of:

app.get(
  "/test",
  (c) => c.text("test"),
)

Do:

app.get(
  doc("/test", "a simple test"), // returns the path to avoid repeating it
  (c) => c.text("test"),
)

Add GET and POST Parameters:

app.post(
  doc("/abc", "", {
    postParams: {
      name: "string",
    },
  }),
  (c) => c.text("Done!"),
)

app.get(
  doc("/xyz", "returns the 'name' GET parameter", {
    getParams: {
      name: "string",
    },
  }),
  (c) => c.text(c.req.query("name")!),
)

Finally, generate the docs:

genDocs() // optionally, pass in a string path to a different output file
app.use("/docs", serveStatic({ path: "./docs.html" })) // serve the static html file however you want

And get something like:

Screenshot 2023-06-08 at 2 20 44 PM

License

GNU LGPLv3