Fork me on GitHub
#malli
<
2021-10-03
>
andre.richards12:10:35

Edit: I implemented below by overriding malli.json-schema/-schema. In there I can control whether to return the ref (and add it to definitions) or return the deref of the attribute schema. Is there a way to 'deref' [:map] children when transforming a schema to Swagger? We use 'decomplected' map attributes, e.g.:

(def registry
    (merge
      (m/default-schemas)
      {:customer/id   :uuid
       :customer/name :string
       :Customer      [:map
                       [:customer/id]
                       [:customer/name]}))

(transform :Customer {:registry registry})
Results in:
{:type        "object",
 :properties  {:customer/id   {:$ref "#/definitions/:customer/id"},
               :customer/name {:$ref "#/definitions/:customer/name"}},
 :required    [:customer/id :customer/name],
 :definitions {:customer/id {:type "string", :format "uuid"}, 
               :customer/name {:type "string"}}}
Apart from the fact that this gives an error in Swagger (the extra forward slash after customer in $ref value), we would really like to get Swagger that looks like this (i.e. without a definition for each attribute):
{:type       "object",
 :properties {:customer/id {:type "string", :format "uuid"}, 
              :customer/name {:type "string"}},
 :required   [:customer/id :customer/name]}
We re-use the attributes in multiple schemas, and really like the fact that we don't have to re-define the attribute schema every time we use it (which is the point of decomplected attributes), and this is working as expected for all the core Malli operations like validate. We considered calling m/deref-all on the :Customer schema, but [:map] does not deref its children, so this does not help.