From f37b6e61cbebab71424ae9561cd5932776c952d9 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 8 Feb 2022 08:24:27 -0600 Subject: added support for basic documentation of apps --- lazybones-documentation.lisp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lazybones-documentation.lisp (limited to 'lazybones-documentation.lisp') diff --git a/lazybones-documentation.lisp b/lazybones-documentation.lisp new file mode 100644 index 0000000..bb94515 --- /dev/null +++ b/lazybones-documentation.lisp @@ -0,0 +1,43 @@ +;;;; lazybones-documentation.lisp -- documenting APP instances + +(in-package :lazybones) + +(defun sorted-endpoints (endpoints) + (sort (copy-seq endpoints) #'string< :key #'endpoint-route)) + +(defun generate-app-documentation (app) + "For now, generates a single Markdown string that documents each endpoint in APP." + (symbol-macrolet ((newline (progn (princ #\newline)(princ #\newline)))) + (with-slots + (title + version + endpoints + (default-authorizer authorizer) + default-content-type + app-error-response-contents + description) + app + (with-output-to-string (*standard-output*) + (princ "# ") (princ title) (princ " - ") (princ "v") (princ version) + newline + (princ description) + newline + (princ "## Endpoints") + (dolist (ep (sorted-endpoints endpoints)) + (with-slots (method route authorizer endpoint-documentation) ep + newline + (princ "### ") (princ method) (princ " ") (princ route) + newline + (when authorizer + (princ "Authorization Required: ") + (cond ((function-or-function-name-p authorizer) + (princ (documentation authorizer 'function))) + ((function-or-function-name-p default-authorizer) + (princ (documentation default-authorizer 'function)))) + newline) + + (princ endpoint-documentation) )))))) + +(defun function-or-function-name-p (thing) + (or (functionp thing) + (and (symbolp thing) (fboundp thing)))) -- cgit v1.2.3