Liking cljdoc? Tell your friends :D

boundary.core.validation.messages

Error message templating and suggestion engine.

This namespace provides message template resolution, parameter interpolation, and intelligent suggestion generation for validation errors.

Key Features:

  • Template resolution with fallback chain (domain → shared → default)
  • Safe parameter interpolation with sanitization
  • 'Did you mean?' suggestion engine using Damerau-Levenshtein distance
  • Expected value, range, and regex hints
  • Dependency and resolution step formatting

Design Principles:

  • Non-breaking: Falls back to legacy messages if template missing
  • i18n-ready: All templates support parameter interpolation
  • Pure functions: No side effects, deterministic output
  • Sanitized: PII and sensitive data are filtered
Error message templating and suggestion engine.

This namespace provides message template resolution, parameter interpolation,
and intelligent suggestion generation for validation errors.

Key Features:
- Template resolution with fallback chain (domain → shared → default)
- Safe parameter interpolation with sanitization
- 'Did you mean?' suggestion engine using Damerau-Levenshtein distance
- Expected value, range, and regex hints
- Dependency and resolution step formatting

Design Principles:
- Non-breaking: Falls back to legacy messages if template missing
- i18n-ready: All templates support parameter interpolation
- Pure functions: No side effects, deterministic output
- Sanitized: PII and sensitive data are filtered
raw docstring

create-dependency-hintclj

(create-dependency-hint {:keys [field-name dependency]})

Create dependency hint.

Args: params: Map with :field-name, :dependency

Returns: Hint string

Example: {:field-name "Billing Address" :dependency "Payment Method"} => "Provide Payment Method before setting Billing Address"

Create dependency hint.

Args:
  params: Map with :field-name, :dependency

Returns:
  Hint string

Example:
  {:field-name "Billing Address" :dependency "Payment Method"}
  => "Provide Payment Method before setting Billing Address"
sourceraw docstring

create-did-you-mean-suggestionclj

(create-did-you-mean-suggestion {:keys [allowed suggestion]})

Create 'Did you mean?' suggestion text.

Args: params: Map with :value, :allowed, optional :suggestion

Returns: Suggestion string or nil

Example: {:value "admim" :allowed "admin, user, viewer" :suggestion "admin"} => "Did you mean "admin"? Allowed values: admin, user, viewer"

Create 'Did you mean?' suggestion text.

Args:
  params: Map with :value, :allowed, optional :suggestion

Returns:
  Suggestion string or nil

Example:
  {:value "admim" :allowed "admin, user, viewer" :suggestion "admin"}
  => "Did you mean \"admin\"? Allowed values: admin, user, viewer"
sourceraw docstring

create-expected-value-hintclj

(create-expected-value-hint {:keys [field-name expected]})

Create expected value/format hint.

Args: params: Map with :field-name, :expected

Returns: Hint string

Example: {:field-name "Email" :expected "user@domain.com"} => "Provide Email in the correct format. Expected: user@domain.com"

Create expected value/format hint.

Args:
  params: Map with :field-name, :expected

Returns:
  Hint string

Example:
  {:field-name "Email" :expected "user@domain.com"}
  => "Provide Email in the correct format. Expected: user@domain.com"
sourceraw docstring

create-length-hintclj

(create-length-hint {:keys [field-name min max]})

Create length validation hint.

Args: params: Map with :field-name, :min or :max

Returns: Hint string

Create length validation hint.

Args:
  params: Map with :field-name, :min or :max

Returns:
  Hint string
sourceraw docstring

create-range-hintclj

(create-range-hint {:keys [field-name min max value]})

Create range validation hint.

Args: params: Map with :field-name, :min, :max, optional :value

Returns: Hint string

Example: {:field-name "Age" :min "0" :max "120" :value "150"} => "Provide Age between 0 and 120. You provided: 150"

Create range validation hint.

Args:
  params: Map with :field-name, :min, :max, optional :value

Returns:
  Hint string

Example:
  {:field-name "Age" :min "0" :max "120" :value "150"}
  => "Provide Age between 0 and 120. You provided: 150"
sourceraw docstring

enhance-errorclj

(enhance-error error opts)

Enhance error map with rendered message and suggestion.

Non-breaking: If rendering fails, preserves original message.

Args: error: Error map with :code and :params opts: Optional rendering options

Returns: Enhanced error map with :message and optional :suggestion

Example: (enhance-error {:field :email :code :required :params {}}) => {:field :email :code :required :params {} :message "Email is required" :suggestion "Provide an email address for the user"}

Enhance error map with rendered message and suggestion.

Non-breaking: If rendering fails, preserves original message.

