Skip to content

Commit

Permalink
Allow skipping apispec validation check on app startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dolamroth committed Feb 11, 2024
1 parent 7898a7b commit 69e891a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/contrib/apispec.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ inner registry by class name. If any 2 classes have same name, APIspec struggles
schema class for introspection and gives up. This results in invalid OpenAPI, where schema is mentioned,
but its definition is missing.

**Note**: Validation is performed on each `app` startup, which includes uvicorn worker restarts.
To disable validation in production, set `settings.APISPEC_PERFORM_CHECKS_ON_STARTUP` to `False`.

### Camel case support

`contrib.camel_case` provides helper methods and classes to convert `snake_case` to `camelCase` and vice versa.
Expand Down
4 changes: 4 additions & 0 deletions starlette_web/common/conf/global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@

EMAIL_SENDER = None

# Contrib.apispec

APISPEC_PERFORM_CHECKS_ON_STARTUP = True

# Contrib.auth

AUTH_PASSWORD_HASHERS = [
Expand Down
6 changes: 6 additions & 0 deletions starlette_web/contrib/apispec/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class AppConfig(BaseAppConfig):
app_name = "apispec"

def initialize(self):
if not settings.APISPEC_PERFORM_CHECKS_ON_STARTUP:
return

try:
__import__("openapi_spec_validator")
except (SystemError, ImportError):
Expand All @@ -24,6 +27,9 @@ def initialize(self):
)

def perform_checks(self):
if not settings.APISPEC_PERFORM_CHECKS_ON_STARTUP:
return

from openapi_spec_validator import validate
from openapi_spec_validator.validation.exceptions import (
OpenAPIValidationError,
Expand Down

0 comments on commit 69e891a

Please sign in to comment.