slim/ext/openapi/main.py

Summary

Maintainability
F
4 days
Test Coverage

Function _build_paths has a Cognitive Complexity of 122 (exceeds 5 allowed). Consider refactoring.
Open

    def _build_paths(self):
        from slim.base.view import BaseView, AbstractSQLView
        paths = {}

        def returning_wrap(items_schema):
Severity: Minor
Found in slim/ext/openapi/main.py - About 2 days 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

File main.py has 395 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
from copy import deepcopy
from typing import Type, TYPE_CHECKING

from slim.base.types import BuiltinInterface
Severity: Minor
Found in slim/ext/openapi/main.py - About 5 hrs to fix

    Function _build_main has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def _build_main(self):
            from ...base.view import RequestView
            doc_info = self.app.doc_info
    
            self.openapi_file = {
    Severity: Minor
    Found in slim/ext/openapi/main.py - 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

    Function _sql_views_check has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def _sql_views_check(self):
            from slim.base.permission import Ability, A
            from slim.base.view import BaseView, AbstractSQLView
            app = self.app
    
    
    Severity: Minor
    Found in slim/ext/openapi/main.py - 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

    Avoid deeply nested control flow statements.
    Open

                            if i.builtin_interface == BuiltinInterface.BULK_INSERT:
                                if view_info['sql_cant_create']:
                                    continue
                                add_returning_header()
                                request_body_schema = {
    Severity: Major
    Found in slim/ext/openapi/main.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if i.builtin_interface == BuiltinInterface.LIST:
                                  page_info = deepcopy(paginate_schema)
                                  page_info["properties"]["items"] = {
                                      "type": "array",
                                      "description": "数据项",
      Severity: Major
      Found in slim/ext/openapi/main.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if i.builtin_interface == BuiltinInterface.SET:
                                    if view_info['sql_cant_write']:
                                        continue
                                    add_bulk_header()
                                    add_returning_header()
        Severity: Major
        Found in slim/ext/openapi/main.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if sql_query:
                                      parameters.extend(view_info['sql_query_parameters'])
          
          
          Severity: Major
          Found in slim/ext/openapi/main.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if i.builtin_interface == BuiltinInterface.DELETE:
                                        if view_info['sql_cant_delete']:
                                            continue
                                        add_bulk_header()
                                        request_body_schema = {
            Severity: Major
            Found in slim/ext/openapi/main.py - About 45 mins to fix

              Function _interface_solve has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _interface_solve(self, beacon_info: RouteInterfaceInfo, method, parameters, request_body_schema):
                      if beacon_info.va_query:
                          for k, v in beacon_info.va_query._fields.items():
                              parameters.append(self._schematics_field_to_parameter(k, v))
              
              
              Severity: Minor
              Found in slim/ext/openapi/main.py - About 45 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 deeply nested control flow statements.
              Open

                                      if i.builtin_interface == BuiltinInterface.LIST:
                                          parameters.extend([
                                              {
                                                  "name": "page",
                                                  "in": "path",
              Severity: Major
              Found in slim/ext/openapi/main.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if i.builtin_interface == BuiltinInterface.NEW:
                                            if view_info['sql_cant_create']:
                                                continue
                                            add_returning_header()
                                            request_body_schema = {
                Severity: Major
                Found in slim/ext/openapi/main.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                              if f:
                                                  doc = f.__doc__
                                                  if doc: doc = doc.strip()
                                                  if doc: break
                  
                  
                  Severity: Major
                  Found in slim/ext/openapi/main.py - About 45 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status