11import inspect
2- from typing import Any , Callable , List , Optional , Type , Union , cast , get_type_hints
2+ from typing import (
3+ Any ,
4+ Callable ,
5+ Dict ,
6+ List ,
7+ Optional ,
8+ Type ,
9+ Union ,
10+ cast ,
11+ get_type_hints ,
12+ )
313
414from ninja .constants import NOT_SET
515from ninja .signature import is_async
@@ -45,6 +55,7 @@ def __init__(
4555 url_name : Optional [str ] = None ,
4656 include_in_schema : bool = True ,
4757 permissions : Optional [List [Type [BasePermission ]]] = None ,
58+ openapi_extra : Optional [Dict [str , Any ]] = None ,
4859 ) -> None :
4960
5061 if not isinstance (methods , list ):
@@ -97,6 +108,7 @@ def __init__(
97108 exclude_none = exclude_none ,
98109 url_name = url_name ,
99110 include_in_schema = include_in_schema ,
111+ openapi_extra = openapi_extra ,
100112 )
101113 self .route_params = ninja_route_params
102114 self .is_async = is_async (view_func )
@@ -124,6 +136,7 @@ def _create_route_function(
124136 url_name : Optional [str ] = None ,
125137 include_in_schema : bool = True ,
126138 permissions : Optional [List [Type [BasePermission ]]] = None ,
139+ openapi_extra : Optional [Dict [str , Any ]] = None ,
127140 ) -> RouteFunction :
128141 if response is NOT_SET :
129142 response = get_type_hints (view_func ).get ("return" ) or NOT_SET
@@ -145,6 +158,7 @@ def _create_route_function(
145158 url_name = url_name ,
146159 include_in_schema = include_in_schema ,
147160 permissions = permissions ,
161+ openapi_extra = openapi_extra ,
148162 )
149163 route_function_class = RouteFunction
150164 if route_obj .is_async :
@@ -171,6 +185,7 @@ def get(
171185 url_name : Optional [str ] = None ,
172186 include_in_schema : bool = True ,
173187 permissions : Optional [List [Type [BasePermission ]]] = None ,
188+ openapi_extra : Optional [Dict [str , Any ]] = None ,
174189 ) -> Callable [[TCallable ], RouteFunction ]:
175190 """
176191 A GET Operation method decorator
@@ -218,6 +233,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
218233 url_name = url_name ,
219234 include_in_schema = include_in_schema ,
220235 permissions = permissions ,
236+ openapi_extra = openapi_extra ,
221237 )
222238
223239 return decorator
@@ -241,6 +257,7 @@ def post(
241257 url_name : Optional [str ] = None ,
242258 include_in_schema : bool = True ,
243259 permissions : Optional [List [Type [BasePermission ]]] = None ,
260+ openapi_extra : Optional [Dict [str , Any ]] = None ,
244261 ) -> Callable [[TCallable ], RouteFunction ]:
245262 """
246263 A POST Operation method decorator
@@ -288,6 +305,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
288305 url_name = url_name ,
289306 include_in_schema = include_in_schema ,
290307 permissions = permissions ,
308+ openapi_extra = openapi_extra ,
291309 )
292310
293311 return decorator
@@ -311,6 +329,7 @@ def delete(
311329 url_name : Optional [str ] = None ,
312330 include_in_schema : bool = True ,
313331 permissions : Optional [List [Type [BasePermission ]]] = None ,
332+ openapi_extra : Optional [Dict [str , Any ]] = None ,
314333 ) -> Callable [[TCallable ], RouteFunction ]:
315334 """
316335 A DELETE Operation method decorator
@@ -358,6 +377,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
358377 url_name = url_name ,
359378 include_in_schema = include_in_schema ,
360379 permissions = permissions ,
380+ openapi_extra = openapi_extra ,
361381 )
362382
363383 return decorator
@@ -381,6 +401,7 @@ def patch(
381401 url_name : Optional [str ] = None ,
382402 include_in_schema : bool = True ,
383403 permissions : Optional [List [Type [BasePermission ]]] = None ,
404+ openapi_extra : Optional [Dict [str , Any ]] = None ,
384405 ) -> Callable [[TCallable ], RouteFunction ]:
385406 """
386407 A PATCH Operation method decorator
@@ -429,6 +450,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
429450 url_name = url_name ,
430451 include_in_schema = include_in_schema ,
431452 permissions = permissions ,
453+ openapi_extra = openapi_extra ,
432454 )
433455
434456 return decorator
@@ -452,6 +474,7 @@ def put(
452474 url_name : Optional [str ] = None ,
453475 include_in_schema : bool = True ,
454476 permissions : Optional [List [Type [BasePermission ]]] = None ,
477+ openapi_extra : Optional [Dict [str , Any ]] = None ,
455478 ) -> Callable [[TCallable ], RouteFunction ]:
456479 """
457480 A PUT Operation method decorator
@@ -500,6 +523,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
500523 url_name = url_name ,
501524 include_in_schema = include_in_schema ,
502525 permissions = permissions ,
526+ openapi_extra = openapi_extra ,
503527 )
504528
505529 return decorator
@@ -524,6 +548,7 @@ def generic(
524548 url_name : Optional [str ] = None ,
525549 include_in_schema : bool = True ,
526550 permissions : Optional [List [Type [BasePermission ]]] = None ,
551+ openapi_extra : Optional [Dict [str , Any ]] = None ,
527552 ) -> Callable [[TCallable ], RouteFunction ]:
528553 """
529554 A Custom Operation method decorator, for creating route with more than one operation
@@ -573,6 +598,7 @@ def decorator(view_func: TCallable) -> RouteFunction:
573598 url_name = url_name ,
574599 include_in_schema = include_in_schema ,
575600 permissions = permissions ,
601+ openapi_extra = openapi_extra ,
576602 )
577603
578604 return decorator
0 commit comments