I'm attempting to rewrite our validation using spec and am running into some 
trouble with naming of nested entities.

Our system processes bills, and we require different fields depending on the 
context. So, for instance, in data-entry-form-1 say we require

```
(s/def :form/data-entry-form-1
  (s/keys :req [:bill/account
                :bill/carrier
                :freight-bill/billed-charges]))
```

where :freight-bill/billed-charges is a nested entity,

```
(s/def :freight-bill/billed-charges
  (s/keys :req [:charge-group/total-charges]))
```

The complication is that billed charges has a different set of required keys on 
data-entry-form-2,

```
(s/def :freight-bill/billed-charges
  (s/keys :req [:charge-group/total-charges
                :charge-group/total-pieces]))
```


It's easy enough to create a specification per form, each with a different set 
of required keys.  It seems unreasonable, however, to create a new spec per 
form per nested entity. Not only would the number of specs grow quickly, but it 
seems strange to create name variations for the same entity, e.g. 
`:de1.freight-bill/billed-charges`.  


I see two solutions as things stand. One approach is to specify everything with 
optional keys, and create separate code for checking required fields. Another 
is to use multispecs, however this approach becomes too complex for my taste, 
as it would require walking nested entities to decorate them with a dispatch 
key like {:type :data-entry-1-form ...} etc.


Ideally, we would be able to specify keys and required key paths separately.

-Tyler

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to