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

Support passing a callable to EnumValidator #946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Nov 5, 2024

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
Copy link
Member Author

ekohl commented Nov 5, 2024

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

Copy link
Collaborator

@mathieujobin mathieujobin left a comment

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.

end

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
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
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
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