blob: b8e1c34e1b389e0277f0844dcd22c1a9d625a734 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
;;;; 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 content-type route authorizer endpoint-documentation) ep
newline
(princ "### ") (princ method) (princ " ") (princ route)
(terpri)
(princ "*")
(princ (if content-type content-type default-content-type ))
(princ "*")
newline
(a:when-let (vars (endpoint-route-vars ep))
(princ "Route Variables: ") newline
(dolist (var vars)
(princ "- ") (princ var)
(a:when-let (val-parser (route-var-value-parser ep var))
(princ ": ") (princ (strip-newlines (documentation val-parser 'function)))))
newline)
(when authorizer
(princ "Authorization Required: ")
newline
(cond ((function-or-function-name-p authorizer)
(princ (ensure-blockquote (documentation authorizer 'function))))
((function-or-function-name-p default-authorizer)
(princ (ensure-blockquote (documentation default-authorizer 'function)))))
newline)
(princ endpoint-documentation) ))))))
(defun ensure-blockquote (string)
(concatenate 'string "> "
(str:replace-all
'(#\newline)
"
> "
string)))
(defun strip-newlines (string)
(str:replace-all '(#\newline) "" string))
(defun function-or-function-name-p (thing)
(or (functionp thing)
(and (symbolp thing) (fboundp thing))))
(defun endpoint-route-vars (ep)
"return a list of route variables for endpoint EP"
(mapcar 'first (remove-if-not #'consp (endpoint-dispatch-pattern ep))))
(defun route-var-value-parser (ep var)
(second (assoc var (remove-if-not #'consp (endpoint-dispatch-pattern ep)))))
|