New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for OpenAPI3 #84

Open
ikitommi opened this Issue May 14, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@ikitommi
Member

ikitommi commented May 14, 2018

This spans over multiple repos, but can be done in parts.

Schema -> OpenAPI3

Spec -> OpenAPI3

  • metosin/schema-tools#44
  • should be easy, a new ns just like spec-tools.swagger overriding some JSON Schema parts (if any!)

Reitit Coercion

  • currently, there is only one body-coercion for request and one for response. We should add support for content-type based coercion:

Coercion for all content-types

(require '[reitit.ring :as ring])
(require '[reitit.ring.coercion])
(require '[reitit.coercion.spec])
(require '[muuntaja.middleware])

(ring/ring-handler
  (ring/router
    ["/plus"
     {:get {:parameters {:body {:x int?, :y int?}}
            :responses {200 {:body {:total pos-int?}}}
            :handler (fn [{{{:keys [x y]} :body} :parameters}]
                       {:status 200, :body (+ x y)})}}]
    {:data {:middleware [muuntaja.middleware/wrap-format
                         reitit.ring.coercion/coerce-request-middleware
                         reitit.ring.coercion/coerce-response-middleware]
            :coercion reitit.coercion.spec/coercion}}))

Coercion per content-type

  • new type :content (from OpenAPI3) which allows content-type->model mappings.
  • should be disallowed with Swagger
(ring/ring-handler
  (ring/router
    ["/plus"
     {:get {:parameters {:content {"application/json" {:x neg-int?, :y neg-int?}
                                   "application/edn" {:x pos-int?, :y pos-int?}}}
            :responses {200 {:content {"application/json" {:json int?}
                                       "application/edn" {:edn int?}}}}
            :handler (fn [{{{:keys [x y]} :body} :parameters :as request}]
                       (let [content-type (-> request :muuntaja/response :format)
                             body (case content-type
                                    "application/json" {:json (+ x y)}
                                    "application/edn" {:edn (+ x y)})]
                         {:status 200, :body body}))}}]
    {:data {:middleware [muuntaja.middleware/wrap-format
                         reitit.ring.coercion/coerce-request-middleware
                         reitit.ring.coercion/coerce-response-middleware]
            :coercion reitit.coercion.spec/coercion}}))

... having both :body and :content could be allowed, the :body could be used as a default if the content-type doesn't match.

@ikitommi

This comment has been minimized.

Member

ikitommi commented Jun 25, 2018

another option for the new key :content would be to reuse the :body key, but I think it would conflict with the string keys.

@valerauko

This comment has been minimized.

Contributor

valerauko commented Oct 17, 2018

There seem to be quite a lot of changes for OpenAPI 3.0. Would all of it need to be implemented here? https://swagger.io/blog/news/whats-new-in-openapi-3-0/

@ikitommi

This comment has been minimized.

Member

ikitommi commented Oct 20, 2018

I think the core change is for the content-negotiation & better json-schema mappings. The rest (security &) are anyway left for client apps / libs to do as there are no existing helpers in reitit for those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment