clojure-spec

kpav 2022-10-18T20:11:25.139799Z

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

kpav 2022-10-18T20:19:12.640979Z

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

kpav 2022-10-18T20:30:50.779309Z

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

kpav 2022-10-18T20:32:00.003829Z

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