This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-19
Channels
- # aws-lambda (1)
- # beginners (35)
- # cider (7)
- # cljsjs (2)
- # clojure (48)
- # clojure-austria (1)
- # clojure-conj (9)
- # clojure-dev (8)
- # clojure-india (6)
- # clojure-italy (12)
- # clojure-nl (8)
- # clojure-norway (3)
- # clojure-spec (9)
- # clojure-uk (92)
- # clojurescript (103)
- # community-development (7)
- # cursive (15)
- # datomic (75)
- # devcards (3)
- # emacs (3)
- # events (1)
- # fulcro (129)
- # hoplon (4)
- # immutant (2)
- # jobs (10)
- # leiningen (9)
- # off-topic (4)
- # onyx (2)
- # re-frame (45)
- # reagent (39)
- # reitit (40)
- # remote-jobs (4)
- # ring (2)
- # ring-swagger (9)
- # shadow-cljs (17)
- # tools-deps (31)
@ikitommi in the end i wrote the swagger specs by hand. it'd be way too verbose in clojure spec
i found the description syntax in the official docs after quite a bit of searching: https://swagger.io/specification/#xmlObject
@vale you can return it if you write it manually, but yeah, there is a issue to support the schema/spec -> openapi3 conversion. Help welcome on that.
actually, the swagger-code always writes the Swagger2 header, so it might not work: https://github.com/metosin/reitit/blob/master/modules/reitit-swagger/src/reitit/swagger.cljc#L81
there are some blogs about the differences, basically the request bodys are per content-type + better support for json-schema (`any-of` & one-of
)
the coercion parameter model is currently modelled based on ring & swagger2, e.g. there is only one type of :body
per endpoint.
so to support openapi3, we should think if the coercion parameter model should change too. Today I think it shouldn't.
having and endpoint, which takes different body-formats (one per content-type) seems like an odd-case.
a protocol for looking up users etc, called webfinger. currently mostly used in distributed social media such as mastodon. this is how i modeled its lookup endpoint in openapi: https://pastebin.com/uBrv9UuU
actually, I might work as the merge is overwriting the defaults with your settings:
(->> (dissoc swagger :id)
(merge {:swagger "2.0"
:x-id ids}))
you have to update the ring-swagger-ui
to the latest so it works too, add this to dependencies [metosin/ring-swagger-ui "3.9.0"]
what if (in the future), there would be: reitit-openapi
module, with own coercion middleware/interceptors, where the :body
is read from under the content-type
key.
would it be very difficult to implement a conditional branch where openapi 3.0 features would be "detected" and used if present?
ok, actually if the only difference is the body parameters, the coercion middleware/interceptor could be shared.
["/api"
{:openapi {:id ::math, :version "3.0.1"}}
["/openapi.json"
{:get {:no-doc true
:openapi {:info {:title "my-api"}}
:handler (openapi/create-openapi-handler)}}]
["/spec"
{:coercion spec/coercion
:openapi {:tags ["spec"]}}
["/plus"
{:get {:summary "plus with spec query parameters"
:parameters {:query {:x int?, :y int?}}
:responses {200 {:body {:total int?}}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200
:body {:total (+ x y)}})}
:post {:summary "plus with spec body parameters"
:parameters {:body {"application/json" {:x int?, :y int?}
"application/xml"} {:x' int?, :y' int?}}
:responses {200 {"application/json" {:body {:total int?}}
"application/xml" {:body {:total' int?}}}}
:handler (fn [{{:keys [:muuntaja/format]}
{{:keys [x y x' y']} :body} :parameters}]
{:status 200
:body (case format
"application/json" {:total (+ x y)}
"application/xml" {:total' (+ x' y')})})}}]]]
so it'd be something like
:responses {200 {:body {"application/json" json-schema
"application/xml" xml-schema} }
500 {:body {"text/plain" "the world has ended"}}
i'd be happy to help implementing it if you can point me in the right direction (i'm not familiar with reitit or ring-swagger's source code)