Open patapizza opened 8 years ago
I'm not sure exactly what you're trying to do, but the last argument of extend-schema
should be a map from key to value, and A
isn't that.
(sam/extend-schema BB B ["bar"] {:a A})
or similar should work, I think -- is that what you're looking for?
Thanks for your response.
I would like to reuse an abstract map schema as extension of another abstract map schema. Consider the use case where I categorize animals by name (cat), and cat features by color (black, white).
(s/defschema CatFeatures
(sam/abstract-map-schema :color {}))
(sam/extend-schema BlackCatFeatures CatFeatures ["black"] {})
(sam/extend-schema WhiteCatFeatures CatFeatures ["white"] {})
(s/defschema Animal
(sam/abstract-map-schema :name {}))
(sam/extend-schema Cat Animal ["cat"] CatFeatures)
(s/checker {:x Animal})
Is there a way to achieve this, without duplicating schemas?
Thanks for the explanation. That's unfortunately not possible currently -- the last argument to extend-schema
has to be an ordinary map schema. I think it should be straightforward to build a variant of abstract-map-schema
that does what you want, however.
It seems like I can't nest abstract map schemas.
Eval'ing
yields
Replacing
A
byAA
in theBB
extension yields a similar exception, this time withclojure.lang.Symbol
.