Skip to content

Commit

Permalink
Use method_name instead of method when generating required warnings
Browse files Browse the repository at this point in the history
Unlike the previous commit, this isn't strictly required as we're not calling
the un-delegated `method`, but instead the warning will contain a standard
`to_s` of the `@controller_method` that isn't very easy to read, like this:

    WARNING (105): [#<Apipie::MethodDescription:0x0000000126316f60>] -- The
    parameter :param is optional but default value is not specified (use
    :default_value => ...)

By using `method_name` instead we get symmetry with the hash warning from the
previous commit.
  • Loading branch information
h-lame committed Jul 9, 2024
1 parent e1fd88a commit 1a4550f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/apipie/generator/swagger/param_description/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def required_from_path?
def warn_optional_without_default_value(definition)
if !required? && !definition.key?(:default)
method_id =
if @param_description.is_a?(Apipie::ResponseDescriptionAdapter::PropDesc)
@controller_method
if @controller_method.present? && @param_description.is_a?(Apipie::ResponseDescriptionAdapter::PropDesc)
@controller_method.method_name
else
Apipie::Generator::Swagger::MethodDescription::Decorator.new(@controller_method).ruby_name
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@
/is optional but default value is not specified/
).to_stderr
end

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

let(:method_desc) do
Apipie::Generator::Swagger::MethodDescription::Decorator.new(
Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
)
end

it 'warns' do
expect { subject }.to output(
/is optional but default value is not specified/
).to_stderr
end
end
end
end
end
Expand Down

0 comments on commit 1a4550f

Please sign in to comment.