|
2 | 2 |
|
3 | 3 | from dataclasses import fields, is_dataclass
|
4 | 4 | from inspect import isclass
|
5 |
| -from typing import Any, Dict, List, Optional, Type, TypeVar, Union |
| 5 | +from typing import Any, Dict, List, Literal, Optional, Type, TypeVar, Union |
6 | 6 |
|
7 | 7 | import humps
|
8 | 8 | from quart import current_app
|
@@ -73,6 +73,8 @@ class MsgSpecValidationError(Exception): # type: ignore
|
73 | 73 |
|
74 | 74 | T = TypeVar("T", bound=Model)
|
75 | 75 |
|
| 76 | +JsonSchemaMode = Literal['validation', 'serialization'] |
| 77 | + |
76 | 78 |
|
77 | 79 | def convert_response_return_value(
|
78 | 80 | result: ResponseReturnValue | HTTPException,
|
@@ -184,9 +186,9 @@ def model_load(
|
184 | 186 | raise exception_class(error)
|
185 | 187 |
|
186 | 188 |
|
187 |
| -def model_schema(model_class: Type[Model], *, preference: Optional[str] = None) -> dict: |
| 189 | +def model_schema(model_class: Type[Model], *, preference: Optional[str] = None, schema_mode: JsonSchemaMode = "validation") -> dict: |
188 | 190 | if _use_pydantic(model_class, preference):
|
189 |
| - return TypeAdapter(model_class).json_schema(ref_template=PYDANTIC_REF_TEMPLATE) |
| 191 | + return TypeAdapter(model_class).json_schema(ref_template=PYDANTIC_REF_TEMPLATE, mode=schema_mode) |
190 | 192 | elif _use_msgspec(model_class, preference):
|
191 | 193 | _, schema = schema_components([model_class], ref_template=MSGSPEC_REF_TEMPLATE)
|
192 | 194 | return list(schema.values())[0]
|
|
0 commit comments