Skip to content

more useful generators #8

@eval

Description

@eval

Currently selecting is helpful to create tailored schemas:

(ms/select Person ^:only [:name :age {:country [:iso]}])

But when used to generate data you often may want to set the properties of some attributes to make it an actually helpful generator for the test/context you'r working on.
So:

;; we'd want to turn this...
[:map [:name string?] [:age pos-int?] :country [:map [:iso string?]]]

;; ...into this:
[:map 
  [:name {:gen/return "Gert"} string?]
  [:age [:int {:min 18 :max 50}]]
  [:country
    [:map 
      [:iso {:gen/elements ["NL" "DK"]} string?]]]]

Sketching:

(-> Person
  (ms/select ^:only [:name :age {:country [:iso]}])
  (ms/merge-in-properties [:name] {:gen/return "Gert"})
  (ms/merge-in-properties [:age] {:min 18 :max 50})
  (ms/merge-in-properties [:country iso] {:gen/elements ["NL" "DK"]})
  (mg/generate)) ;; => {:name "Gert" :age 21 :country "DK"}

or even:

(-> Person
  (ms/select ^:only [:name :age {:country [:iso]}])
  (ms/merge-in-properties [[:name {:gen/return "Gert"}]
                           [:age {:min 18 :max 50}]
                           [:country [:iso {:gen/elements ["NL" "DK"]}]]])
  (mg/generate)) ;; => {:name "Gert" :age 21 :country "DK"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions