8000 rework conditional loading of the OAS plugins by giograno · Pull Request #11585 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content
8000

rework conditional loading of the OAS plugins #11585

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
Sep 27, 2024
Merged
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
7 changes: 6 additions & 1 deletion localstack-core/localstack/aws/handlers/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class OpenAPIValidator(Handler):
open_apis: list["OpenAPI"]

def __init__(self) -> None:
# avoid to load the specs if we don't have to perform any validation
self._load_specs()

def _load_specs(self) -> None:
"""Load the openapi spec plugins iff at least one between request and response validation is set."""
if not (config.OPENAPI_VALIDATE_REQUEST or config.OPENAPI_VALIDATE_RESPONSE):
return
specs = PluginManager("localstack.openapi.spec").load_all()
Expand All @@ -92,6 +95,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
if not config.OPENAPI_VALIDATE_REQUEST:
return

hasattr(self, "open_apis") or self._load_specs()
Copy link
Member

Choose a reason for hiding this comment

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

It might be cleaner to move the conditional into _load_specs() but yes, it will impact the performance due to the extra call

path = context.request.path

if path.startswith(f"{INTERNAL_RESOURCE_PATH}/") or path.startswith("/_aws/"):
Expand Down Expand Up @@ -119,6 +123,7 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
if not config.OPENAPI_VALIDATE_RESPONSE:
return

hasattr(self, "open_apis") or self._load_specs()
path = context.request.path

if path.startswith(f"{INTERNAL_RESOURCE_PATH}/") or path.startswith("/_aws/"):
Expand Down
Loading
0