Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coercing issues #145

Closed
nenadalm opened this issue Nov 10, 2018 · 3 comments
Closed

Coercing issues #145

nenadalm opened this issue Nov 10, 2018 · 3 comments

Comments

@nenadalm
Copy link
Contributor

Hi. I am playing with reitit and since it started using coerce instead of conform my handler stopped working: https://github.com/nenadalm/spa-demo/blob/6ead886d34c263cc8c459f7ec8746f853c27c129/server/src/app/routes/user/handler.cljs#L44.

related change in reitit: metosin/reitit@cb14cf0#diff-b5391373d6c546daf15d41bb3a9368d2R125

I found that some assertion fails Assert failed: missing spec predicate spec. It fails in both clojure and clojurescript.

Here is code with which it can be reproduced:

(ns app.core
  (:require
   [clojure.spec.alpha :as s]
   [spec-tools.core :as st]))

(s/def :resource.user/id int?)
(s/def :resource/user (s/keys :req-un [:resource.user/id]))

(s/def :response.user/data :resource/user)
(s/def :response/user (s/keys :req-un [:response.user/data]))

(def no-op-transformer
  (reify
    st/Transformer
    (-name [_] ::no-op)
    (-encoder [_ _ _])
    (-decoder [_ _ _])))

(def spec (st/create-spec {:spec :response/user}))
(def value {:data {:id 41, :type "user", :attributes {:name "string"}}})
(def transformer no-op-transformer)

(comment
  ;; this works
  (st/conform spec value transformer)

  ;; Unhandled java.lang.AssertionError
  ;; Assert failed: missing spec predicate spec
  (st/coerce spec value transformer)
  )

project.clj

(defproject app "0.0.1-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [metosin/spec-tools "0.8.1"]
                 [org.clojure/clojurescript "1.10.439"]
                 [org.clojure/test.check "0.10.0-alpha2"]]
  :profiles {:dev
             {:dependencies [[com.bhauman/figwheel-main "0.1.9"]]}})
@ikitommi
Copy link
Member

[metosin/spec-tools "0.8.2"] should have this fixed via e6041cb.

@ikitommi
Copy link
Member

If this fixes the problem, I'll push out a new patch for reitit too.

@nenadalm
Copy link
Contributor Author

thanks. that fixes the problem with reitit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants