Fork me on GitHub
#reitit
<
2019-09-06
>
Alexsandro Soares00:09:15

I'm trying to create two endpoints for my API: /users/ -> listing all users and /users/2 -> listing the user with id=2. I did the routes like posted before. This worked for me, but I can't test both endpoins using Swagger UI. What's the correct way to do this?

ikitommi05:09:40

@rlander there is no separation of key or value either in Schema or Spec, so I don’t think there is an easy way. With schema, you can create a custom coercion-matcher, that effects maps, and transforms the keys.

ikitommi05:09:11

there are sample in schema-tools how to create matchers that effect maps, e.g. the one that strips away extra keys not part of the Schema: https://github.com/metosin/schema-tools/blob/master/src/schema_tools/coerce.cljc#L46-L65

ikitommi05:09:57

the matchers in Schema don’t compose that easily, there are helpers for this in schema-tools, including multi-matcher, or-matchers and forwarding-matcher.

ikitommi05:09:34

Another way is to add a custom mw/interceptor that does transforms the bodies before & after validation.

rlander18:09:28

Thanks for the response, thats the aproach I ended up taking for my use case: add a middleware that transforms the bodies before and after and a "derived schema" that is just the Schema + a case transformation.

ikitommi05:09:37

but, no easy way, but a valid case and asked a lot. Added a issue to malli to make it easy with it. https://github.com/metosin/malli/issues/58

rlander18:09:54

That would pretty much solve the issue for us, had we been using malli instead of schema 😃 We're planning on doing that sooner rather than later

ikitommi05:09:11

welcome @prof.asoares. Why can’t you test those via swagger-ui?

stathissideris11:09:44

hello, do people use reitit instead of secretary?

Alexsandro Soares11:09:14

Hi, when I tried to use the swagger-ui I couldn't see the endpoint to list all users. But, I can see the two others endpoints.

y.khmelevskii13:09:11

Hi gents! I’m trying to add cors interceptor to my router config and I have some problems. My interceptor

(defn cors-interceptor []
  {:name ::cors
   :enter
   (fn [context]
     (assoc context :request
               (io.pedestal.http.cors/allow-origin {:creds true :allowed-origins some?})))})
then I added this interceptor https://github.com/khmelevskii/duct-pedestal-reitit/blob/master/src/duct_pedestal_reitit/router.clj#L12 but it doesn’t work. Can you help me to understand what I’m doing wrong?

y.khmelevskii13:09:23

I need it because in prod build I have a problem with cors for swagger js files https://www.dropbox.com/s/w4fhyp0inxv02kt/Screenshot%202019-09-06%2016.06.54.png?dl=0

Alexsandro Soares16:09:47

I solved my problem using this code. Thanks anyway.

4
ikitommi16:09:55

@y.khmelevskii there is a CORS interceptor in the Issue comment to be bundle in reitit-interceptors at https://github.com/metosin/reitit/issues/236

y.khmelevskii19:09:57

thank you @ikitommi for the link. I saw it. But currently I can’t see this PR in reitit and I’m not sure how long I need to wait it. Thats why I’m going to use another way but I’m not sure how I can do it