Skip to content

Proposal for convention regarding custom validator #2509

Closed
@ericproulx

Description

@ericproulx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions