10
10
from werkzeug .datastructures import Headers
11
11
from werkzeug .exceptions import HTTPException
12
12
13
- from .typing import Model , ResponseReturnValue , ResponseValue
13
+ from .typing import Model , PydanticDumpOptions , ResponseReturnValue , ResponseValue
14
14
15
15
try :
16
16
from pydantic import (
@@ -100,14 +100,14 @@ def convert_response_return_value(
100
100
value = model_dump (
101
101
value ,
102
102
camelize = current_app .config ["QUART_SCHEMA_CONVERT_CASING" ],
103
- by_alias = current_app .config ["QUART_SCHEMA_BY_ALIAS" ],
104
103
preference = current_app .config ["QUART_SCHEMA_CONVERSION_PREFERENCE" ],
104
+ pydantic_kwargs = current_app .config ["QUART_SCHEMA_PYDANTIC_DUMP_OPTIONS" ],
105
105
)
106
106
headers = model_dump (
107
107
headers , # type: ignore
108
108
kebabize = True ,
109
- by_alias = current_app .config ["QUART_SCHEMA_BY_ALIAS" ],
110
109
preference = current_app .config ["QUART_SCHEMA_CONVERSION_PREFERENCE" ],
110
+ pydantic_kwargs = current_app .config ["QUART_SCHEMA_PYDANTIC_DUMP_OPTIONS" ],
111
111
)
112
112
113
113
new_result : ResponseReturnValue
@@ -128,23 +128,23 @@ def convert_response_return_value(
128
128
def model_dump (
129
129
raw : ResponseValue ,
130
130
* ,
131
- by_alias : bool ,
132
131
camelize : bool = False ,
133
132
kebabize : bool = False ,
134
133
preference : Optional [str ] = None ,
134
+ pydantic_kwargs : Optional [PydanticDumpOptions ] = None ,
135
135
) -> dict | list :
136
136
if is_pydantic_dataclass (type (raw )):
137
- value = RootModel [type (raw )](raw ).model_dump () # type: ignore
137
+ value = RootModel [type (raw )](raw ).model_dump (** ( pydantic_kwargs or {}) ) # type: ignore
138
138
elif isinstance (raw , BaseModel ):
139
- value = raw .model_dump (by_alias = by_alias )
139
+ value = raw .model_dump (** ( pydantic_kwargs or {}) )
140
140
elif isinstance (raw , Struct ) or is_attrs (raw ): # type: ignore
141
141
value = to_builtins (raw )
142
142
elif (
143
143
(isinstance (raw , (list , dict )) or is_dataclass (raw ))
144
144
and PYDANTIC_INSTALLED
145
145
and preference != "msgspec"
146
146
):
147
- value = TypeAdapter (type (raw )).dump_python (raw )
147
+ value = TypeAdapter (type (raw )).dump_python (raw , ** ( pydantic_kwargs or {}) )
148
148
elif (
149
149
(isinstance (raw , (list , dict )) or is_dataclass (raw ))
150
150
and MSGSPEC_INSTALLED
0 commit comments