Fork me on GitHub
#ring-swagger
<
2020-02-05
>
antonmos18:02:35

@ikitommi i tried to use st/spec instead of s/conform

(s/def ::user-ids
  (st/spec
    {:spec (s/coll-of ::corespec/user-id)
     :description "comma separated list of user-ids"
     :json-schema/type {:type "string"}
     :json-schema/example "1,2,3"
     :decode/string #(cs/split %2 #",")
     :encode/string #(cs/join %2 ",")}))

(st/coerce ::user-ids "1,2" st/string-transformer)
=> [1 2]
but compojure-api doesnt seem to be coercing….
(context "/v1" []
    :coercion :spec
    (GET "/events" []
      :coercion :spec
      :query-params [user-ids :- ::user-ids]
      (println "foo" (pr-str {} user-ids 30)))))
GET /v1/events?user-ids=4723 HTTP/1.1
{
    "spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$584/user-ids]), :type :map, :leaf? false})",
    "problems": [
        {
            "path": [
                "user-ids"
            ],
            "pred": "clojure.core/coll?",
            "val": "4723",
            "via": [
                "spec$584/user-ids"
            ],
            "in": [
                "user-ids"
            ]
        }
    ],
    "type": "compojure.api.exception/request-validation",
    "coercion": "spec",
    "value": {
        "user-ids": "4723"
    },
    "in": [
        "request",
        "query-params"
    ]
}
am i doing something wrong or is this not supported?