-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feed :set
into generator
#3
Comments
Sorry but I don't understand what you're suggesting. Would you be able to provide more context perhaps? |
Absolutely. With clojure.spec you can provide an override directly into the generator, the benefit of that is that if you have dependent keys within the map then the generator will factor that in, otherwise you can unintentionally produce invalid data. (s/def :event/type keyword?)
(s/def :event/query string?)
(s/def :event/message string?)
(defmulti event-type :event/type)
(defmethod event-type :search [_] (s/keys :req [:event/type :event/query]))
(defmethod event-type :error [_] (s/keys :req [:event/type :event/message]))
(s/def :event/event (s/multi-spec event-type :event/type))
;; What I'd like data potato to do:
(gen/generate (s/gen :event/event {:event/type #(gen/return :error)})) ;;=> #:event{:type :event/error, :message "24zPSp"}
;; What data potato effectively does, but this creates an invalid event (it was a search that datapotato "changed")!
(merge (gen/generate (s/gen :event/event)) {:event/type :error}) ;; => #:event{:type :error, :query "F160GJ9nab4F24"} So the |
This is a good idea, but I am unfamiliar with malli. Does that support the same feature? If not, then this would lead to a diversion of the implenentations. |
Indirectly, yes. You'd use something like |
Hi, just playing around with this and our clojure spec generators.
It would be handy if
:set
could somehow be fed into the generator so I could do:(s/gen schema {[...] #(gen/return ...)})
for any overrides provided. This would allow generating off a multi-spec without needing a whole separate schema per multi-spec type(s).e.g. I could do
{:count 1 :set {:color :red}}
and it would only generate things which must be red.The text was updated successfully, but these errors were encountered: