metosin / malli

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

Valid schema when eval'd in repl, but `malli.core/invalid-schema` on boot. #903

Open jteneycke opened 1 year ago

jteneycke commented 1 year ago

I have a schema:

(def File-schema
  [:map {
         :decode/multipart
         {
          :enter (fn [x]
                   (generic-coerce-multipart-file x))
          :leave (fn [x]
                   (generic-process-file (:client-assets-dir config) x))
          }
         }
   [:file/uuid {:optional true} [:maybe uuid?]]
   [:file/name string?]
   [:file/uri  uri?]
   [:file/type {:optional true} string?]
   [:file/size int?]
   [:file/date inst?]
   ])

And I want to merge some keys and properties in to make another one:

(def Slideshow-File-schema
    (let [new-keys (m/schema [:map
                              [:file/renders {:optional true} [:vector [:map [:file/uri uri?]]]]
                              [:file/errors {:optional true} string?]
                              ])]
      (-> File-schema
          (mu/merge new-keys)
          (mu/update-properties
            assoc-in
            [:decode/multipart :leave]
            (fn
              [x]
              (process-slideshow-file
                (generic-process-file (:client-assets-dir config) x))))
          )))

So that it generates a schema that looks like this with my overrides and additions:

(def Slideshow-File-schema
  [:map {
         :decode/multipart
         {
          :enter (fn [x]
                   (generic-coerce-multipart-file x))
          :leave (fn [x]
                   (process-slideshow-file
                     (generic-process-file (:client-assets-dir config) x))) ;; my override
          }
         }
   [:file/uuid {:optional true} [:maybe uuid?]]
   [:file/name string?]
   [:file/uri  uri?]
   [:file/type {:optional true} string?]
   [:file/size int?]
   [:file/date inst?]
   [:file/renders {:optional true} [:vector [:map [:file/uri uri?]]]]   ;; appended key/value
   [:file/errors {:optional true} string?]                              ;; appended key/value
   ])

It produces the schema I want when I'm evaling it in cider, and verifying the shape with mu/to-map-syntax and the app is running. But when I restart my app, I get these errors and they prevent it from compiling/starting:

Exception in thread "main" Syntax error macroexpanding at (util.clj:426:5). :malli.core/invalid-schema

Caused by: clojure.lang.ExceptionInfo: :malli.core/invalid-schema {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema :map}}