@@ -199,6 +199,34 @@ def get_dependant(
199
199
else :
200
200
add_param_to_fields (field = param_field , dependant = dependant )
201
201
202
+ _add_return_annotation (dependant , endpoint_signature )
203
+ _add_extra_responses (dependant , responses )
204
+
205
+ return dependant
206
+
207
+
208
+ def _add_extra_responses (dependant : Dependant , responses : Optional [Dict [int , OpenAPIResponse ]]):
209
+ # Also add the optional extra responses to the dependant model.
210
+ if not responses :
211
+ return
212
+
213
+ for response in responses .values ():
214
+ for schema in response .get ("content" , {}).values ():
215
+ if "model" in schema :
216
+ response_field = analyze_param (
217
+ param_name = "return" ,
218
+ annotation = cast (OpenAPIResponseContentModel , schema )["model" ],
219
+ value = None ,
220
+ is_path_param = False ,
221
+ is_response_param = True ,
222
+ )
223
+ if response_field is None :
224
+ raise AssertionError ("Response field is None for response model" )
225
+
226
+ dependant .response_extra_models .append (response_field )
227
+
228
+
229
+ def _add_return_annotation (dependant : Dependant , endpoint_signature : inspect .Signature ):
202
230
# If the return annotation is not empty, add it to the dependant model.
203
231
return_annotation = endpoint_signature .return_annotation
204
232
if return_annotation is not inspect .Signature .empty :
@@ -214,26 +242,6 @@ def get_dependant(
214
242
215
243
dependant .return_param = param_field
216
244
217
- # Also add the optional extra responses to the dependant model.
218
- if responses :
219
- for response in responses .values ():
220
- if "content" in response :
221
- for schema in response ["content" ].values ():
222
- if "model" in schema :
223
- response_field = analyze_param (
224
- param_name = "return" ,
225
- annotation = cast (OpenAPIResponseContentModel , schema )["model" ],
226
- value = None ,
227
- is_path_param = False ,
228
- is_response_param = True ,
229
- )
230
- if response_field is None :
231
- raise AssertionError ("Response field is None for response model" )
232
-
233
- dependant .response_extra_models .append (response_field )
234
-
235
- return dependant
236
-
237
245
238
246
def is_body_param (* , param_field : ModelField , is_path_param : bool ) -> bool :
239
247
"""
0 commit comments