This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-14
Channels
- # announcements (3)
- # babashka-sci-dev (22)
- # beginners (6)
- # calva (36)
- # cljsrn (1)
- # clojure (59)
- # clojure-europe (31)
- # clojure-france (3)
- # clojure-gamedev (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-uk (4)
- # clojurescript (6)
- # conjure (1)
- # cursive (11)
- # data-oriented-programming (1)
- # datahike (2)
- # docker (8)
- # duct (4)
- # emacs (1)
- # figwheel-main (5)
- # kaocha (1)
- # leiningen (8)
- # lsp (64)
- # malli (10)
- # membrane (5)
- # nrepl (11)
- # off-topic (5)
- # portal (6)
- # quil (9)
- # reagent (62)
- # reitit (15)
- # releases (3)
- # ring-swagger (2)
- # shadow-cljs (36)
- # specter (2)
- # tools-deps (21)
Hello !
I'd like to generate swagger specs having "field descriptions" (i.e. a description that describes the field in its context, rather than a description in the scope of the standalone schema/type).
I've seen the OpenAPI Spec now supports fields (namely :description
) aside the :$ref
field, for the exact purpose of describing an instance / a role rather than describing a type.
Example of what I'd like to generate below :
{:definitions
{"some-item" {...}
"some-struct"
{:type "object",
:properties
{:primary-item {:$ref "#/definitions/some-item"
:description "Preferred item under all circumstances"},
:secondary-item {:$ref "#/definitions/some-item"
:description "Secondary item, because one never knows"}},
:additionalProperties false}}}
Is this feature supported in ring-swagger
yet ? I can't see how to do it (I'm using plumatic schema)Unfortunately, my attempts have been unsuccessful so far, see example below :
(s/defschema some-item
{:id s/Int})
(s/defschema some-struct
{:primary-item (-> some-item
(json-schema/describe "Preferred item under all circumstances"))
:secondary-item (-> some-item
(json-schema/describe "Secondary item, because one never knows"))})
(deftest descriptions-are-conflated
(let [swagger-spec
(select-keys (swagger/swagger-json
{:paths {"/test" {:get {:responses {200 {:schema some-struct}}}}}})
[:definitions])]
(is (= {:definitions
{"some-item"
{:description "Preferred item under all circumstances",
:type "object",
:properties {:id {:type "integer", :format "int64"}},
:additionalProperties false,
:required [:id]},
"some-struct"
{:type "object",
:properties
{:primary-item {:$ref "#/definitions/some-item"},
:secondary-item {:$ref "#/definitions/some-item"}},
:additionalProperties false,
:required [:primary-item :secondary-item]}}} swagger-spec))))