|
277 | 277 | (defn ^:private normalize-fields |
278 | 278 | "Converts a deep nested map where keys are strings to keywords. |
279 | 279 | normalization-rules follow the nest order, :ANY means any field name. |
280 | | - :kebab-case means convert field names to kebab-case. |
281 | | - :stringfy means convert field names to strings." |
| 280 | + :kebab-case-key means convert field names to kebab-case. |
| 281 | + :stringfy-key means convert field names to strings." |
282 | 282 | [normalization-rules m] |
283 | | - (let [kc-paths (set (:kebab-case normalization-rules)) |
284 | | - str-paths (set (:stringfy normalization-rules)) |
285 | | - ; match a current path against a rule path with :ANY wildcard |
| 283 | + (let [kc-paths (set (:kebab-case-key normalization-rules)) |
| 284 | + str-paths (set (:stringfy-key normalization-rules)) |
| 285 | + keywordize-paths (set (:keywordize-val normalization-rules)) |
| 286 | + ; match a current path against a rule path with :ANY wildcard |
286 | 287 | matches-path? (fn [rule-path cur-path] |
287 | 288 | (and (= (count rule-path) (count cur-path)) |
288 | 289 | (every? true? |
|
295 | 296 | normalize-map (fn normalize-map [cur-path m*] |
296 | 297 | (cond |
297 | 298 | (map? m*) |
298 | | - (let [apply-kebab? (applies? kc-paths cur-path) |
299 | | - apply-string? (applies? str-paths cur-path)] |
| 299 | + (let [apply-kebab-key? (applies? kc-paths cur-path) |
| 300 | + apply-string-key? (applies? str-paths cur-path) |
| 301 | + apply-keywordize-val? (applies? keywordize-paths cur-path) |
| 302 | + ] |
300 | 303 | (into {} |
301 | 304 | (map (fn [[k v]] |
302 | 305 | (let [base-name (cond |
303 | 306 | (keyword? k) (name k) |
304 | 307 | (string? k) k |
305 | 308 | :else (str k)) |
306 | | - kebabed (if apply-kebab? |
| 309 | + kebabed (if apply-kebab-key? |
307 | 310 | (csk/->kebab-case base-name) |
308 | 311 | base-name) |
309 | | - new-k (if apply-string? |
| 312 | + new-k (if apply-string-key? |
310 | 313 | kebabed |
311 | 314 | (keyword kebabed)) |
312 | | - new-v (normalize-map (conj cur-path new-k) v)] |
| 315 | + new-v (if apply-keywordize-val? |
| 316 | + (keyword v) |
| 317 | + v) |
| 318 | + new-v (normalize-map (conj cur-path new-k) new-v)] |
313 | 319 | [new-k new-v]))) |
314 | 320 | m*)) |
315 | 321 |
|
|
320 | 326 | (normalize-map [] m))) |
321 | 327 |
|
322 | 328 | (def ^:private normalization-rules |
323 | | - {:kebab-case |
| 329 | + {:kebab-case-key |
324 | 330 | [[:providers]] |
325 | | - :stringfy |
| 331 | + :keywordize-val |
| 332 | + [[:providers :ANY :httpClient]] |
| 333 | + :stringfy-key |
326 | 334 | [[:behavior] |
327 | 335 | [:providers] |
328 | 336 | [:providers :ANY :models] |
|
0 commit comments