metosin / metosin/spec-tools

`st/strip-extra-keys-transformer` not handling merged `s/or`

Open
#271 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
606
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Similar to #178 and might be related to #264

When having a spec with merge of an or-spec, `st/strip-extra-keys-transformer` removes too many keys. However it seems to be an issue with parsing of the specs.
```clojure
(ns merged-or.test
(:require [clojure.spec.alpha :as s]
[spec-tools.core :as st]))

(s/def ::a int?)
(s/def ::doors int?)
(s/def ::wheels int?)
(s/def ::car (s/keys :req-un [::doors]))
(s/def ::bike (s/keys :req-un [::wheels]))
(s/def ::vehicle (s/or :car ::car
:bike ::bike))
(s/def ::merged-or (s/merge ::vehicle
(s/keys :opt-un [::a])))
(s/def ::merged-or-reversed (s/merge (s/keys :opt-un [::a])
::vehicle))

(let [chevy {:doors 4 :a 1}]
[(st/coerce ::merged-or chevy st/json-transformer)
(st/coerce ::merged-or chevy st/strip-extra-keys-transformer)
(st/coerce ::merged-or-reversed chevy st/strip-extra-keys-transformer)])
; => [{:doors 4, :a 1}
; {:a 1}
; {:doors 4, :a 1}]
```
I've not been able to create a fix :(

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided reproduction around st/coerce with st/strip-extra-keys-transformer. Trace how merged s/or specs are parsed and transformed, then verify that both ::merged-or and ::merged-or-reversed preserve :doors and :a for the sample input.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.