Skip to content

Commit

Permalink
Use method_name instead of method when generating hash warnings
Browse files Browse the repository at this point in the history
In #865 we introduced a `method_name` method on `MethodDescription` to avoid this bug, but the commit didn't actually use that method.  Sometimes the `@controller_method` object used is a `Apipie::Generator::Swagger::MethodDescription::Decorator` which is a `SimpleDelegate` onto a `Apipie::MethodDescription` and we'd expect to be able to call `method` on it, but unfortunately `method` is one of the things _not_ delegated by `SimpleDelegate` because it's a standard ruby method and so you get

    ArgumentError: wrong number of arguments (given 0, expected 1)

when you try to call it.  Using `method_name` instead avoids that so that's what we do - and now we can happily generate the swagger warnings when we have hash type objects without defined params.
  • Loading branch information
h-lame committed Jul 9, 2024
1 parent 89e7ded commit e1fd88a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/apipie/generator/swagger/param_description/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def validator
def warn_hash_without_internal_typespec
method_id =
if @param_description.is_a?(Apipie::ResponseDescriptionAdapter::PropDesc)
@controller_method.method
@controller_method.method_name
else
Apipie::Generator::Swagger::MethodDescription::Decorator.new(@param_description.method_description).ruby_name
end
Expand Down
20 changes: 19 additions & 1 deletion spec/lib/apipie/generator/swagger/param_description/type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
)
end

let(:controller_method) { 'index' }

let(:type_definition) do
described_class.
new(param_description, with_null: with_null, controller_method: 'index').
new(param_description, with_null: with_null, controller_method: controller_method).
to_hash
end

Expand Down Expand Up @@ -178,6 +180,22 @@
it 'outputs a hash without internal typespec warning' do
expect { subject }.to output(/is a generic Hash without an internal type specification/).to_stderr
end

context 'and param is a prop desc with a delegated controller method' do
let(:param_description) do
Apipie.prop(param_description_name, 'object', {}, [])
end

let(:controller_method) do
Apipie::Generator::Swagger::MethodDescription::Decorator.new(
method_desc
)
end

it 'outputs a hash without internal typespec warning' do
expect { subject }.to output(/is a generic Hash without an internal type specification/).to_stderr
end
end
end
end
end

0 comments on commit e1fd88a

Please sign in to comment.