Args:
  error: Error map with :code and :params
  opts: Optional rendering options

Returns:
  Enhanced error map with :message and optional :suggestion

Example:
  (enhance-error {:field :email :code :required :params {}})
  => {:field :email
      :code :required
      :params {}
      :message "Email is required"
      :suggestion "Provide an email address for the user"}
sourceraw docstring

format-allowed-valuesclj

(format-allowed-values values
                       {:keys [max-items conjunction]
                        :or {max-items 10 conjunction "and"}})

Format list of allowed values for display.

Args: values: Collection of allowed values opts: Optional map with :max-items (default 10), :conjunction (default 'and')

Returns: Formatted string

Examples: (format-allowed-values ["admin" "user" "viewer"]) => "admin, user, and viewer"

(format-allowed-values ["a" "b" "c" "d"] {:conjunction "or"}) => "a, b, c, or d"

Format list of allowed values for display.

Args:
  values: Collection of allowed values
  opts: Optional map with :max-items (default 10), :conjunction (default 'and')

Returns:
  Formatted string

Examples:
  (format-allowed-values ["admin" "user" "viewer"])
  => "admin, user, and viewer"
  
  (format-allowed-values ["a" "b" "c" "d"] {:conjunction "or"})
  => "a, b, c, or d"
sourceraw docstring

format-field-nameclj

(format-field-name field)

Format field name for display (kebab-case to Title Case).

Args: field: Field keyword

Returns: Formatted string

Examples: :email -> "Email" :tenant-id -> "Tenant ID" :user-agent -> "User Agent"

Format field name for display (kebab-case to Title Case).

Args:
  field: Field keyword

Returns:
  Formatted string

Examples:
  :email -> "Email"
  :tenant-id -> "Tenant ID"
  :user-agent -> "User Agent"
sourceraw docstring

interpolate-templateclj

(interpolate-template template params)

Interpolate parameters into template string.

Replaces {{placeholder}} with corresponding param value.

Args: template: Template string with {{placeholder}} markers params: Map of parameter values

Returns: Interpolated string

Example: (interpolate-template "{{field-name}} is required" {:field-name "Email"}) => "Email is required"

Interpolate parameters into template string.

Replaces {{placeholder}} with corresponding param value.

Args:
  template: Template string with {{placeholder}} markers
  params: Map of parameter values

Returns:
  Interpolated string

Example:
  (interpolate-template "{{field-name}} is required" {:field-name "Email"})
  => "Email is required"
sourceraw docstring

render-messageclj

(render-message code params _)

Render complete error message with template and parameters.

Args: code: Error code keyword params: Parameter map opts: Optional rendering options

Returns: Rendered message string

Example: (render-message :required {:field :email}) => "Email is required"

Render complete error message with template and parameters.

Args:
  code: Error code keyword
  params: Parameter map
  opts: Optional rendering options

Returns:
  Rendered message string

Example:
  (render-message :required {:field :email})
  => "Email is required"
sourceraw docstring

render-suggestionclj

(render-suggestion code params)

Render suggestion text based on error code and parameters.

Args: code: Error code keyword params: Parameter map

Returns: Suggestion string or nil

Example: (render-suggestion :invalid-value {:field :role :value "admim" :allowed "admin, user, viewer" :suggestion "admin"}) => "Did you mean "admin"? Allowed values: admin, user, viewer"

Render suggestion text based on error code and parameters.

Args:
  code: Error code keyword
  params: Parameter map

Returns:
  Suggestion string or nil

Example:
  (render-suggestion :invalid-value 
                    {:field :role
                     :value "admim"
                     :allowed "admin, user, viewer"
                     :suggestion "admin"})
  => "Did you mean \"admin\"? Allowed values: admin, user, viewer"
sourceraw docstring

suggest-similar-valueclj

(suggest-similar-value value
                       allowed-values
                       {:keys [threshold max-distance]
                        :or {threshold 0.6 max-distance 2}})

Suggest similar value from allowed values using string distance.

Args: value: Input value (possibly misspelled) allowed-values: Collection of allowed values opts: Optional map with :threshold (default 0.6), :max-distance (default 2)

Returns: Best match string or nil

Example: (suggest-similar-value "admim" ["admin" "user" "viewer"]) => "admin"

Suggest similar value from allowed values using string distance.

Args:
  value: Input value (possibly misspelled)
  allowed-values: Collection of allowed values
  opts: Optional map with :threshold (default 0.6), :max-distance (default 2)

Returns:
  Best match string or nil

Example:
  (suggest-similar-value "admim" ["admin" "user" "viewer"])
  => "admin"
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