Skip to content

Commit

Permalink
Allow the Pydantic Dump Options to be specified on construction
Browse files Browse the repository at this point in the history
This is more typesafe and convenient.
  • Loading branch information
pgjones committed May 15, 2024
1 parent abf72c1 commit de59ee6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/quart_schema/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Server,
Tag,
)
from .typing import PydanticDumpOptions
from .validation import (
DataSource,
QUART_SCHEMA_HEADERS_ATTRIBUTE,
Expand Down Expand Up @@ -217,6 +218,7 @@ def __init__(
security: Optional[List[Dict[str, List[str]]]] = None,
external_docs: Optional[Union[ExternalDocumentation, dict]] = None,
conversion_preference: Literal["msgspec", "pydantic", None] = None,
pydantic_dump_options: Optional[PydanticDumpOptions] = None,
) -> None:
self.openapi_path = openapi_path
self.redoc_ui_path = redoc_ui_path
Expand All @@ -225,6 +227,7 @@ def __init__(

self.convert_casing = convert_casing
self.conversion_preference = conversion_preference
self.pydantic_dump_options = {} if pydantic_dump_options is None else pydantic_dump_options

self.info: Optional[Info] = None
if info is not None:
Expand Down Expand Up @@ -299,7 +302,7 @@ def init_app(self, app: Quart) -> None:
"QUART_SCHEMA_SCALAR_JS_URL",
"https://cdn.jsdelivr.net/npm/@scalar/api-reference",
)
app.config.setdefault("QUART_SCHEMA_PYDANTIC_DUMP_OPTIONS", {})
app.config.setdefault("QUART_SCHEMA_PYDANTIC_DUMP_OPTIONS", self.pydantic_dump_options)
app.config.setdefault("QUART_SCHEMA_CONVERT_CASING", self.convert_casing)
app.config.setdefault("QUART_SCHEMA_CONVERSION_PREFERENCE", self.conversion_preference)
app.json = create_json_provider(app)
Expand Down

0 comments on commit de59ee6

Please sign in to comment.