-
Notifications
You must be signed in to change notification settings - Fork 8
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
Should we have a phrase-all function? #15
Comments
You are right. There is no
Returning a list of messages from |
I think it's a nice idea, some folks like to return all errors at once for a particular API input - |
Do you also think, that a simple list of messages is a good solution? |
@alexanderkiel yes that's what I would expect |
Here's what I have for this - it works very well: (defn validate-msg
[spec x & {:keys [sep prefix suffix with-val?]
:or {sep " and " prefix "" suffix "" with-val? false}}]
(let [msgbody (->> (s/explain-data spec x) ::s/problems
(mapv #(phrase {} %))
(cljstr/join sep))
msgval (if with-val? (format "<%s>: " x) "")]
(str msgval prefix msgbody suffix)))
(defn make-validator [spec & validate-msg-kvs]
(fn [x]
(if (not (s/valid? spec x))
(apply validate-msg spec x validate-msg-kvs)
"")))
;;; Example use:
(def validate-bc-rep-xref (make-validator ::bc-replicate-xref-rec))
(validate-bc-rep-xref
{:strain-cond-repid (str/split #"-" "T4P-006PEN120MIN-CC"),
:illumbc "TACTTAG",
:sampbc "TGGTCCTx"})
=> "rep id `CC` in `T4P-006PEN120MIN-CC` must be a single upper case or lower case letter or digit and Sample BC `TGGTCCTx` must contain only 'A', 'T', 'G', 'C' characters and Illumina BC `TACTTAG` is not listed as an index in SampleSheet.csv" |
I think this is required to provide messages to consumers. Its very unpleasant to provide one error at a time. This suggests users of this library will create their Therefore I support adding it to the core of the library. |
Hi,
Not sure if i understood all correctly but i don't think that there is a method to get all the errors ?
like :
Do i miss something ?
Thanks,
The text was updated successfully, but these errors were encountered: