Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:orn json-schema & generator #400

Merged
merged 1 commit into from Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/malli/generator.cljc
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
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
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