-
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
Conversation
Codecov ReportBase: 64.89% // Head: 64.96% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #27471 +/- ##
==========================================
+ Coverage 64.89% 64.96% +0.07%
==========================================
Files 3179 3179
Lines 92322 92497 +175
Branches 11736 11734 -2
==========================================
+ Hits 59910 60093 +183
+ Misses 27574 27568 -6
+ Partials 4838 4836 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
src/metabase/util/schema.clj
Outdated
@@ -399,6 +609,39 @@ | |||
s/Keyword s/Any} | |||
(deferred-tru "parameter must be a map with :id and :type keys"))) | |||
|
|||
(defschema ParameterSourceMalli |
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.
This is here just because I want to try to use multi.
Ideally, this should be part of ParameterMalli
but I don't know how to merge a [:map]
with a [:multi]
. Suggestions are greatly appreciated.
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.
;; TODO - rename this to `PositiveInt`? | ||
(def IntGreaterThanZero | ||
"Schema representing an integer than must also be greater than zero." | ||
(with-api-error-message | ||
(s/constrained s/Int (partial < 0) (deferred-tru "Integer greater than zero")) | ||
(deferred-tru "value must be an integer greater than zero."))) | ||
|
||
(def NonNegativeInt |
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.
this is exactly the same as IntGreaterThanOrEqualToZero
. so I replaced all the places that use it with IntGreaterThanOrEqualToZero
.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
this was overriding the 'integer methods above.
@@ -326,6 +329,20 @@ | |||
(wrap-response-if-needed | |||
(do ~@body)))))))) | |||
|
|||
(defmacro defendpoint-async-schema |
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
and defendpoint
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
No failed tests 🎉 |
src/metabase/util/schema.clj
Outdated
[:map | ||
[:id NonBlankStringMalli] | ||
[:type keyword-or-non-blank-str-malli] | ||
;; TODO how to merge this with ParameterSourceMalli above? |
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.
best to merge these with each of the :multi's children's maps until merging multi with map is implemented in malli
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.
ha. Thanks for letting me know.
What do you think of renaming the schemas in
That would help highlight the fact that we want to move past the Plumatic things, and make the malli ones nicer to use. Also, that's what I did with |
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.
Great work, You caught a few bugs I left in!
I had a few requests and questions but nothing major. It will be great to get more and more things using malli.
I'm not really sure if defschema
is worth using, but if you keep it in, please use the Malli version of it from this comment.
Then the renaming would be nice but can be done later
yes, let's do this.
yea, it was meant to make defining a schema shorter, but now I'm thinking about it doesn't save much lines of code. |
- NonBlankStringMalli -> NonBlankString
…do/ignore on all existsing usage instead
@@ -501,9 +507,10 @@ | |||
"Schema for a string that is a valid representation of a boolean (either `true` or `false`). | |||
Something that adheres to this schema is guaranteed to to work with `Boolean/parseBoolean`." | |||
(mc/schema | |||
[:and {:error/fn (constantly (deferred-tru "value must be a valid boolean string (''true'' or ''false'')."))} | |||
[:and |
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.
what do you think of using [:enum "true" "false"]
here? you did setup those tests to make sure the new m.schemas are equal to the old ones, but if it's too drastic a change that makes sense too
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.
Looks good. Just saw some failing tests having to do with s/defn
being used with malli schemas. Once they're fixed we should be good to go
Migrate
metabase.util.schema
to use Malli.Rename all existing Plumatic schema to have a post fix
Plumatic
and the default name will be reserved for Malli.Example:
Ideally, we could change most of
defendpoint-schema
todefendpoint
after this. Hopefully, this is not too ambitious 🤞Note for reviewers: this PR contains a lot of file changes but most of them are renaming.
The main change is in
metabase.util.schema
and test is inmetabase.util.schema-test
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)