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?
@stuartrexking you can use s/merge
to merge two s/keys
specs together.
(s/merge ::my-spec (s/keys :req-un [::some-new-key]))
@seancorfield Thank you.
Is there a way to get the results of s/valid? and s/expalin-str in one call?
you don't mean like by using juxt
or something right?
Nope, want spec itself to return it
so that I can destructure say the validity and the error in the same call
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
You could run s/explain-data, check that, then run the function to produce the string from the data