Liking cljdoc? Tell your friends :D

boundary.core.validation.generators

Property-based test data generators for validation testing.

This namespace provides pure functions for generating test data from Malli schemas, supporting both valid and invalid data generation with deterministic seeding.

Key Features:

  • Valid data generation conforming to schemas
  • Invalid data generation with specific violation types
  • Boundary case generation (min/max values, edge cases)
  • Rule-aware generation for targeted testing
  • Deterministic seeding for reproducible tests

Design Principles:

  • Pure functions only (no side effects, no I/O)
  • Schema lookup via injected functions (no direct registry access)
  • Deterministic with explicit seeds
  • FC/IS compliant (all generators are functional core)

Usage: ;; Generate valid data (gen-valid-one User {:seed 42}) => {:id #uuid "..." :email "user@example.com" ...}

;; Generate invalid data (gen-invalid-one User :missing-required {:seed 42 :field :email}) => {:id #uuid "..." :name "John" ...} ; missing :email

;; Generate boundary cases (gen-boundaries User {:seed 42}) => [{:name "" ...} {:name "a" ...} {:name "aaa..." ...}]

Property-based test data generators for validation testing.

This namespace provides pure functions for generating test data from Malli schemas,
supporting both valid and invalid data generation with deterministic seeding.

Key Features:
- Valid data generation conforming to schemas
- Invalid data generation with specific violation types
- Boundary case generation (min/max values, edge cases)
- Rule-aware generation for targeted testing
- Deterministic seeding for reproducible tests

Design Principles:
- Pure functions only (no side effects, no I/O)
- Schema lookup via injected functions (no direct registry access)
- Deterministic with explicit seeds
- FC/IS compliant (all generators are functional core)

Usage:
  ;; Generate valid data
  (gen-valid-one User {:seed 42})
  => {:id #uuid "..." :email "user@example.com" ...}
  
  ;; Generate invalid data
  (gen-invalid-one User :missing-required {:seed 42 :field :email})
  => {:id #uuid "..." :name "John" ...} ; missing :email
  
  ;; Generate boundary cases
  (gen-boundaries User {:seed 42})
  => [{:name "" ...} {:name "a" ...} {:name "aaa..." ...}]
raw docstring

default-countclj

Default number of samples to generate.

Default number of samples to generate.
sourceraw docstring

default-seedclj

Default seed for deterministic generation.

Default seed for deterministic generation.
sourceraw docstring

default-sizeclj

Default size parameter for Malli generator.

Default size parameter for Malli generator.
sourceraw docstring

gen-boundariesclj

(gen-boundaries schema-or-key opts)

Generate boundary case values for schema fields.

Args: schema-or-key: Malli schema or keyword to resolve opts: Options map with :seed, :registry

Returns: Vector of boundary case samples

Example: (gen-boundaries User {:seed 42}) => [{:name "" ...} {:name "a" ...} {:name "aaa..." ...}]

Generate boundary case values for schema fields.

Args:
  schema-or-key: Malli schema or keyword to resolve
  opts: Options map with :seed, :registry

Returns:
  Vector of boundary case samples

Example:
  (gen-boundaries User {:seed 42})
  => [{:name "" ...} {:name "a" ...} {:name "aaa..." ...}]
sourceraw docstring

gen-for-moduleclj

(gen-for-module module-kw opts)

Generate examples across all rules in a module.

Args: module-kw: Module keyword (e.g., :user, :billing) opts: Options map with: - :type (:valid or :invalid) - :seed - :list-rules (fn [module-kw] [rule-ids]) - :resolve-schema (fn [rule-id] schema)

Returns: Map of rule-id to generated samples

Example: (gen-for-module :user {:type :valid :seed 42 :list-rules my-list-fn :resolve-schema my-resolver}) => {:user.email/required {:id #uuid "..." ...} :user.name/required {:id #uuid "..." ...}}

Generate examples across all rules in a module.

Args:
  module-kw: Module keyword (e.g., :user, :billing)
  opts: Options map with:
        - :type (:valid or :invalid)
        - :seed
        - :list-rules (fn [module-kw] [rule-ids])
        - :resolve-schema (fn [rule-id] schema)

Returns:
  Map of rule-id to generated samples

Example:
  (gen-for-module :user
                  {:type :valid
                   :seed 42
                   :list-rules my-list-fn
                   :resolve-schema my-resolver})
  => {:user.email/required {:id #uuid "..." ...}
      :user.name/required {:id #uuid "..." ...}}
sourceraw docstring

gen-for-ruleclj

(gen-for-rule rule-id opts)

Generate examples for specific validation rule.

Args: rule-id: Validation rule identifier keyword opts: Options map with: - :type (:valid or :invalid) - :violation (violation type if :type is :invalid) - :seed - :resolve-schema (fn [rule-id] schema) - :rule->schema-key (fn [rule-id] keyword)

Returns: Generated sample for the rule

Example: (gen-for-rule :user.email/required {:type :invalid :violation :missing-required :seed 42 :resolve-schema my-resolver}) => {:id #uuid "..." :name "Alice" ...}

Generate examples for specific validation rule.

Args:
  rule-id: Validation rule identifier keyword
  opts: Options map with:
        - :type (:valid or :invalid)
        - :violation (violation type if :type is :invalid)
        - :seed
        - :resolve-schema (fn [rule-id] schema)
        - :rule->schema-key (fn [rule-id] keyword)

Returns:
  Generated sample for the rule

Example:
  (gen-for-rule :user.email/required
                {:type :invalid
                 :violation :missing-required
                 :seed 42
                 :resolve-schema my-resolver})
  => {:id #uuid "..." :name "Alice" ...}
sourceraw docstring

gen-invalidclj

(gen-invalid schema-or-key violation-type opts)

Generate sequence of invalid samples from schema.

Args: schema-or-key: Malli schema or keyword to resolve violation-type: Keyword from violation-types set opts: Options map with :seed, :count, :field, :registry

Returns: Lazy sequence of generated invalid samples

Example: (take 3 (gen-invalid User :missing-required {:seed 42 :field :email :count 5})) => ({:id #uuid "..." :name "Alice" ...} ...)

Generate sequence of invalid samples from schema.

Args:
  schema-or-key: Malli schema or keyword to resolve
  violation-type: Keyword from violation-types set
  opts: Options map with :seed, :count, :field, :registry

Returns:
  Lazy sequence of generated invalid samples

Example:
  (take 3 (gen-invalid User :missing-required {:seed 42 :field :email :count 5}))
  => ({:id #uuid "..." :name "Alice" ...} ...)
sourceraw docstring

gen-invalid-oneclj

(gen-invalid-one schema-or-key violation-type opts)

Generate single invalid sample from schema with specific violation.

Args: schema-or-key: Malli schema or keyword to resolve violation-type: Keyword from violation-types set opts: Options map with :seed, :field, :registry

Returns: Single generated sample that violates schema

Example: (gen-invalid-one User :missing-required {:seed 42 :field :email}) => {:id #uuid "..." :name "Alice" ...} ; missing :email

Generate single invalid sample from schema with specific violation.

Args:
  schema-or-key: Malli schema or keyword to resolve
  violation-type: Keyword from violation-types set
  opts: Options map with :seed, :field, :registry

Returns:
  Single generated sample that violates schema

Example:
  (gen-invalid-one User :missing-required {:seed 42 :field :email})
  => {:id #uuid "..." :name "Alice" ...} ; missing :email
sourceraw docstring

gen-validclj

(gen-valid schema-or-key opts)

Generate sequence of valid samples from schema.

Args: schema-or-key: Malli schema or keyword to resolve opts: Options map with :seed, :size, :count, :registry

Returns: Lazy sequence of generated samples

Example: (take 3 (gen-valid User {:seed 42 :count 5})) => ({:id #uuid "..." ...} {:id #uuid "..." ...} ...)

Generate sequence of valid samples from schema.

Args:
  schema-or-key: Malli schema or keyword to resolve
  opts: Options map with :seed, :size, :count, :registry

Returns:
  Lazy sequence of generated samples

Example:
  (take 3 (gen-valid User {:seed 42 :count 5}))
  => ({:id #uuid "..." ...} {:id #uuid "..." ...} ...)
sourceraw docstring

gen-valid-oneclj

(gen-valid-one schema-or-key opts)

Generate single valid sample from schema.

Args: schema-or-key: Malli schema or keyword to resolve opts: Options map with :seed, :size, :registry

Returns: Single generated sample conforming to schema

Example: (gen-valid-one User {:seed 42 :size 5}) => {:id #uuid "..." :email "user@example.com" :name "Alice" ...}

Generate single valid sample from schema.

Args:
  schema-or-key: Malli schema or keyword to resolve
  opts: Options map with :seed, :size, :registry

Returns:
  Single generated sample conforming to schema

Example:
  (gen-valid-one User {:seed 42 :size 5})
  => {:id #uuid "..." :email "user@example.com" :name "Alice" ...}
sourceraw docstring

resolve-schemaclj

(resolve-schema schema-or-key opts)

Resolve schema from keyword or schema value using optional registry function.

Args: schema-or-key: Either a Malli schema or a keyword to look up opts: Options map with optional :registry function (fn [k] schema)

Returns: Malli schema or nil if not found

Example: (resolve-schema :user {:registry (fn [k] User)}) => User schema

(resolve-schema User {}) => User schema

Resolve schema from keyword or schema value using optional registry function.

Args:
  schema-or-key: Either a Malli schema or a keyword to look up
  opts: Options map with optional :registry function (fn [k] schema)

Returns:
  Malli schema or nil if not found

Example:
  (resolve-schema :user {:registry (fn [k] User)})
  => User schema
  
  (resolve-schema User {})
  => User schema
sourceraw docstring

rng-from-seedclj

(rng-from-seed seed)

Create deterministic RNG from seed.

Args: seed: Long integer seed value

Returns: Java Random instance

Example: (rng-from-seed 42) => #object[java.util.Random ...]

Create deterministic RNG from seed.

Args:
  seed: Long integer seed value

Returns:
  Java Random instance

Example:
  (rng-from-seed 42)
  => #object[java.util.Random ...]
sourceraw docstring

violation-typesclj

Supported violation types for invalid data generation.

Supported violation types for invalid data generation.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close