clojure-spec

Lycheese 2022-11-12T19:48:32.791469Z

I use spec to validate a deeply nested map that is built in a cljs frontend and then sent to the backend. While working in the frontend it is regularly saved to localStorage and loaded on page reload. I want to validate that the localStorage version is valid before loading it, but the rules for its validity are not the same as when sending it to the backend since it can still be incomplete. The only way I was able to think of on how to accomplish this is by grouping all "finished version-only" predicates with a s/and on the top-level key used to validate the map and having a second top-level "temp state" key without those predicates and only structural verification. Is there a more elegant way? Like passing a parameter to the validation which makes some nested specs optional?

practicalli-johnny 2022-11-25T06:49:03.297649Z

I'd probably have two separate composite spec definitions, one for the front end and one for the back. I assume this would require only adding one more spec definition to describe the front end optional keys, as it's composed from oher existing spec definitions