-
Notifications
You must be signed in to change notification settings - Fork 1
/
spellbook.cljc
33 lines (27 loc) · 1.02 KB
/
spellbook.cljc
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
(ns ensorcel.spellbook
#?(:cljs (:require [schema.core :as s
:include-macros true])
:clj (:require [schema.core :as s])))
(def path-regex #"^/?([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*/?)?")
(def path (s/either
[(s/either s/Keyword s/Str)]
(s/both (s/pred #(re-matches path-regex %)) s/Str)))
(def version-regex #"^[a-zA-Z0-9]+")
(def version (s/both (s/pred #(re-matches version-regex %)) s/Str))
(def Schema
(s/protocol s/Schema))
(def SpellBook
{(s/optional-key :version) version
:services {s/Keyword {:path path
:endpoints {s/Keyword {:path path
:method (s/enum :GET :POST :PUT :DELETE)
(s/optional-key :args) Schema
(s/optional-key :returns) Schema}}}}})
(defn validate!
[spellbook]
(s/validate SpellBook spellbook))
(defn correct-path
[path]
(vec
(cond->> path
(vector? path) (interpose "/"))))