Fork me on GitHub
#malli
<
2020-04-13
>
ikitommi07:04:03

maybe :swagger/discriminator :type?

ikitommi07:04:11

haven’t used the discriminator, so not sure how it should work. what is the expected swagger schema?

sudakatux10:04:02

so i would expect i could "type":"mytype"

sudakatux10:04:18

So my probelm was that i could not POST since it could not figure out the type

sudakatux10:04:42

the way i got what i wanted was by doing this

sudakatux10:04:16

(m/validate schema (m/decode
    schema data
    (mt/transformer mt/strip-extra-keys-transformer mt/string-transformer)))))

sudakatux10:04:25

where schema is

sudakatux10:04:56

[:multi
 {:dispatch :type, :decode/string (fn* [p1__40150#] (update p1__40150# :type keyword))}
 [:other [:map [:data [:map [:nombre string?] [:apellido string?] [:edad int?]]] [:type [:= :other]]]]
 [:one [:map [:data [:map [:nombre string?] [:apellido string?] [:kk int?]]] [:type [:= :one]]]]]

sudakatux10:04:00

{:data {:nombre "nombre" :apellido "apellido" :edad 12} :type "other"}

sudakatux10:04:27

on an ideal I would have liked to be able to use that schema in the {:paremeters {:body here}}

plexus13:04:16

am I right that this is not supported? should it be?

(def m [:map
          [:i {:error/message "not a number"} int?]])

  (me/humanize (m/explain m {:i "123"}))
  ;; => {:i ["should be int"]}

plexus13:04:53

I find in general there's some annoying asymmetry between properties on map entries vs properties schemas. See also my PR for adding :gen/gen / :gen/elements / :gen/fmap support to map entries

sudakatux13:04:44

sorry deleted the message by mistake

sudakatux13:04:48

will take a look

plexus13:04:36

thanks @U8JTE9PG8. I'm interested in general if users should expect props on schemas to also work on map entries, or if that's not a design goal.

ikitommi16:04:51

Thanks @U07FP7QJ0 for the PR! Will check it soon along others. I would like to have first class entry meta, not sure what is the best way for it.

plexus13:04:28

I suppose you can do this

(def m [:map
          [:i
           [int? {:error/message "not a number"}]]])