metosin / malli

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

`:?` vs `:sequential` in JSON Schema transformers #793

Open NoahTheDuke opened 1 year ago

NoahTheDuke commented 1 year ago

Hey friends, I've found a small difference between [:sequential {:max 1} schema] and [:? schema] when transformed with malli.json-schema:

(m.js/transform
  (m/schema
    [:map {:closed true}
     [:data [:?
             [:map {:closed true}
              [:id :int]
              [:description [:maybe :string]]
              [:name :string]]]]]))
; {:type "object",
;  :properties {:data {}},
;  :required [:data],
;  :additionalProperties false}
(m.js/transform
  (m/schema
    [:map {:closed true}
     [:data [:sequential {:max 1}
             [:map {:closed true}
              [:id :int]
              [:description [:maybe :string]]
              [:name :string]]]]]))
; {:type "object",
;  :properties
;  {:data
;   {:type "array",
;    :items
;    {:type "object",
;     :properties
;     {:id {:type "integer"},
;      :description {:oneOf [{:type "string"} {:type "null"}]},
;      :name {:type "string"}},
;     :required [:id :description :name],
;     :additionalProperties false},
;    :maxItems 1}},
;  :required [:data],
;  :additionalProperties false}

Is this intentional? If not, I can dig in to try to fix it.