GithubHelp home page GithubHelp logo

Comments (5)

AlfonsoUceda avatar AlfonsoUceda commented on May 31, 2024 2

Folks, if you don't mind, I'm going to close this issue, for now don't use filled.schema just schema for nested structures. By the way, thanks for this issue.

from validations.

mjq avatar mjq commented on May 31, 2024 1

Here's a one-file gist that I think demonstrates the reported issue: https://gist.github.com/mjq/ab7ccae8a7620f34843897ce3da65699

The first assertion passes, but the second two fail, just as @rodrigopk described: :email is whitelisted at the first level, but not at the second.

Through experimentation, things work as expected (tests pass) with:

  params do
    required(:id).filled(:int?)
    optional(:user).schema do
      optional(:first_name).filled
      optional(:last_name).filled
    end
  end

(Note that filled was removed from :user and added to :first_name and :last_name).

I'm not sure if there's really a bug here or if the original code was unexpected/wrong. It would be nice if errors were thrown when hanami-validations sees unexpected validation constructions (like the filled.schema chain, or the optional rules without filled or any other conditions).

from validations.

AlfonsoUceda avatar AlfonsoUceda commented on May 31, 2024 1

@mjq @rodrigopk I've talked with dry maintainers and they told me that it is a limitation, chaining is not supported, right now we don't raise an error but they will improve the behaviour in dry-v 1.0

from validations.

AlfonsoUceda avatar AlfonsoUceda commented on May 31, 2024

Hi @rodrigopk do you have that config inside params block in the action class?

IMO that behaviour is right, because you are defining something like the following structure:

:id
:user
  |-> :first_name
  |-> :last_name

so you'll have to access it using params[:user][:email], if you want access the email to the first level, then don't declare them inside :user, for example check this: https://github.com/hanami/controller#validations--coercions of course you should send parameters outside user scope.

from validations.

AlfonsoUceda avatar AlfonsoUceda commented on May 31, 2024

@mjq ok, now I understand better the problem. I think the problem is use .filled in required(:user).filled.schema { ... }, when you have a nested data, you have to use required(:user).schema { ... } and if that nested data is optional you can use required(:user).maybe { ... }.

Anyway, I'll ask to dry-validation maintainers why with filled.schema doesn't work well.

from validations.

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.