/ / Mit clojure.core / Mit prismatischem Schema erweitern Ich bekomme ein unterschiedliches Verhalten von s / protocol in s / validate und s / with-fn-validation - clojure, prismatic-schema

Mit clojure.core / Extend mit Prismatic Schema erhalte ich ein unterschiedliches Verhalten von s / protocol in s / validate und in s / with-fn-Validierung - clojure, prismatic-schema

Ich versuche, das Protokoll einer defrecord-Instanz zu validieren, die ich dynamisch mit clojure.core / extend erstellt habe

Unten können Sie sehen, dass die Erfüllungen true und erfüllt(s / validate (s / protocol ...)) löst keine Ausnahme aus, aber wenn ich s / with-fn-validation starte, erhalte ich eine Schemaausnahme (nicht (erfüllt Protokoll)), obwohl es darin enthalten ist für diesen Körper bekomme ich immer das gleiche Ergebnis (erfüllt Protokoll x)

(ns wrapper.issue
(:require [schema.core :as s]))

(defprotocol Welcome
(greetings [e] )
(say_bye [e a b])
)

(s/defn greetings+ :-  s/Str
[component :- (s/protocol Welcome)]
(greetings component))

(defrecord Example []
Welcome
(greetings [this] "my example greeting!")
(say_bye [this a b] (str "saying good bye from " a " to " b))
)

(defrecord MoreSimpleWrapper [e])

(extend MoreSimpleWrapper
Welcome
{:greetings (fn [this]
(str "wrapping!! " (greetings (:e this)))
)
:say_bye (fn  [this a b]
(str "good bye !"))})


(println (satisfies? Welcome (MoreSimpleWrapper. (Example.))))
;;=>true
(println  (s/validate (s/protocol Welcome) (MoreSimpleWrapper. (Example.))))
;;=>#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}

(s/with-fn-validation
(println (satisfies? Welcome (MoreSimpleWrapper. (Example.))))
;;=>true
(println  (s/validate (s/protocol Welcome) (MoreSimpleWrapper. (Example.))))
;;=>#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}
)

(s/with-fn-validation
(greetings+ (MoreSimpleWrapper. (Example.))))
;;=>CompilerException clojure.lang.ExceptionInfo: Input to greetings+ does not match schema: [(named (not (satisfies? Welcome a-wrapper.issue.MoreSimpleWrapper)) component)] {:schema [#schema.core.One{:schema (protocol Welcome), :optional? false, :name component}], :value [#wrapper.issue.MoreSimpleWrapper{:e #wrapper.issue.Example{}}], :error [(named (not (satisfies? Welcome a-wrapper.issue.MoreSimpleWrapper)) component)]}, compiling:(/Users/tangrammer/git/olney/wrapper/src/wrapper/issue.clj:39:69)

Hier auch ein Kern mit der Code

Antworten:

0 für die Antwort № 1

Es war ein Schemafehler :)

jetzt behoben in Momentaufnahme-0.3.2

https://github.com/Prismatic/schema/issues/164