Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor decorators #1618

Merged
merged 3 commits into from
Jan 7, 2023
Merged

Refactor decorators #1618

merged 3 commits into from
Jan 7, 2023

Conversation

RobbeSneyders
Copy link
Member

This PR refactors the decorators so they can be used independently of an API, which will allow them to be used by other wrapped frameworks as well.

@RobbeSneyders RobbeSneyders added this to the Connexion 3.0 milestone Jan 3, 2023
@RobbeSneyders RobbeSneyders requested a review from Ruwann January 3, 2023 21:29
@RobbeSneyders RobbeSneyders force-pushed the feature/refactor-decorators branch from 0e7faef to de3b6f6 Compare January 3, 2023 21:38
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3833178906

  • 334 of 397 (84.13%) changed or added relevant lines in 17 files are covered.
  • 14 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.2%) to 90.759%

Changes Missing Coverage Covered Lines Changed/Added Lines %
connexion/frameworks/flask.py 51 52 98.08%
connexion/handlers.py 5 6 83.33%
connexion/decorators/parameter.py 29 31 93.55%
connexion/apps/async_app.py 2 5 40.0%
connexion/frameworks/abstract.py 16 21 76.19%
connexion/frameworks/starlette.py 35 48 72.92%
connexion/decorators/response.py 81 98 82.65%
connexion/decorators/main.py 74 95 77.89%
Files with Coverage Reduction New Missed Lines %
connexion/apis/abstract.py 1 97.3%
connexion/operations/abstract.py 5 75.56%
connexion/utils.py 8 92.9%
Totals Coverage Status
Change from base Build 3808719842: -0.2%
Covered Lines: 3084
Relevant Lines: 3398

💛 - Coveralls

Copy link
Member Author

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review


MODULE_PATH = pathlib.Path(__file__).absolute().parent.parent
SWAGGER_UI_URL = "ui"

logger = logging.getLogger("connexion.apis.abstract")


class AbstractAPIMeta(abc.ABCMeta):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see a reason for this to be a Metaclass. I would still like to rework how the jsonifier is defined and passed around.

@@ -41,7 +41,7 @@ def wrapped_default(self, o):
if isinstance(o, uuid.UUID):
return str(o)

return default_fn(o)
return default_fn(self, o)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're wrapping a method.

@@ -243,45 +228,20 @@ def get_mimetype(self):
return DEFAULT_MIMETYPE

@property
def _uri_parsing_decorator(self):
def uri_parser_class(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer not to pass this via the operation. We can probably handle it similarly to the Jsonifier.


# TODO: don't default
produces = list(set(self.operation.produces))
if data is not None and not produces:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps backward compatibility, although I don't think we should. We should expect the spec to define a content type when a response is returned.

https://swagger.io/specification/v2/#responseObject

  • A missing response schema defines an empty response
  • If a response schema is present, produces should be defined

In OpenAPI 3, a response cannot be defined without its content type.

@@ -139,7 +139,12 @@ def test_pass_through(simple_app):
app_client = simple_app.app.test_client()

response = app_client.get("/v1.0/multimime", data={}) # type: flask.Response
assert response.status_code == 200
assert response.status_code == 500
assert (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change of behavior. If the spec defines multiple content types, we should not guess.

@@ -1,67 +1,116 @@
from unittest.mock import MagicMock

from connexion.decorators.parameter import parameter_to_arg, pythonic
from connexion.decorators.parameter import (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test both Sync & Async decorator. Refactored to work with new decorators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants