Skip to content

Commit

Permalink
Sort the map schema elements before creating generator
Browse files Browse the repository at this point in the history
This is a hacky fix for #16, preventing wildcard keys from overriding
specific keys.
  • Loading branch information
gfredericks committed Jun 4, 2019
1 parent 27e2cfa commit a25f615
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit a25f615

Please sign in to comment.