Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate options to 1-child -reducing, disallow 0-child #1147

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

frenchy64
Copy link
Collaborator

:union and :merge don't work well with 0 and 1 children.

For 1 child, they don't propagate options to the child. This happens because the reduce call in -reducing returns init, which is a ?schema.

  • this pr ensures options are always propagated

For 0 children, deref'ing returns nil. This is because the reduce call in -reducing is passed nil init.

  • this pr adds checks for non-empty children to :merge and :union
  • fallback error for other users of -reducing
(m/form (m/deref-all (m/schema [:merge [:merge :map]] {:registry (merge (mu/schemas) (m/default-schemas))})))
; (err) Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:157).
; (err) :malli.core/invalid-schema

(m/deref (m/schema :merge {:registry (merge (mu/schemas) (m/default-schemas))}))
;=> nil

@frenchy64 frenchy64 marked this pull request as ready for review December 11, 2024 01:01
@frenchy64 frenchy64 requested a review from ikitommi December 11, 2024 01:12
@ikitommi ikitommi merged commit 440de1b into metosin:master Dec 12, 2024
13 checks passed
@ikitommi
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants