Skip to content

Support passing a callable to EnumValidator - #946

Open
ekohl wants to merge 1 commit into
Apipie:masterfrom
ekohl:callable-enum-validator
Open

ekohl wants to merge 1 commit into
Apipie:masterfrom
ekohl:callable-enum-validator

Conversation

@ekohl

@ekohl ekohl commented Nov 5, 2024

Copy link
Copy Markdown
Member

In case the possible values are dynamic. This probably can't ever be made to work reliably with statically generating HTML documentation.

It's expected that the proc never throws an exception.

This was triggered by Katello code which really should be dynamic. Rather than using a ProcValidator this gives an accurate description as well.

In case the possible values are dynamic. This probably can't ever be
made to work reliably with statically generating HTML documentation.

It's expected that the proc never throws an exception.
@ekohl
ekohl force-pushed the callable-enum-validator branch from a07a525 to df3ecde Compare November 5, 2024 14:49
@ekohl

ekohl commented Nov 5, 2024

Copy link
Copy Markdown
Member Author

When writing this I didn't realize it would become ambiguous when to use ProcValidator and EnumValidator.

@mathieujobin mathieujobin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can increase test coverage and make sure all tests pass. then I can merge and release.

@PanosCodes if you have time to review later, that'd be appreciated as well.

Comment thread lib/apipie/validator.rb

def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a?(Array)
self.new(param_description, argument) if argument.is_a?(Array) || argument.respond_to?(:call)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathieujobin I'm not sure how to disambiguate this from the ProcValidator here:

self.new(param_description, argument) if argument.is_a?(Proc) && argument.arity == 1

If you have any thoughts, I'd love to hear them.

I thought about introducing a class that somehow wraps the callable, but it feels rather heavy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because EnumValidator will receive a Proc as well ?
Can you check that is it an Enum before?

.respond_to?(:call) can be a lot of things... so, you accept to build a Enum validator with either an Array or a Proc? not an Enum ? is a Enum a Proc underneath?

it would be good to add a new test where the confusion between the two validator can be demonstrated and the right one is being selected. this will help finding a working implementation.

@PanosCodes

Copy link
Copy Markdown
Contributor

I don't know if it's possible, but since we have a dynamic argument that we want to evaluate at the time apipie is called, can we maybe get the value of the callable before it is given to the validators and have the validator work as is? 🤔

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

Successfully merging this pull request may close these issues.

3 participants