zalando/connexion

View on GitHub
connexion/operations/openapi.py

Summary

Maintainability
D
2 days
Test Coverage

File openapi.py has 310 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from copy import copy, deepcopy

from connexion.operations.abstract import AbstractOperation

Severity: Minor
Found in connexion/operations/openapi.py - About 3 hrs to fix

    Function __init__ has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, api, method, path, operation, resolver, path_parameters=None,
    Severity: Major
    Found in connexion/operations/openapi.py - About 1 hr to fix

      Function _get_typed_body_values has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_typed_body_values(self, body_arg, body_props, additional_props):
              """
              Return a copy of the provided body_arg dictionary
              whose values will have the appropriate types
              as defined in the provided schemas.
      Severity: Minor
      Found in connexion/operations/openapi.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 from_spec has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def from_spec(cls, spec, api, path, method, resolver, *args, **kwargs):
      Severity: Major
      Found in connexion/operations/openapi.py - About 50 mins to fix

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

            def _get_body_argument(self, body, arguments, has_kwargs, sanitize):
                x_body_name = sanitize(self.body_schema.get('x-body-name', 'body'))
                if is_nullable(self.body_schema) and is_null(body):
                    return {x_body_name: None}
        
        
        Severity: Minor
        Found in connexion/operations/openapi.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 too many return statements within this function.
        Open

                    return (None, status_code)
        Severity: Major
        Found in connexion/operations/openapi.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return {}
          Severity: Major
          Found in connexion/operations/openapi.py - About 30 mins to fix

            Function _get_query_defaults has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_query_defaults(self, query_defns):
                    defaults = {}
                    for k, v in query_defns.items():
                        try:
                            if v["schema"]["type"] == "object":
            Severity: Minor
            Found in connexion/operations/openapi.py - 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

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                def _nested_example(self, schema):
                    try:
                        return schema["example"]
                    except KeyError:
                        pass
            Severity: Major
            Found in connexion/operations/openapi.py and 1 other location - About 5 hrs to fix
            connexion/operations/swagger2.py on lines 208..222

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 89.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if query_schema["type"] == "array":
                        return [make_type(part, query_schema["items"]["type"]) for part in value]
                    else:
                        return make_type(value, query_schema["type"])
            Severity: Major
            Found in connexion/operations/openapi.py and 1 other location - About 2 hrs to fix
            connexion/operations/swagger2.py on lines 307..310

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 59.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    super(OpenAPIOperation, self).__init__(
            Severity: Major
            Found in connexion/operations/openapi.py and 1 other location - About 2 hrs to fix
            connexion/operations/swagger2.py on lines 82..82

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 55.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if path_schema.get('type') == 'string' and path_schema.get('format') == 'path':
                            # path is special case for type 'string'
                            path_type = 'path'
                        else:
                            path_type = path_schema.get('type')
            Severity: Major
            Found in connexion/operations/openapi.py and 1 other location - About 2 hrs to fix
            connexion/operations/swagger2.py on lines 156..160

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 50.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                    query_defns = {sanitize(p["name"]): p
                                   for p in self.parameters
                                   if p["in"] == "query"}
            Severity: Major
            Found in connexion/operations/openapi.py and 2 other locations - About 1 hr to fix
            connexion/operations/swagger2.py on lines 250..252
            connexion/operations/swagger2.py on lines 268..270

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                    try:
                        return (self._nested_example(deep_get(self._responses, schema_path)),
                                status_code)
                    except KeyError:
                        return (None, status_code)
            Severity: Minor
            Found in connexion/operations/openapi.py and 1 other location - About 30 mins to fix
            connexion/operations/swagger2.py on lines 202..206

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status