-
-
Save SevereOverfl0w/1d3c439e5d389dacf8317b8e5ab88161 to your computer and use it in GitHub Desktop.
Another win for meander
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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