bhb / expound

Human-optimized error messages for clojure.spec
Eclipse Public License 1.0
927 stars 24 forks source link

should contain keys: summary could be improved [0.7.2] #155

Closed hlship closed 4 years ago

hlship commented 5 years ago

The should contain keys summary of key specs for composites (via s/keys) could be better.

-- Spec failed --------------------

  {:tire-line-numbers [1 2 3 4],
   :store-id "5504",
   :last-modified-at "2019-04-04T17:02:26.000+0000",
   :start-time "10:00",
   :order-number "26698749828094",
   :end-time "10:30",
   :store-time-zone "PST",
   :reservation-id "3c59240d-4fc3-438a-8707-05091a02a93f",
   :booked-at "2019-04-20T10:00:00.000+0000",
   :installation-line-number 5,
   :delivery-at "2019-04-20T14:00:00.000+0000"}

should contain keys: :customer, :store-address

|            key |                                                                                            spec |
|----------------+-------------------------------------------------------------------------------------------------|
|      :customer |                                                        (keys :req-un [string? string? string?]) |
| :store-address | (keys :req-un [string? (and string? (fn [%] (re-matches #"\d{5}(-d{4})?" %))) string? string?]) |

-- Relevant specs -------

:eReceipts.query-service.order-service-proxy-client/add-tire-installation-item-details:
  (clojure.spec.alpha/keys
   :req-un
   [:eReceipts.query-service.order-service-proxy-client/order-number
    :eReceipts.query-service.order-service-proxy-client/last-modified-at
    :eReceipts.query-service.order-service-proxy-client/tire-line-numbers
    :eReceipts.query-service.order-service-proxy-client/installation-line-number
    :eReceipts.query-service.order-service-proxy-client/store-time-zone
    :eReceipts.query-service.order-service-proxy-client/store-id
    :eReceipts.query-service.order-service-proxy-client/store-address
    :eReceipts.query-service.order-service-proxy-client/booked-at
    :eReceipts.query-service.order-service-proxy-client/start-time
    :eReceipts.query-service.order-service-proxy-client/end-time
    :eReceipts.query-service.order-service-proxy-client/delivery-at
    :eReceipts.query-service.order-service-proxy-client/reservation-id
    :eReceipts.query-service.order-service-proxy-client/customer])

-------------------------
Detected 1 error

Given:

(s/def ::address (s/keys :req-un [::street-address
                                  ::postal-code
                                  ::state
                                  ::city]))

(s/def ::street-address string?)
(s/def ::postal-code (s/and string?
                            #(re-matches #"\d{5}(-d{4})?" %)))
(s/def ::state string?)
(s/def ::city string?)

(s/def ::store-address ::address)

I'd expect the table to reference those qualified spec names, rather than what they expand into.

bhb commented 5 years ago

@hlship Thanks for reporting this!

Can you provide an example of what you'd expect the table to contain?

bhb commented 5 years ago

Just to clarify, what's the spec for ::customer?

I think I see the problem - are you saying that the table should show the spec, but instead of:

| :store-address | (keys :req-un [string? (and string? (fn [%] (re-matches #"\d{5}(-d{4})?" %))) string? string?]) |

it should include something like this?

| :store-address | (s/keys :req-un [:eReceipts.query-service.order-service-proxy-client/street-address :eReceipts.query-service.order-service-proxy-client/postal-code :eReceipts.query-service.order-service-proxy-client/state :eReceipts.query-service.order-service-proxy-client/city]) |

bhb commented 4 years ago

@hlship Thanks for reporting this! The fix is included in version 0.8.0, which I've just released.