-
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 non-string enum validators ... #944
base: master
Are you sure you want to change the base?
Conversation
@@ -25,8 +25,11 @@ def inspect | |||
end | |||
|
|||
def self.inherited(subclass) | |||
BaseValidator.validators.unshift(subclass) |
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.
Previously when subclassing a concrete validator, e.g. EnumValidator
, this method would init the @validators
ivar on EnumValidator
and insert the new subclass there.
By explicitly referencing BaseValidator
, the new class is added to the correct list.
This change shouldn't affect backwards compatibility. Worst case if anyone subclassed existing validators, they probably did BaseValidator.inherited(my_validator)
or so, in which case this fix would cause my_validator
to appear in the list twice.
expect_param_def("get", "/users/in_departments", "departments", "in", "query") | ||
expect_array_param_def("get", "/users/in_departments", "departments", | ||
%w[finance operations sales marketing HR]) | ||
|
||
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search]) | ||
|
||
expect_response_params_def("get", "/pets/{id}/as_properties", 200, "pet_name", "example", "mypet") |
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.
this added line is not related to this PR. i've just copied it from the other changed example above because it looks as if the two examples were supposed to mirror each other.
... both for custom validators and self-describing properties. Before: ```ruby expect(pm_schema).to have_field(:num_tails, 'number', {:description => "Number of tails", :enum => [0, 1]}) # => expected param 'num_tails' to have type 'number' (got 'string') expect_param_def("get", "/users/by_department_number", "department", "type", "integer") # => expected: "integer" # => got: "string" ``` After: tests pass. This PR also adds support for subclassing of validators.
9f5d68c
to
a4fd25c
Compare
... both for custom validators and self-describing properties.
Before:
After:
tests pass.
This PR also adds support for subclassing of validators.