Replace assert with proper exceptions in OpenAPI extension

assert statements are stripped with python -O. Use ValueError for
duplicate schema registration and RuntimeError for missing static
route configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 18:08:16 -04:00
parent 868f84fc8b
commit f194efecae
+4 -3
View File
@@ -174,8 +174,8 @@ class OpenAPISchema:
def add_schema(self, name, schema, check_existing=True):
"""Adds a marshmallow or Pydantic schema to the API specification."""
if check_existing:
assert name not in self.schemas
assert name not in self.pydantic_schemas
if name in self.schemas or name in self.pydantic_schemas:
raise ValueError(f"Schema '{name}' is already registered")
if _is_pydantic_model(schema):
self.pydantic_schemas[name] = schema
@@ -221,7 +221,8 @@ class OpenAPISchema:
def static_url(self, asset):
"""Given a static asset, return its URL path."""
assert self.static_route is not None
if self.static_route is None:
raise RuntimeError("Cannot generate static URL: static_route is disabled")
return f"{self.static_route}/{str(asset)}"
def docs_response(self, req, resp):