metosin / compojure-api

Sweet web apis with Compojure & Swagger
http://metosin.github.io/compojure-api/doc/
Eclipse Public License 1.0
1.11k stars 149 forks source link

spec coercion to int #446

Open jeroenvanwijgerden opened 4 years ago

jeroenvanwijgerden commented 4 years ago

Library Version(s)

2.0.0-alpha31

Problem

(s/def ::version (s/and int? #{1 2}))

(GET "/test/:v" request
      :path-params [v :- ::version]
      (r/ok v))

when requesting GET /test/1 results in

{:problems
    [{:message "Validation error",
      :details
      {:path ["v"],
       :pred [1 2],
       :val "1",
       :via ["spec$60151/v"],
       :in ["v"],
       :phrase.alpha/mappings {:x0 1, :x1 2, :x2 ["x1" "x0"]},
       :phrase.alpha/via []}}]}

However

(s/def ::version #{1 2})

(GET "/test/:v" request
      :path-params [v :- (s/and int? ::version)]
      (r/ok v))

when requesting GET /test/1 does give me the expected response body of 1.

thomaswhitcomb commented 3 years ago

@jeroenvanwijgerden what is the "s" namespace?