Fork me on GitHub
#clojure-spec
<
2020-08-25
>
stuartrexking05:08:48

Is it possible to add a req-un to an existing s/def to create a new s/def. I have a request map with a number of keys, and a response map with all the keys in the request, plus an additional id key. Is there a nice way to do this?

seancorfield05:08:45

@stuartrexking you can use s/merge to merge two s/keys specs together.

seancorfield05:08:26

(s/merge ::my-spec (s/keys :req-un [::some-new-key]))

jacklombard10:08:50

Is there a way to get the results of s/valid? and s/expalin-str in one call?

sogaiu10:08:49

you don't mean like by using juxt or something right?

jacklombard10:08:09

Nope, want spec itself to return it

jacklombard10:08:33

so that I can destructure say the validity and the error in the same call

jacklombard11:08:02

I am using spec for api validation where I check whether the body or the params are valid, if not I return 400 with error message as s/explain-str against the same spec. Of course the error message is not humanized, but we can deal with it. Don’t want spec to run its validation twice since payloads can be huge

alexmiller12:08:59

You could run s/explain-data, check that, then run the function to produce the string from the data