jinx icon indicating copy to clipboard operation
jinx copied to clipboard

"format" specifications ignored during validation

Open JulesGosnell opened this issue 5 years ago • 0 comments

[jinx "0.1.6"]

I was hoping for a switch to enable this.

When I dug into the code, I found everything necessary to do it, but hooked up wrongly - validate/process-keyword is being called with document instance, rather than schema keys.

I've added this hack to our project to get it to work:

(do ;; tweak jinx:

(require '(juxt.jinx-alpha.validate))

;; warn us if we use an unknown format

(defmethod juxt.jinx-alpha.validate/check-format :default [fmt instance ctx] (log/warn "unrecognised json schema format:" fmt instance))

;; force checking of a field's format - probably wrong but works

(defmethod juxt.jinx-alpha.validate/process-keyword :default [k value instance annotations ctx] (when-let [f (and (map? value) (value "format"))] (juxt.jinx-alpha.validate/process-keyword "format" f (instance k) annotations ctx))))

If I introduce a badly formatted value into my document and validate I now get an error message. It logs the entire object as 'instance'' rather than just the offending field, but it is better than nothing.

JulesGosnell avatar Dec 29 '20 11:12 JulesGosnell