Fork me on GitHub
#reitit
<
2019-01-24
>
kanwei18:01:40

now trying to add :parameters and :response to routes, but the generated spec json doesn't include parameters and response.

kanwei18:01:57

(def nested-routes
  [["/search_by_company_name"
    {
     :get {:summary     "XXXXXXX"
           :description "XXXXXXX"
           :parameters  {:query {:company_name string?}}
           :responses   {200 {:body {:total int?}}}
           :handler     (fn [req]

ikitommi18:01:11

do you have :coercion defined?

kanwei18:01:25

yeah

{:coercion   reitit.coercion.spec/coercion
     :middleware [parameters/parameters-middleware
                  ;; coercing response bodys
                  coercion/coerce-response-middleware
                  ;; coercing request parameters
                  coercion/coerce-request-middleware
                  ]}

kanwei18:01:10

do I need more? I already have muuntaja on a higher-up middleware

ikitommi18:01:36

that should be all you need.

kanwei18:01:37

tried to read the source but it was hard to see where the parameters are added

kanwei18:01:34

so summary/description work but not params

ikitommi18:01:53

where have you defined the coercion? In top level route data?

kanwei18:01:14

(def search-routes
  (reitit/router
    [["/api/v2" nested-routes]
     ["/api/vtest/swagger.json"
      {:get {:no-doc  true
             :swagger {:info {:version     "2.0"}
             :handler (swagger/create-swagger-handler)
             }}]]
    {:coercion   reitit.coercion.spec/coercion
     :middleware [parameters/parameters-middleware
                  ;; coercing response bodys
                  coercion/coerce-response-middleware
                  ;; coercing request parameters
                  coercion/coerce-request-middleware
                  ]})

  )

ikitommi18:01:12

You should have the :coercion and :middleware under a :data in the router options

ikitommi18:01:46

everything under :data gets merged into endpoints

ikitommi18:01:29

need to support closed specs so that there would be warning about misplaced keys,...

kanwei18:01:30

aww yeah, totally works now

๐Ÿ‘ 1
kanwei18:01:43

yeah a warning would be nice ๐Ÿ˜‰

kanwei19:01:08

i like everything much better than compojure-api - thanks for all the hard work

kanwei19:01:23

(i know you also did compojure-api ๐Ÿ™‚ )

ikitommi19:01:22

thanks! We like it too ;)

kanwei20:01:34

is there a way to order the generated swagger endpoints? it seems to be random using reitit

kanwei20:01:50

whereas compojure-api was ordered based on the position in the file

ikitommi20:01:22

@kanwei there is no sorting on the server-side, do you think there should be? for swagger-ui, you can sort the endpoints using ui-options.

ikitommi20:01:43

(swagger-ui/create-swagger-ui-handler
  {:path "/"
   :config {:validatorUrl nil
            :operationsSorter "alpha"}})