Git Product home page Git Product logo

Comments (5)

vjik avatar vjik commented on August 22, 2024 2

I prefer first way with additional parameter in Result::getAttributeErrorMessagesIndexedByPath() and
Result::getErrorMessagesIndexedByPath() and by default escape separator chars in value path elements. It's allow to consumers correctly parse result keys.

from validator.

arogachev avatar arogachev commented on August 22, 2024

What is your use case for this method?

from validator.

bouledepate avatar bouledepate commented on August 22, 2024

@arogachev,

I have REST API. After validating the data with this method, I get all the errors given their path, since I'm using a Nested validator. Then I generate an exception, where I put the received array of errors, encode it through json_encode and give it to the client. And as planned, the key in this array can look like: "account.profile.name".

Also, "account.profile.name" is the key in the array of data that comes from the client to the server and it sends them for validation. Therefore, in order to avoid the behavior that Nested validator has, when "sub-arrays" are formed from such keys, I follow the documentation and escape the dots. "account/.profile/.name".

If a key contains the separator (.), or Each shortcut (*), it must be escaped with backslash () in the rule config to work correctly. In the input data escaping is not needed.

If the "account.profile.name" attribute fails validation, then I would expect to see the following in the response from the getErrorMessagesIndexedByPath: {"account.profile.name": "error text"},
but not {"account//.profile//.name": "error text"}

from validator.

bouledepate avatar bouledepate commented on August 22, 2024

I hope you got what I meant :)

from validator.

samdark avatar samdark commented on August 22, 2024

Makes sense. Thanks for suggestion, @bouledepate

from validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.