Fork me on GitHub
#malli
<
2023-11-22
>
Alex Sky14:11:11

Hello! First of all, thank you for malli. It's beautiful. So, my question is as follows How properly show in swagger-ui structure like a :multi or :or For example

[:multi {:dispatch :type}
   [:sized [:map [:type keyword?] [:size int?]]]
   [:human [:map [:type keyword?] [:name string?] [:address [:map [:country keyword?]]]]]]
(defmethod accept :multi [_ _ children _] (let [cs (mapv last children)] (assoc (first cs) :x-anyOf cs)))
As I understand it, here we take only the first part and the rest is not visible in swagger-ui. i.e. in the model in swagger-ui I will see only :sized I'd appreciate any ideas or maybe is it ok for swagger?) UPD someone is using swagger-ui ? and has used anyOf ?

dergutemoritz09:11:07

I don't think :multi can be fully represented in swagger since the dispatch function can be any function. In our project we therefore introduced a custom :multi-map which specializes for a :type-key dispatch style multi schema whose children all have to be :map or :multi-map. This allows for representing it in less expressive formats (TypeScript declarations in our case - I don't know if swagger / open-api has support for this).

👍 1
dergutemoritz09:11:31

As for :or I would assume that swagger should support this :thinking_face:

Alex Sky10:11:04

thanks for the reply. Yes it looks like there are no simple solutions 🙂

ikitommi11:11:32

OpenAPI supports discriminator, which should help here if the :dispatch uses a key, see https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

ikitommi11:11:03

maybe we should support also functions when doing transformations to xyz from malli? so, instead of:

[:multi {:openapi {:type ....}}] 
we could have:
[:multi {:openapi (fn [schema options] ...transform here...)}] 
… that would allow easy in-place transformations.

👍 1
ikitommi11:11:30

but, PR welcome if the current :openapi doesn’t properly use the discriminator!

👍 1
dergutemoritz12:11:20

Specal-casing keyword-based dispatch is a nice idea 👍

Alex Sky20:11:54

I guess I'm just on an older version.

Alex Sky20:11:42

migrated to the new version now everything is fine. Problem solved.