-
Notifications
You must be signed in to change notification settings - Fork 459
Support non-string enum validators ... #944
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
Open
jaynetics
wants to merge
1
commit into
Apipie:master
Choose a base branch
from
jaynetics:support-non-string-enums
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,9 @@ def expect_response_params_def(http_method, path, response_code, param_name, fie | |
| expect_param_def("get", "/users/by_department", "department", "enum", | ||
| %w[finance operations sales marketing HR]) | ||
|
|
||
| expect_param_def("get", "/users/by_department_number", "department", "type", "integer") | ||
| expect_param_def("get", "/users/by_department_number", "department", "enum", [1, 2, 3]) | ||
|
|
||
| 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") | ||
| end | ||
|
|
@@ -135,12 +138,15 @@ def expect_response_params_def(http_method, path, response_code, param_name, fie | |
| expect_param_def("get", "/users/by_department", "department", "enum", | ||
| %w[finance operations sales marketing HR]) | ||
|
|
||
| expect_param_def("get", "/users/by_department_number", "department", "type", "integer") | ||
| expect_param_def("get", "/users/by_department_number", "department", "enum", [1, 2, 3]) | ||
|
|
||
| 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") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| end | ||
|
|
||
| it "generates a valid swagger file" do | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class CustomTypedEnumValidator < Apipie::Validator::EnumValidator | ||
| attr_accessor :expected_type | ||
|
|
||
| def initialize(param_description, enum, type) | ||
| super(param_description, enum) | ||
| self.expected_type = type | ||
| end | ||
|
|
||
| def self.build(param_description, argument, options, block) | ||
| if argument.is_a?(Array) && options.to_h[:type] | ||
| new(param_description, argument, options[:type]) | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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@validatorsivar onEnumValidatorand 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 causemy_validatorto appear in the list twice.