clojure-spec 2022-10-18

Is there a way to generate only required or optional keys?

e,g, Given this spec:

(s/def ::required-key string?)
  (s/def ::optional-key string?)
  (s/def ::foo (s/keys :req [::required-key]
                       :opt [::optional-key]))
I'd like a way to force generation of:
{:required-key "foo"}
And also:
{:required-key "foo"
   :optional-key "bar"}

Alex Miller (Clojure team) 2022-10-18T20:29:32.440979Z

the latter should be what you get by default - required and sometimes optional

Alex Miller (Clojure team) 2022-10-18T20:29:43.530709Z

you could filter with fmap to get the former

This is assuming I am given an unknown spec. Basically, I'd like to know which keys are required, and which keys are optional

Alex Miller (Clojure team) 2022-10-18T20:31:35.242859Z

there are some 3rd party libraries that have functions to parse that from the spec form

ah ok thanks! I'll take a look into those