-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
metabase.util.schema
to Malli
#27471
Merged
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e944abb
first step to migrate util/schema to malli
qnkhuat 687025e
more tests and better mesage handling
qnkhuat df50f27
remove with-error-message-malli and use put the error directly into the
qnkhuat fb8f29c
- NonBlankString -> NonBlankStringPlumatic
qnkhuat 6e200f6
remove defschema and just calls mc/schema when define on
qnkhuat 7aa1728
typo and fix kondo for defendpoint-async-schema
qnkhuat 818181f
add defendpoint-schema to clj-kondo's deprecated var
qnkhuat 7dbed1e
enterprise namespace too
qnkhuat de5ba6e
fix clj-kondo failing in test
qnkhuat e0ad6fe
still fixing kondo in test ns
qnkhuat 8e3348b
merge with master
qnkhuat 6c43fa2
remove ignoring deprecated defschema-schema in clj-kondo, use clj-kon…
qnkhuat 5b56531
still miss a few places
qnkhuat 98f7898
move fn/error to fn instead of leaving it it the outer :and for some …
qnkhuat 3830108
Merge branch 'master' into ngoc-malli-for-util-schema
qnkhuat 144aea9
merge with master and fix conflicts
qnkhuat 8aa22b9
white space fix. *insert same same but different meme*
qnkhuat 8b44d4b
clj-kondo warning fixes
qnkhuat 15d8627
fix misalign plumatic schema
qnkhuat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,22 @@ | |
|
||
(defn- diamond [s] (str "<" s ">")) | ||
(defn- titled [schema] (if-let [t (-> schema mc/properties :title)] (str "(titled: ‘" t "’) ") "")) | ||
(defn- min-max-suffix [schema] | ||
(defn- min-max-suffix-length [schema] | ||
(let [{:keys [min max]} (-> schema mc/properties)] | ||
(cond | ||
(and min max) (str " with length between " min " and " max) | ||
(and min max) (str " with length between " min " and " max " inclusive") | ||
min (str " with length longer than " min) | ||
max (str " with length shorter than " max) | ||
:else ""))) | ||
|
||
(defn- min-max-suffix-number [schema] | ||
(let [{:keys [min max]} (-> schema mc/properties)] | ||
(cond | ||
(and min max) (str " between " min " and " max " inclusive") | ||
min (str " greater than or equal to " min) | ||
max (str " less than or equal to " max) | ||
:else ""))) | ||
|
||
(defmulti accept | ||
"Can this be accepted?" | ||
(fn [name _schema _children _options] name) :default ::default) | ||
|
@@ -86,22 +94,22 @@ | |
" dispatched by " dispatcher))) | ||
|
||
(defmethod accept :map-of [_ schema children _] | ||
(str "a map " (titled schema) "from " (diamond (first children)) " to " (diamond (second children)) (min-max-suffix schema))) | ||
(str "a map " (titled schema) "from " (diamond (first children)) " to " (diamond (second children)) (min-max-suffix-length schema))) | ||
|
||
(defmethod accept 'vector? [_ schema children _] (str "vector" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept :vector [_ schema children _] (str "vector" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept 'vector? [_ schema children _] (str "vector" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
(defmethod accept :vector [_ schema children _] (str "vector" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
|
||
(defmethod accept 'sequential? [_ schema children _] (str "sequence" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept :sequential [_ schema children _] (str "sequence" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept 'sequential? [_ schema children _] (str "sequence" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
(defmethod accept :sequential [_ schema children _] (str "sequence" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
|
||
(defmethod accept 'set? [_ schema children _] (str "set" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept :set [_ schema children _] (str "set" (titled schema) (min-max-suffix schema) " of " (first children))) | ||
(defmethod accept 'set? [_ schema children _] (str "set" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
(defmethod accept :set [_ schema children _] (str "set" (titled schema) (min-max-suffix-length schema) " of " (first children))) | ||
|
||
(defmethod accept 'string? [_ schema _ _] (str "string" (min-max-suffix schema))) | ||
(defmethod accept :string [_ schema _ _] (str "string" (min-max-suffix schema))) | ||
(defmethod accept 'string? [_ schema _ _] (str "string" (min-max-suffix-length schema))) | ||
(defmethod accept :string [_ schema _ _] (str "string" (min-max-suffix-length schema))) | ||
|
||
(defmethod accept 'number? [_ _ _ _] "number") | ||
(defmethod accept :number [_ _ _ _] "number") | ||
(defmethod accept 'number? [_ schema _ _] (str "number" (min-max-suffix-number schema))) | ||
(defmethod accept :number [_ schema _ _] (str "number" (min-max-suffix-number schema))) | ||
|
||
(defmethod accept 'pos-int? [_ _ _ _] "integer greater than 0") | ||
(defmethod accept :pos-int [_ _ _ _] "integer greater than 0") | ||
|
@@ -112,21 +120,21 @@ | |
(defmethod accept 'nat-int? [_ _ _ _] "natural integer") | ||
(defmethod accept :nat-int [_ _ _ _] "natural integer") | ||
|
||
(defmethod accept 'float? [_ _ _ _] "float") | ||
(defmethod accept :float [_ _ _ _] "float") | ||
(defmethod accept 'float? [_ schema _ _] (str "float" (min-max-suffix-number schema))) | ||
(defmethod accept :float [_ schema _ _] (str "float" (min-max-suffix-number schema))) | ||
|
||
(defmethod accept 'pos? [_ _ _ _] "number greater than 0") | ||
(defmethod accept :pos [_ _ _ _] "number greater than 0") | ||
|
||
(defmethod accept 'neg? [_ _ _ _] "number less than 0") | ||
(defmethod accept :neg [_ _ _ _] "number less than 0") | ||
|
||
(defmethod accept 'integer? [_ schema _ _] (str "integer" (min-max-suffix schema))) | ||
(defmethod accept 'int? [_ schema _ _] (str "integer" (min-max-suffix schema))) | ||
(defmethod accept :int [_ schema _ _] (str "integer" (min-max-suffix schema))) | ||
(defmethod accept 'integer? [_ schema _ _] (str "integer" (min-max-suffix-number schema))) | ||
(defmethod accept 'int? [_ schema _ _] (str "integer" (min-max-suffix-number schema))) | ||
(defmethod accept :int [_ schema _ _] (str "integer" (min-max-suffix-number schema))) | ||
|
||
(defmethod accept 'double? [_ schema _ _] (str "double" (min-max-suffix schema))) | ||
(defmethod accept :double [_ schema _ _] (str "double" (min-max-suffix schema))) | ||
(defmethod accept 'double? [_ schema _ _] (str "double" (min-max-suffix-number schema))) | ||
(defmethod accept :double [_ schema _ _] (str "double" (min-max-suffix-number schema))) | ||
|
||
(defmethod accept :merge [_ schema _ options] ((::describe options) (mc/deref schema) options)) | ||
(defmethod accept :union [_ schema _ options] ((::describe options) (mc/deref schema) options)) | ||
|
@@ -185,10 +193,6 @@ | |
(defmethod accept 'keyword? [_ _ _ _] "keyword") | ||
(defmethod accept :keyword [_ _ _ _] "keyword") | ||
|
||
(defmethod accept 'integer? [_ _ _ _] "integer") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was overriding the 'integer methods above. |
||
(defmethod accept 'int? [_ _ _ _] "integer") | ||
(defmethod accept :int [_ _ _ _] "integer") | ||
|
||
(defn- -map [_n schema children _o] | ||
(let [optional (set (->> children (filter (mc/-comp :optional second)) (mapv first))) | ||
additional-properties (:closed (mc/properties schema)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write this to be asymmetry with
defendpoint-schema
anddefendpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch