Skip to content
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

Sort the map schema elements before creating generator #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/schema_generators/generators.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@

(defn elements-generator [elts params]
(->> elts
;; move schema keys to the front for map generators, so they
;; don't override the specific keys; this is probably still
;; wrong when optional keys are present
(map-indexed (fn [idx elt]
[idx elt]))
(sort-by (fn [[idx elt]]
(if (and (vector? elt)
(= :schema.spec.collection/remaining (first elt)))
[0 idx]
[1 idx])))
(map second)
(map #(element-generator % params))
(apply generators/tuple)
(generators/fmap (partial apply concat))))
Expand All @@ -72,8 +83,6 @@
(generators/such-that g (sub-generator o params))
(sub-generator o params))))))

;; TODO: this does not currently capture proper semantics of maps with
;; both specific keys and key schemas that can override them.
schema.spec.collection.CollectionSpec
(composite-generator [s params]
(generators/such-that
Expand Down