|
18 | 18 | negated message)))) |
19 | 19 |
|
20 | 20 | (let [prefix (str "-en-humanize-negation-" (random-uuid))] |
21 | | - (defn- -en-humanize-negation [{:keys [schema] :as error} options] |
22 | | - (let [remove-prefix #(str/replace-first % prefix "") |
23 | | - negated? #(str/starts-with? % prefix)] |
24 | | - (loop [schema schema] |
25 | | - (or (when-some [s (error-message (assoc error :negated #(some->> % (str prefix))) options)] |
26 | | - (if (negated? s) |
27 | | - (remove-prefix s) |
28 | | - (or (when (and (string? s) |
29 | | - (str/starts-with? s "should not ")) |
30 | | - (str/replace-first s "should not" "should")) |
31 | | - (when (and (string? s) |
32 | | - (str/starts-with? s "should ")) |
33 | | - (str/replace-first s "should" "should not"))))) |
34 | | - (let [dschema (m/deref schema)] |
35 | | - (when-not (identical? schema dschema) |
36 | | - (recur dschema)))))))) |
| 21 | + (defn- -en-humanize-negation [{:keys [schema negated] :as error} options] |
| 22 | + (if negated |
| 23 | + (negated (error-message (dissoc error :negated) options)) |
| 24 | + (let [remove-prefix #(str/replace-first % prefix "") |
| 25 | + negated? #(str/starts-with? % prefix)] |
| 26 | + (loop [schema schema] |
| 27 | + (or (when-some [s (error-message (assoc error :negated #(some->> % (str prefix))) options)] |
| 28 | + (if (negated? s) |
| 29 | + (remove-prefix s) |
| 30 | + (or (when (and (string? s) |
| 31 | + (str/starts-with? s "should not ")) |
| 32 | + (str/replace-first s "should not" "should")) |
| 33 | + (when (and (string? s) |
| 34 | + (str/starts-with? s "should ")) |
| 35 | + (str/replace-first s "should" "should not"))))) |
| 36 | + (let [dschema (m/deref schema)] |
| 37 | + (when-not (identical? schema dschema) |
| 38 | + (recur dschema))))))))) |
37 | 39 |
|
38 | 40 | (defn- -forward-negation [?schema {:keys [negated] :as error} options] |
39 | 41 | (let [schema (m/schema ?schema options)] |
|
0 commit comments