This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-03
Channels
- # babashka (16)
- # beginners (70)
- # biff (1)
- # calva (15)
- # clj-commons (1)
- # cljsrn (1)
- # clojure (31)
- # clojure-android (1)
- # clojure-nl (4)
- # clojure-spec (17)
- # clojurescript (6)
- # cursive (3)
- # fulcro (22)
- # holy-lambda (21)
- # honeysql (20)
- # jobs-discuss (5)
- # kaocha (1)
- # lsp (51)
- # malli (1)
- # missionary (7)
- # nrepl (1)
- # off-topic (9)
- # portal (3)
- # reitit (1)
- # shadow-cljs (4)
- # xtdb (2)
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.