diff --git a/.rubocop.yml b/.rubocop.yml index 45cc3b9aa..abd4c7b7a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,9 @@ AllCops: NewCops: enable TargetRubyVersion: 2.6 +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + Layout/LineLength: Max: 140 Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a38dfd2e5..4d2c2087d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,15 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 180` -# on 2024-02-19 23:31:58 UTC using RuboCop version 1.60.2. +# on 2024-07-10 23:53:15 UTC using RuboCop version 1.65.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -RubyVersionGlobalsUsage: - Exclude: - - apipie-rails.gemspec - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Severity, Include. @@ -18,7 +14,7 @@ Gemspec/DeprecatedAttributeAssignment: Exclude: - 'apipie-rails.gemspec' -# Offense count: 11 +# Offense count: 12 # Configuration parameters: EnforcedStyle, AllowedGems, Include. # SupportedStyles: Gemfile, gems.rb, gemspec # Include: **/*.gemspec, **/Gemfile, **/gems.rb @@ -50,6 +46,13 @@ Gemspec/RequiredRubyVersion: Exclude: - 'spec/dummy/components/test_engine/test_engine.gemspec' +# Offense count: 1 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RubyVersionGlobalsUsage: + Exclude: + - 'apipie-rails.gemspec' + # Offense count: 24 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. @@ -142,7 +145,7 @@ Layout/EmptyLineAfterGuardClause: - 'spec/lib/swagger/swagger_dsl_spec.rb' - 'spec/spec_helper.rb' -# Offense count: 13 +# Offense count: 12 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. Layout/EmptyLineBetweenDefs: @@ -158,7 +161,7 @@ Layout/EmptyLineBetweenDefs: - 'spec/dummy/app/controllers/pets_using_auto_views_controller.rb' - 'spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb' -# Offense count: 55 +# Offense count: 54 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLines: Exclude: @@ -227,7 +230,7 @@ Layout/EmptyLinesAroundBlockBody: - 'spec/spec_helper.rb' - 'spec/test_engine/memes_controller_spec.rb' -# Offense count: 44 +# Offense count: 43 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only @@ -241,7 +244,6 @@ Layout/EmptyLinesAroundClassBody: - 'lib/apipie/markup.rb' - 'lib/apipie/param_description.rb' - 'lib/apipie/resource_description.rb' - - 'lib/apipie/response_description.rb' - 'lib/apipie/response_description_adapter.rb' - 'lib/apipie/see_description.rb' - 'lib/apipie/tag_list_description.rb' @@ -415,16 +417,6 @@ Layout/MultilineMethodCallBraceLayout: Exclude: - 'lib/tasks/apipie.rake' -# Offense count: 14 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'lib/apipie/generator/swagger/param_description/builder.rb' - - 'lib/apipie/generator/swagger/param_description/composite.rb' - - 'lib/apipie/generator/swagger/param_description/type.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. @@ -601,12 +593,11 @@ Layout/TrailingEmptyLines: - 'spec/lib/apipie/generator/swagger/param_description_spec.rb' - 'spec/lib/apipie/param_group_spec.rb' -# Offense count: 15 +# Offense count: 14 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowInHeredoc. Layout/TrailingWhitespace: Exclude: - - 'lib/apipie/error_description.rb' - 'spec/dummy/app/controllers/application_controller.rb' - 'spec/dummy/app/controllers/twitter_example_controller.rb' @@ -711,7 +702,7 @@ Lint/UnderscorePrefixedVariableName: # Offense count: 22 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +# Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: - 'lib/apipie/configuration.rb' @@ -726,7 +717,7 @@ Lint/UnusedBlockArgument: # Offense count: 24 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: - 'lib/apipie/dsl_definition.rb' @@ -737,6 +728,7 @@ Lint/UnusedMethodArgument: # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AutoCorrect. Lint/UselessAssignment: Exclude: - 'lib/apipie/application.rb' @@ -746,24 +738,26 @@ Lint/UselessAssignment: # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AutoCorrect. Lint/UselessMethodDefinition: Exclude: - 'spec/dummy/app/controllers/overridden_concerns_controller.rb' -# Offense count: 3 +# Offense count: 4 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: CheckForMethodsWithNoSideEffects. +# Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: - 'spec/controllers/users_controller_spec.rb' + - 'spec/lib/swagger/swagger_dsl_spec.rb' # Offense count: 60 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 96 -# Offense count: 3 -# Configuration parameters: CountBlocks. +# Offense count: 1 +# Configuration parameters: CountBlocks, CountModifierForms. Metrics/BlockNesting: Max: 4 @@ -977,7 +971,7 @@ RSpec/DescribeClass: # Offense count: 75 # This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SkipBlocks, EnforcedStyle. +# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants. # SupportedStyles: described_class, explicit RSpec/DescribedClass: Exclude: @@ -997,6 +991,7 @@ RSpec/DescribedClass: # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AutoCorrect. RSpec/EmptyExampleGroup: Exclude: - 'spec/lib/apipie/generator/swagger/param_description/composite_spec.rb' @@ -1020,7 +1015,7 @@ RSpec/EmptyLineAfterHook: Exclude: - 'spec/lib/apipie/apipies_controller_spec.rb' -# Offense count: 52 +# Offense count: 55 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 85 @@ -1046,6 +1041,7 @@ RSpec/HookArgument: # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AutoCorrect. RSpec/HooksBeforeExamples: Exclude: - 'spec/controllers/users_controller_spec.rb' @@ -1092,7 +1088,7 @@ RSpec/MessageSpies: RSpec/MultipleExpectations: Max: 19 -# Offense count: 163 +# Offense count: 170 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 15 @@ -1117,7 +1113,7 @@ RSpec/NamedSubject: - 'spec/lib/swagger/rake_swagger_spec.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' -# Offense count: 97 +# Offense count: 99 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 6 @@ -1156,13 +1152,6 @@ RSpec/PredicateMatcher: - 'spec/lib/apipie/file_handler_spec.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Inferences. -RSpecRails/InferredSpecType: - Exclude: - - 'spec/controllers/pets_controller_spec.rb' - # Offense count: 2 RSpec/RepeatedExampleGroupBody: Exclude: @@ -1209,7 +1198,7 @@ Rails/Delegate: Exclude: - 'lib/apipie/response_description_adapter.rb' -# Offense count: 24 +# Offense count: 25 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: slashes, arguments @@ -1420,7 +1409,7 @@ Style/CommentedKeyword: - 'lib/apipie/dsl_definition.rb' - 'lib/apipie/extractor/recorder.rb' -# Offense count: 8 +# Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition @@ -1455,7 +1444,7 @@ Style/EmptyCaseCondition: # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowComments. +# Configuration parameters: AutoCorrect, EnforcedStyle, AllowComments. # SupportedStyles: empty, nil, both Style/EmptyElse: Exclude: @@ -1465,7 +1454,7 @@ Style/EmptyElse: # Offense count: 27 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. +# Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: Exclude: @@ -1552,7 +1541,7 @@ Style/HashExcept: # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -# SupportedShorthandSyntax: always, never, either, consistent +# SupportedShorthandSyntax: always, never, either, consistent, either_consistent Style/HashSyntax: Exclude: - 'spec/dummy/config/routes.rb' @@ -1687,7 +1676,7 @@ Style/Proc: - 'spec/lib/apipie/apipies_controller_spec.rb' # Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedCompactTypes. # SupportedStyles: compact, exploded Style/RaiseArgs: @@ -1844,7 +1833,7 @@ Style/StringConcatenation: - 'lib/apipie/application.rb' - 'lib/apipie/extractor/writer.rb' -# Offense count: 1229 +# Offense count: 1233 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -1944,7 +1933,7 @@ Style/TrailingCommaInArrayLiteral: - 'spec/controllers/users_controller_spec.rb' - 'spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb' -# Offense count: 5 +# Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma @@ -1952,7 +1941,6 @@ Style/TrailingCommaInHashLiteral: Exclude: - 'lib/apipie/generator/swagger/param_description.rb' - 'lib/apipie/generator/swagger/param_description/builder.rb' - - 'lib/apipie/response_description.rb' - 'spec/controllers/users_controller_spec.rb' # Offense count: 1 diff --git a/lib/apipie/application.rb b/lib/apipie/application.rb index 898f534fa..5399b0bb3 100644 --- a/lib/apipie/application.rb +++ b/lib/apipie/application.rb @@ -281,12 +281,12 @@ def to_swagger_json(version, resource_id, method_name, language, clear_warnings resources = Apipie::Generator::Swagger::ResourceDescriptionsCollection - .new(resource_descriptions) - .filter( - resource_id: resource_id, - method_name: method_name, - version: version - ) + .new(resource_descriptions) + .filter( + resource_id: resource_id, + method_name: method_name, + version: version + ) Apipie::SwaggerGenerator.generate_from_resources( resources, diff --git a/lib/apipie/generator/swagger/method_description/api_schema_service.rb b/lib/apipie/generator/swagger/method_description/api_schema_service.rb index 596b3488a..9b8df904b 100644 --- a/lib/apipie/generator/swagger/method_description/api_schema_service.rb +++ b/lib/apipie/generator/swagger/method_description/api_schema_service.rb @@ -17,8 +17,8 @@ def call end parameters = Apipie::Generator::Swagger::MethodDescription::ParametersService - .new(@method_description, path: path, http_method: api.normalized_http_method) - .call + .new(@method_description, path: path, http_method: api.normalized_http_method) + .call paths[path.swagger_path(@method_description)] ||= {} paths[path.swagger_path(@method_description)][api.normalized_http_method] = { diff --git a/lib/apipie/generator/swagger/method_description/parameters_service.rb b/lib/apipie/generator/swagger/method_description/parameters_service.rb index 0b7a35dd7..aa4a7c096 100644 --- a/lib/apipie/generator/swagger/method_description/parameters_service.rb +++ b/lib/apipie/generator/swagger/method_description/parameters_service.rb @@ -40,7 +40,7 @@ def body_params_schema if Apipie.configuration.generator.swagger.json_input_uses_refs? composite = composite - .referenced("#{@method_description.operation_id}_input") + .referenced("#{@method_description.operation_id}_input") end swagger_schema_for_body = composite.to_swagger @@ -80,7 +80,7 @@ def all_params warn_path_parameter_not_described(name, @path) result[name.to_sym] = Apipie::Generator::Swagger::ParamDescription - .create_for_missing_param(@method_description, name) + .create_for_missing_param(@method_description, name) end result @@ -89,15 +89,15 @@ def all_params def body_param_descriptions @body_param_descriptions ||= all_params - .reject { |k, _| @path.param?(k) } - .values + .reject { |k, _| @path.param?(k) } + .values end def path_param_descriptions @path_param_descriptions ||= all_params - .select { |k, _| @path.param?(k) } - .each_value { |desc| desc.required = true } - .values + .select { |k, _| @path.param?(k) } + .each_value { |desc| desc.required = true } + .values end # @return [Array] diff --git a/lib/apipie/generator/swagger/param_description/path_params_composite.rb b/lib/apipie/generator/swagger/param_description/path_params_composite.rb index 8e1783fe8..c7505c9c3 100644 --- a/lib/apipie/generator/swagger/param_description/path_params_composite.rb +++ b/lib/apipie/generator/swagger/param_description/path_params_composite.rb @@ -26,21 +26,21 @@ def to_swagger context.add_to_prefix!(desc.name) out = Apipie::Generator::Swagger::ParamDescription::PathParamsComposite - .new(desc.validator.params_ordered, context) - .to_swagger + .new(desc.validator.params_ordered, context) + .to_swagger @result.concat(out) else param_entry = Apipie::Generator::Swagger::ParamDescription::Builder - .new(desc, in_schema: false, controller_method: context.controller_method) - .with_description(language: context.language) - .with_name(prefix: context.prefix) - .with_type(with_null: context.allow_null?) - .with_in( - http_method: context.http_method, - default_in_value: context.default_in_value - ).to_swagger + .new(desc, in_schema: false, controller_method: context.controller_method) + .with_description(language: context.language) + .with_name(prefix: context.prefix) + .with_type(with_null: context.allow_null?) + .with_in( + http_method: context.http_method, + default_in_value: context.default_in_value + ).to_swagger @result << param_entry end diff --git a/lib/apipie/generator/swagger/resource_description_composite.rb b/lib/apipie/generator/swagger/resource_description_composite.rb index 6f42e93ea..a7c7c11c6 100644 --- a/lib/apipie/generator/swagger/resource_description_composite.rb +++ b/lib/apipie/generator/swagger/resource_description_composite.rb @@ -41,11 +41,11 @@ def paths next unless method_description.show result = Apipie::Generator::Swagger::MethodDescription::ApiSchemaService - .new( - Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description), - language: @language - ) - .call + .new( + Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description), + language: @language + ) + .call results.deep_merge!(result) end diff --git a/lib/apipie/static_dispatcher.rb b/lib/apipie/static_dispatcher.rb index 357c168d1..984d5ae75 100644 --- a/lib/apipie/static_dispatcher.rb +++ b/lib/apipie/static_dispatcher.rb @@ -16,8 +16,8 @@ def initialize(root) def match?(path) # Replace all null bytes path = ::Rack::Utils.unescape(path || '') - .encode(Encoding::UTF_8, invalid: :replace, replace: '') - .gsub("\x0", '') + .encode(Encoding::UTF_8, invalid: :replace, replace: '') + .gsub("\x0", '') full_path = path.empty? ? @root : File.join(@root, path) paths = "#{full_path}#{ext}" diff --git a/spec/controllers/pets_controller_spec.rb b/spec/controllers/pets_controller_spec.rb index b2ced196b..6490f637d 100644 --- a/spec/controllers/pets_controller_spec.rb +++ b/spec/controllers/pets_controller_spec.rb @@ -4,7 +4,7 @@ require 'apipie/rspec/response_validation_helper' require "json-schema" -RSpec.describe PetsController, :type => :controller do +RSpec.describe PetsController do it "does not raise error when rendered output matches the described response" do response = get :return_and_validate_expected_response, format: :json expect(response).to match_declared_responses diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4bec5290a..727b9b5d6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,8 +61,11 @@ def fail(msg) config.mock_with :rspec - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{Rails.root}/spec/fixtures" + if Rails.version >= "7.1" + config.fixture_paths = ["#{Rails.root}/spec/fixtures"] + else + config.fixture_path = "#{Rails.root}/spec/fixtures" + end # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false