<p dir="auto">Seems to me that most APIs will assign unique error codes to each potential validation error, in addition to human-readable messages.</p>
<p dir="auto">Before considering a PR, I wonder what the consensus on adding the ability to add a 'code' property to each field constraint would be?</p>
<p dir="auto">Following my <a href="http://stackoverflow.com/q/15206637/744147" rel="nofollow">(unanswered) question at StackOverflow</a> I'm reporting this as a bug, as no one seems to know the answer.</p>
<p dir="auto">Currently there's no way that I can see to populate the <code class="notranslate">code</code> property for the <code class="notranslate">ConstraintViolation</code> class, as it is not defined in the <code class="notranslate">Constraint</code> class. But as I see, it goes farther than that, as all the validators just ignore the parameters for the <code class="notranslate">addViolation</code> method, making it impossible for simple asserts to define a code for the violation.</p>
<p dir="auto">What I expect it to allow is the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
 * @Assert\NotBlank(code=400)
 * @Assert\Email(code=401)
 */
protected $email;"><pre class="notranslate"><code class="notranslate">/**
 * @Assert\NotBlank(code=400)
 * @Assert\Email(code=401)
 */
protected $email;
</code></pre></div>
<p dir="auto">Problem is, the current validators call <code class="notranslate">addViolations</code> without setting the 5th argument (<code class="notranslate">code</code>). Plus, the <code class="notranslate">Constraint</code> class doesn't implement such a <code class="notranslate">code</code> property as mentioned.</p>
<p dir="auto">If this is indeed considered a bug, I would like to send a PR with a patch, provided that this is the way that it should be working.If it's not, some directions would be amazing!</p>