Skip to content

Instantly share code, notes, and snippets.

@lvh
Created July 22, 2016 14:03
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 lvh/243576d4e825d3792d4cd1bb8d8c39d7 to your computer and use it in GitHub Desktop.
Save lvh/243576d4e825d3792d4cd1bb8d8c39d7 to your computer and use it in GitHub Desktop.
(s/def ::json-type any?)
(s/def ::type
#{"object" "array" "integer" "number" "boolean" "string" "null"})
(def schema-type nil)
(defmulti schema-type :type)
(s/def ::shared-schema-props
(s/keys :opt-un [::type ::title ::description ::default]))
(s/def ::title string?)
(s/def ::description string?)
(s/def ::format string?)
(s/def ::default ::json-type)
(s/def ::schema
(s/merge (s/multi-spec schema-type :type)
::shared-schema-props))
(s/def ::root-schema ::schema)
(defmethod schema-type "object"
[_]
(s/keys :opt-un [::min-properties
::max-properties
::additional-properties
::required
::properties]))
(s/def ::min-properties (s/int-in 0 16384))
(s/def ::max-properties (s/int-in 0 16384))
(s/def ::additional-properties
(s/or
::implicit-additional-properties boolean?
::explicit-additional-properties ::schema))
(s/def ::required (s/every string? :distinct true))
(s/def ::properties
(s/map-of keyword? ::schema))
(defmethod schema-type "array"
[_]
::shared-schema-props)
(defmethod schema-type "integer"
[_]
::shared-schema-props)
(defmethod schema-type "number"
[_]
::shared-schema-props)
(defmethod schema-type "boolean"
[_]
::shared-schema-props)
(defmethod schema-type "string"
[_]
::shared-schema-props)
(defmethod schema-type "null"
[_]
::shared-schema-props)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment