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

Introduce schemas for map key constraints #1161

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

frenchy64
Copy link
Collaborator

@frenchy64 frenchy64 commented Jan 13, 2025

This PR adds some schemas to help constrain the keysets of :map schemas. Instead of [:and [:map ..] [:fn <OPAQUE>]], you now write [:and [:map ...] [:xor ..] [:iff ..] ...].

The next step is to improve the generators for these schemas. The basic strategy to generate [:and S T] will be to generate S but propagate T as a hint to the S generator. Most of the work will be to canonicalize T by expanding into disjunctive normal form.

Humanization comes with the usual caveats of not being able to represent the difference between a conjunction or disjunction of errors, so some of the humanizers are a little strange. I'm not sure if this can be fixed without a breaking change to the humanization representation.

There are more general abstractions here (like the idea of simplifying a schema) but we can build towards that later. I have sketches of using such abstractions to compile optimal validators and generators. For now, concentrating on map keyset constraints is helping move this work along.

Note: the :max-tries change is to fix an unrelated flaky test:

ERROR in malli.generator-test/min-max-test (core.cljc:179)
valid properties
Exception: clojure.lang.ExceptionInfo: :malli.generator/distinct-generator-failure
{:type :malli.generator/distinct-generator-failure, :message :malli.generator/distinct-generator-failure, :data {:gen #clojure.test.check.generators.Generator{:gen #object[clojure.test.check.generators$such_that$fn__2964 0x66099385 "clojure.test.check.generators$such_that$fn__2964@66099385"]}, :max-tries 10, :num-elements [15](https://github.com/frenchy64/malli/actions/runs/12751433381/job/35538498628#step:6:16), :schema [:set {:gen/min 10, :max 20} int?]}}

@frenchy64 frenchy64 marked this pull request as ready for review January 13, 2025 09:39
@frenchy64 frenchy64 requested a review from ikitommi January 13, 2025 09:39
@frenchy64 frenchy64 marked this pull request as draft January 13, 2025 18:44
@frenchy64 frenchy64 marked this pull request as ready for review January 13, 2025 20:08
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.

1 participant