Skip to content

Instantly share code, notes, and snippets.

@SevereOverfl0w
Forked from eraserhd/new.clj
Created September 27, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SevereOverfl0w/fefd6a309d9f07f759921b79f59f56c7 to your computer and use it in GitHub Desktop.
Save SevereOverfl0w/fefd6a309d9f07f759921b79f59f56c7 to your computer and use it in GitHub Desktop.
Another win for meander
(defn- schema->type
[schema]
(let [types (concat
(m/search schema
{"format" "date-time"} :db.type/instant
{"format" "uri"} :db.type/uri
{"type" "array"} '(Array nil)
{"type" "boolean"} :db.type/boolean
{"type" "integer"} :db.type/long
{"type" "string"} :db.type/string
{"items" (m/pred some? ?item)} (list 'Array (schema->type ?item))
{"$ref" (m/pred some? ?ref)} (if (= ?ref "#uuid")
:db.type/uuid
(subs ?ref 1)))
(map schema->type (get schema "allOf")))]
(reduce narrower-type nil types)))
(defn- schema->type
[schema]
(let [types (concat
(case (get schema "type")
nil []
"boolean" [:db.type/boolean]
"string" [:db.type/string]
"integer" [:db.type/long]
"array" ['(Array nil)])
(case (get schema "format")
"date-time" [:db.type/instant]
[])
(when-let [items (get schema "items")]
[(list 'Array (schema->type items))])
(let [$ref (get schema "$ref")]
(cond
(nil? $ref) []
(= $ref "#uuid") [:db.type/uuid]
:else [(subs $ref 1)]))
(map schema->type (get schema "allOf")))]
(reduce narrower-type nil types)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment