-
Notifications
You must be signed in to change notification settings - Fork 463
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
base: master
Are you sure you want to change the base?
Conversation
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.
a07a525
to
df3ecde
Compare
When writing this I didn't realize it would become ambiguous when to use |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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:
apipie-rails/lib/apipie/validator.rb
Line 313 in eeef4de
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.
There was a problem hiding this comment.
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.
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? 🤔 |
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.