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

Proposal for convention regarding custom validator #2509

Open
ericproulx opened this issue Oct 25, 2024 · 1 comment
Open

Proposal for convention regarding custom validator #2509

ericproulx opened this issue Oct 25, 2024 · 1 comment

Comments

@ericproulx
Copy link
Contributor

I would like to propose an update on how custom validator are registered within Grape. Actually, its based on an inherited hook that computes a short name based on the class's name. It works great but I think that setting a convention would simplify the process and the overall understanding of custom validators.

Basically, I'm suggesting that custom validator should be declared the same way has the built-in ones:

  • Declared In Grape::Validations::Validators modules
  • Class name must end with Validator

That way, instead of relying on the inherited hook, we could just call Grape::Validations::Validators.const_get(computed_short_name) when compiling. We're already using this pattern for versioning and coercing

It's not explicitly said in our documentation but right now anyone can add custom versioners and coercers by following the convention. In addition, parsers, formatters and error_formatters could also benefit from a convention and ease customization. In lower versions, we had Grape::Util::Registrable but I removed it not long ago since it wasn't really documented.

In any case, I've created a PR that applies Grape's convention and surprisingly its 🟢. That means that we don't have any tests that tries to load a real custom validator. I'll check that out.

Thanks everyone.

@ericproulx
Copy link
Contributor Author

Screenshot 2024-10-26 at 14 01 43 Well, our custom validator in the test suite are following the convention, that's why its 🟢

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

No branches or pull requests

1 participant