From 1a4550fb2c1e0cf96ebfada4e3d0242ab9af74f4 Mon Sep 17 00:00:00 2001 From: Murray Steele Date: Mon, 24 Jun 2024 17:47:07 +0100 Subject: [PATCH] Use `method_name` instead of `method` when generating required warnings 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): [#] -- 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. --- .../swagger/param_description/builder.rb | 4 ++-- .../swagger/param_description/builder_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/apipie/generator/swagger/param_description/builder.rb b/lib/apipie/generator/swagger/param_description/builder.rb index eb695b1f..04c75497 100644 --- a/lib/apipie/generator/swagger/param_description/builder.rb +++ b/lib/apipie/generator/swagger/param_description/builder.rb @@ -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 diff --git a/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb b/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb index db7479df..bd73ed7f 100644 --- a/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +++ b/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb @@ -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