Skip to content

Commit

Permalink
Merge pull request #400 from metosin/orn_json-schema_generator
Browse files Browse the repository at this point in the history
:orn json-schema & generator
  • Loading branch information
ikitommi authored Mar 21, 2021
2 parents da6366d + 5bdc96d commit 183217c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/malli/generator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
(defmethod -schema-generator :not [schema options] (gen/such-that (m/validator schema options) (ga/gen-for-pred any?) 100))
(defmethod -schema-generator :and [schema options] (gen/such-that (m/validator schema options) (-> schema (m/children options) first (generator options)) 100))
(defmethod -schema-generator :or [schema options] (-or-gen schema options))
(defmethod -schema-generator :orn [schema options] (-or-gen (m/into-schema :or (m/properties schema) (map last (m/children schema)) (m/options schema)) options))
(defmethod -schema-generator ::m/val [schema options] (generator (first (m/children schema)) options))
(defmethod -schema-generator :map [schema options] (-map-gen schema options))
(defmethod -schema-generator :map-of [schema options] (-map-of-gen schema options))
Expand Down
1 change: 1 addition & 0 deletions src/malli/json_schema.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
(defmethod accept :not [_ _ children _] {:not (last children)})
(defmethod accept :and [_ _ children _] {:allOf children})
(defmethod accept :or [_ _ children _] {:anyOf children})
(defmethod accept :orn [_ _ children _] {:anyOf (map last children)})

(defmethod accept ::m/val [_ _ children _] (first children))
(defmethod accept :map [_ _ children _]
Expand Down
1 change: 1 addition & 0 deletions test/malli/json_schema_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[[:and int? pos-int?] {:allOf [{:type "integer"}
{:type "integer", :minimum 1}]}]
[[:or int? string?] {:anyOf [{:type "integer"} {:type "string"}]}]
[[:orn [:i int?] [:s string?]] {:anyOf [{:type "integer"} {:type "string"}]}]
[[:map
[:a string?]
[:b {:optional true} string?]
Expand Down

0 comments on commit 183217c

Please sign in to comment.