rswag-specs/lib/rswag/specs/request_factory.rb

Summary

Maintainability
D
1 day
Test Coverage

Method build_query_string_part has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

      def build_query_string_part(param, value, swagger_doc)
        name = param[:name]
        escaped_name = CGI.escape(name.to_s)

        # OAS 3: https://swagger.io/docs/specification/serialization/
Severity: Minor
Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method add_headers has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def add_headers(request, metadata, swagger_doc, parameters, example)
        tuples = parameters
          .select { |p| p[:in] == :header }
          .map { |p| [p[:name], example.send(extract_getter(p)).to_s] }

Severity: Minor
Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method build_query_string_part has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def build_query_string_part(param, value, swagger_doc)
        name = param[:name]
        escaped_name = CGI.escape(name.to_s)

        # OAS 3: https://swagger.io/docs/specification/serialization/
Severity: Minor
Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 1 hr to fix

    Method add_path has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def add_path(request, metadata, swagger_doc, parameters, example)
            open_api_3_doc = doc_version(swagger_doc).start_with?('3')
            uses_base_path = swagger_doc[:basePath].present?
    
            if open_api_3_doc && uses_base_path
    Severity: Minor
    Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method add_headers has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def add_headers(request, metadata, swagger_doc, parameters, example)
            tuples = parameters
              .select { |p| p[:in] == :header }
              .map { |p| [p[:name], example.send(extract_getter(p)).to_s] }
    
    
    Severity: Minor
    Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 1 hr to fix

      Method add_headers has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def add_headers(request, metadata, swagger_doc, parameters, example)
      Severity: Minor
      Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 35 mins to fix

        Method add_path has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def add_path(request, metadata, swagger_doc, parameters, example)
        Severity: Minor
        Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 35 mins to fix

          Method expand_parameters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def expand_parameters(metadata, swagger_doc, example)
                  operation_params = metadata[:operation][:parameters] || []
                  path_item_params = metadata[:path_item][:parameters] || []
                  security_params = derive_security_params(metadata, swagger_doc)
          
          
          Severity: Minor
          Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid too many return statements within this method.
          Open

                        return "#{escaped_name}=" + value.to_a.flatten.map{|v| CGI.escape(v.to_s) }.join(separator)
          Severity: Major
          Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return "#{escaped_name}=#{CGI.escape(value.to_s)}" unless type&.to_sym == :array
            Severity: Major
            Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return "#{name}=#{value}"
              Severity: Major
              Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 30 mins to fix

                Method security_version has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def security_version(scheme_names, swagger_doc)
                        if doc_version(swagger_doc).start_with?('2')
                          (swagger_doc[:securityDefinitions] || {}).slice(*scheme_names).values
                        else # Openapi3
                          if swagger_doc.key?(:securityDefinitions)
                Severity: Minor
                Found in rswag-specs/lib/rswag/specs/request_factory.rb - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                There are no issues that match your filters.

                Category
                Status