Skip to content

validate_request and validate_response return value deprecation fix #589

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

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions openapi_core/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Optional
from typing import Union

from lazy_object_proxy import Proxy

from openapi_core.exceptions import SpecError
from openapi_core.finders import SpecClasses
from openapi_core.finders import SpecFinder
Expand Down Expand Up @@ -317,19 +319,24 @@ def validate_request(
if cls is None or issubclass(
cls, (RequestUnmarshaller, WebhookRequestUnmarshaller)
):
warnings.warn(
"validate_request is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_request function instead.",
DeprecationWarning,
)
return unmarshal_request(
result = unmarshal_request(
request,
spec=spec,
base_url=base_url,
cls=cls,
**validator_kwargs,
)

def return_result() -> RequestUnmarshalResult:
warnings.warn(
"validate_request is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_request function instead.",
DeprecationWarning,
)
return result

return Proxy(return_result) # type: ignore
if isinstance(request, WebhookRequest):
if cls is None or issubclass(cls, WebhookRequestValidator):
validate_webhook_request(
Expand Down Expand Up @@ -400,20 +407,25 @@ def validate_response(
if cls is None or issubclass(
cls, (ResponseUnmarshaller, WebhookResponseUnmarshaller)
):
warnings.warn(
"validate_response is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_response function instead.",
DeprecationWarning,
)
return unmarshal_response(
result = unmarshal_response(
request,
response,
spec=spec,
base_url=base_url,
cls=cls,
**validator_kwargs,
)

def return_result() -> ResponseUnmarshalResult:
warnings.warn(
"validate_response is deprecated for unmarshalling data "
"and it will not return any result in the future. "
"Use unmarshal_response function instead.",
DeprecationWarning,
)
return result

return Proxy(return_result) # type: ignore
if isinstance(request, WebhookRequest):
if cls is None or issubclass(cls, WebhookResponseValidator):
validate_webhook_response(
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module = [
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "lazy_object_proxy.*"
ignore_missing_imports = true

[tool.poetry]
name = "openapi-core"
version = "0.17.1"
Expand Down Expand Up @@ -74,6 +78,7 @@ backports-cached-property = {version = "^1.0.2", python = "<3.8" }
asgiref = "^3.6.0"
jsonschema = "^4.17.3"
multidict = {version = "^6.0.4", optional = true}
lazy-object-proxy = "^1.7.1"

[tool.poetry.extras]
django = ["django"]
Expand Down
Loading