-
Notifications
You must be signed in to change notification settings - Fork 42
[OpenAPI]: Extend @response / @request tag syntax to accept serializer options #299
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,37 @@ def self.__try_parse_collection(str) | |
| end | ||
| end | ||
|
|
||
| # @private | ||
| # @return [Array<Boolean, String, Hash>] a tuple of (is_collection, serializer, args) | ||
| def self.__parse_serializer_args(str) | ||
| is_collection, inner = __try_parse_collection(str) | ||
|
|
||
| if is_collection | ||
| # discard is_collection since we already know this is a collection from the outer call | ||
| _, clean_inner, args = __parse_serializer_args(inner) | ||
| if args.any? | ||
| [is_collection, clean_inner, args] | ||
| else | ||
| [is_collection, clean_inner, {}] | ||
|
Comment on lines
+140
to
+141
Member
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 branch is not covered with tests.
Contributor
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. It's covered by this two test (Line 94) and (Line 99) cases: context "with a collection using square brackets without options" do
let(:str) { "[UserBlueprint]" }
it { is_expected.to eq([true, "UserBlueprint", {}]) }
end
context "with a collection using Array syntax without options" do
let(:str) { "Array<UserBlueprint>" }
it { is_expected.to eq([true, "UserBlueprint", {}]) }
end |
||
| end | ||
| elsif str =~ /^([\w:]+)\(([^)]+)\)$/ | ||
| [is_collection, $1, __parse_keywords($2)] | ||
| else | ||
| [is_collection, str, {}] | ||
| end | ||
| end | ||
|
|
||
| # @private | ||
| def self.__parse_keywords(str) | ||
| return {} if str.nil? || str.empty? | ||
|
|
||
| str.split(",").each_with_object({}) do |part, hash| | ||
| option = YAML.load(part) | ||
| return nil unless option.is_a?(Hash) | ||
|
Member
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 condition is not covered with tests.
Contributor
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. Added a new test case for this (Line 183) context "with an invalid option (not a key value pair)" do
let(:str) { "extended" }
it { is_expected.to be_nil }
end |
||
| hash.merge!(option.transform_keys!(&:to_sym)) | ||
| end | ||
| end | ||
|
|
||
| # @private | ||
| def self.__module_parent(klass) | ||
| klass.name =~ /::[^:]+\z/ ? Object.const_get($`) : Object | ||
|
|
||
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.
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.
Done