aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-17 09:27:40 -0600
committerColin Okay <okay@toyful.space>2022-02-17 09:27:40 -0600
commitc48ecda020797fe3fe65d55d02a8b72f6e7f19cb (patch)
treee642534d2f6b755244ed475036ee4f69734aa1e3 /example
parent65963eeef5afea104d5a94a99851e6eb79acd101 (diff)
add whole classes to documentation
Diffstat (limited to 'example')
-rw-r--r--example/lazybones-example-docs.md23
-rw-r--r--example/lazybones-example.lisp32
2 files changed, 55 insertions, 0 deletions
diff --git a/example/lazybones-example-docs.md b/example/lazybones-example-docs.md
index a7dfca9..522d129 100644
--- a/example/lazybones-example-docs.md
+++ b/example/lazybones-example-docs.md
@@ -6,6 +6,17 @@ Just an API that defines some endpoints. These
## Endpoints
+### GET /animal/:genus:/:species:
+*text/plain*
+
+Route Variables:
+
+- GENUS
+- SPECIES
+
+
+Prints information about [Animal](#animal) specified by GENUS and SPECIES
+
### POST /crapshoot
*text/plain*
@@ -97,3 +108,15 @@ An instance of person. As JSON, it looks like:
+<h3 id='#animal'>animal</h3>
+
+An animal
+
+**Slots:**
+- GENUS: The genus
+- SPECIES: The species
+- POPULATION: Population on Earth
+- HABITAT: Where the animal lives
+
+
+
diff --git a/example/lazybones-example.lisp b/example/lazybones-example.lisp
index 5eb00d9..018b4ae 100644
--- a/example/lazybones-example.lisp
+++ b/example/lazybones-example.lisp
@@ -135,3 +135,35 @@
}
")
+
+(defclass animal ()
+ ((genus :initarg :genus :documentation "The genus")
+ (species :initarg :species :documentation "The species")
+ (population :initarg :population :documentation "Population on Earth")
+ (habitat :initarg :habitat :documentation "Where the animal lives"))
+ (:documentation "An animal"))
+
+;; add a documentation definition for animal class, the provided slots
+;; will show up in the api docs
+(lzb:add-class-to-definitions (lzb:app)
+ 'animal
+ 'genus 'species 'population 'habitat)
+
+(defvar +dummy-animal+
+ (make-instance 'animal
+ :genus "Pseudocheirus"
+ :species "Peregrinis"
+ :population "Unknown"
+ :habitat "Australia"))
+
+;; you can refer to definitions in docstrings
+(defendpoint* :get "/animal/:genus:/:species:" () ()
+ "Prints information about [Animal](#animal) specified by GENUS and SPECIES"
+ (if (and (string-equal genus "Pseudocheirus")
+ (string-equal species "Peregrinis"))
+ (with-output-to-string (out)
+ (with-slots (genus species population habitat) +dummy-animal+
+ (format out "The ~a ~a lives in ~a. Population: ~a~%"
+ genus species population habitat)))
+ (http-err 404)))
+