metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 205 forks source link

separate the roles of -schema-schema #893

Open opqdonut opened 1 year ago

opqdonut commented 1 year ago

Currently, -schema-schema is used for 4 different things:

  1. A wrapper for a schema, potentially with props, like [:schema {:foo 1} :int]
  2. An invisible wrapper that doesn't have a m/form, but just outputs the form of the child:
    user=> (m/form (m/schema [:and {:registry {"Foo" :int}} "Foo"]))
    [:and {:registry {"Foo" :int}} "Foo"]
    user=> (m/ast (m/schema [:and {:registry {"Foo" :int}} "Foo"]))
    {:type :and, :children [{:type :malli.core/schema, :value "Foo"}], :registry {"Foo" {:type :int}}}
  3. A reference schema, like [:schema "Foo"]
    • a :schema reference is eager, unlike :ref which is lazy
  4. A sub-regex-schema, like [:cat :int [:schema [:cat :int :int]]]

To avoid weird corner cases like #884 and #851 in the future, we should add new schemas for use cases 3 and 4. We should also have a good look at use case 2 and see if the code for it is right (m/-pointer).

Ideally, -schema-schema would only be responsible for use case 1.

Based on a discussion with @ikitommi