blob: bb9451544effb6b06ad37ded5e9c910021cf0e93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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))))
|