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

Validation results as error metadata #14

Merged
merged 4 commits into from
Jan 3, 2014

Conversation

dm3
Copy link
Contributor

@dm3 dm3 commented Sep 29, 2013

Continuation of #10

validate now accepts an optional function as the first parameter. This function is responsible for converting error metadata into messages (see core/with-default-messages as an example which provides backwards compatible behavior).

Error metadata is a map with the following structure:

  • path - path to the field which produced the error
  • value - value of the field which produced the error
  • args - arguments supplied to the validator
  • metadata - metadata of the defvalidator including the validator parameter which contains the namespace-prefixed keyword with the name of the validator (e.g. :bouncer.validators/required).
  • message - message supplied to the validator when calling core/validate

Vadim Platonov added 4 commits September 29, 2013 11:24
`bouncer.core/validate` now accepts an optional function responsible for
transforming the error metadata map as the first parameter.

Errors returned by

    (bouncer.core/validate {:a {:b "1"}}
        [:a :b] bouncer.validators/matches #"2" :message "oops")

will contain error metadata in the form of

    {:path [:a :b]
     :value "1"
     :args (#"2")
     :metadata {:default-message-format "%s must match ..."
                :optional true
                :validator :bouncer.validators/matches}
     :message "oops"}

instead of an interpolated message. Backwards-compatible behavior can be
achieved by passing `bouncer.core/with-default-messages` as the first
parameter to `validate`.

Any metadata supplied to `defvalidator` will appear in the error
metadata under the `:metadata` key.
@dm3
Copy link
Contributor Author

dm3 commented Oct 29, 2013

Just checking, have you had the time to go through the PR?

@theleoborges
Copy link
Owner

Hi @dm3 , I'm really sorry about the delay but I've been swamped at work.

The PR is on my backlog and I'll get to it soon. I plan to go through it within the next couple of weeks.

Thanks for sending it through.

@theleoborges theleoborges merged commit f60812e into theleoborges:master Jan 3, 2014
@theleoborges
Copy link
Owner

Hi @dm3 ,

Apologies for having taken so long to get around to this but it's finally done :)

The only change I made was default to with-default-messages instead of identity. This guarantees 100% backwards compatibility.

I'll be releasing this soon as 0.3.1-beta1.

Thank you so much for your contribution.

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