metosin/reitit

Single item lists in query params with spec coercion

Open

#298 ouverte le 26 juin 2019

Voir sur GitHub
 (8 commentaires) (10 réactions) (0 assignés)Clojure (261 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (1 569 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

When defining a route with an array value in the query params like so:

{:get {:parameters {:query {:strings [string?]}}
           :handler (fn [{{:keys [query]} :parameters}]
                            {:status 200
                             :body query})}}

the query string is expected to look something like ?strings=hello&strings=world. However when only one is sent the query string will be ?strings=hello. Causing reitit to spit out

{
  "spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$367119/strings]), :type :map, :leaf? false})",
  "problems": [
    {
      "path": [
        "strings"
      ],
      "pred": "clojure.core/coll?",
      "val": "hello",
      "via": [
        "spec$367119/strings"
      ],
      "in": [
        "strings"
      ]
    }
  ],
  "type": "reitit.coercion/request-coercion",
  "coercion": "spec",
  "value": {
    "strings": "hello"
  },
  "in": [
    "request",
    "query-params"
  ]
}

Maybe reitit should be able to coerce ?strings=hello to ["hello"] if the spec is (coll-of string?)?

Guide contributeur