Open abcdw opened 1 year ago
Minimal repro:
(m/schema [:schema {:registry {:select-keys (mu/-select-keys)}} :int])
Root cause might be that m/schema
walks the local registries and tries to instantiate all IntoSchema
s. select-keys blows on invalid child count.
even more minimal:
;; :and requires 1+ children
(m/schema [:schema {:registry {::and (m/-and-schema)}} :int])
Not instantiating IntoSchema
s should have a positive effect on Schema creation.
The problem is that we can't not instantiate the registry. Otherwise we get errors like this:
FAIL in malli.core-test/validation-test (core_test.cljc:739)
schema schemas
Expected:
[:and
{:registry {:malli.core-test/a :malli.core-test/b,
:malli.core-test/b :malli.core-test/c,
:malli.core-test/c [:schema pos-int?]}}
[:and :malli.core-test/a :malli.core-test/b :malli.core-test/c]]
Actual:
[:and
{:registry {:malli.core-test/a :malli.core-test/b,
:malli.core-test/b :malli.core-test/c,
:malli.core-test/c [:schema -pos-int? +#<Fn@7b3c0ecb clojure.core/pos_int_QMARK_>]}}
[:and :malli.core-test/a :malli.core-test/b :malli.core-test/c]]
The problem here is that the registry is kind of meant for actual schemas, but something like (m/-and-schema)
isn't a schema, it's a higher-order-schema. A schema factory.
One hacky option would be to make (m/-and-schema)
(and friends) return something that is both an IntoSchema
and a Schema
with a suitable -form
method.
One more partial solution would be to make -form
fail with a nice error message when it encounters a :registry
it can't handle.
The problem here is that the registry is kind of meant for actual schemas, but something like (m/-and-schema) isn't a schema, it's a higher-order-schema. A schema factory.
Yes, I remember @ikitommi noting that IntoSchema's aren't serializable, which is a key requirement of schemas. (Therefore they shouldn't be in local registries).
As this popped up, re-collecting my thouhgts on this:
:gen/gen
having a generator as a value => this is ok:registry
to be serialisable doesn't make much sense, user should know what he/she is doing hereIs there a good reason not to support IntoSchema
s in the local registry?
This one works:
This one throws an error: