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

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

rework conditional loading of the OAS plugins #11585

merged 1 commit into from
Sep 27, 2024

Conversation

giograno
Copy link
Member

Motivation

When we introduced the validation for the internal endpoints based on the OpenAPI specs, we made sure the correspondent plugins and specs wouldn't be loaded if at least one between OPENAPI_VALIDATE_REQUEST or OPENAPI_VALIDATE_RESPONSE.
The idea was to avoid this step, when unnecessary.

However, this is an issue if we turn these config variables when the container is already started, and the chain initialized.
In such a case, the calls to the validators fail because the instance variable open_apis hasn't been initialized (I came across this while writing some tests).

To support the later activation of the validation at runtime, we slightly reworked the loading logic.

Changes

  • We use the same old logic when instantiating the validator classes. However, when calling the handler we look for the open_apis attribute and eventually perform the loading.

@giograno giograno added the semver: patch Non-breaking changes which can be included in patch releases label Sep 25, 2024
@giograno giograno self-assigned this Sep 25, 2024
Copy link

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 37m 35s ⏱️ +43s
3 443 tests ±0  3 045 ✅ ±0  398 💤 ±0  0 ❌ ±0 
3 445 runs  ±0  3 045 ✅ ±0  400 💤 ±0  0 ❌ ±0 

Results for commit 2e3ca48. ± Comparison against base commit 83f7b3c.

@giograno giograno marked this pull request as ready for review September 26, 2024 00:56
@giograno giograno requested a review from thrau as a code owner September 26, 2024 00:56
@@ -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

@giograno giograno merged commit b11d2ba into master Sep 27, 2024
37 checks passed
@giograno giograno deleted the load-specs branch September 27, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0