11import typing as t
22
33from ellar .auth .guards import GuardAPIKeyCookie
4- from ellar .common import Body , ModuleRouter , Query
4+ from ellar .common import Body , GuardCanActivate , ModuleRouter , Query , UseGuards
55from ellar .common .constants import CONTROLLER_OPERATION_HANDLER_KEY
66from ellar .common .responses .models import ResponseModel , ResponseModelField
7+ from ellar .core import ExecutionContext
78from ellar .core .connection import HTTPConnection
89from ellar .core .routing import ModuleRouterFactory
910from ellar .openapi import OpenAPIRouteDocumentation , openapi_info
1415from ..schema import BlogObjectDTO , CreateCarSchema , Filter , NoteSchemaDC
1516
1617
18+ class JustAGuard (GuardCanActivate ):
19+ async def can_activate (self , context : ExecutionContext ) -> bool :
20+ return True
21+
22+
1723class CustomCookieAPIKey (GuardAPIKeyCookie ):
1824 parameter_name = "custom-key"
1925
@@ -41,16 +47,21 @@ class CustomResponseModel(ResponseModel):
4147@openapi_info (
4248 summary = "Endpoint Summary" ,
4349 description = "Endpoint Description" ,
44- deprecated = False ,
50+ deprecated = True ,
4551 tags = ["endpoint" , "endpoint-25" ],
4652)
47- def get_car_by_id (car_id : int , filter : Filter = Query ()):
53+ def get_car_by_id (
54+ car_id : int ,
55+ filter : Filter = Query (),
56+ schema : int = Query (description = "input field description" , deprecated = True ),
57+ ):
4858 res = filter .dict ()
49- res .update (car_id = car_id )
59+ res .update (car_id = car_id , schema = schema )
5060 return res
5161
5262
5363@router .get ("/create" , response = {201 : CreateCarSchema })
64+ @UseGuards (JustAGuard )
5465def create_car (car : CreateCarSchema ):
5566 return car
5667
@@ -68,7 +79,7 @@ def test_open_api_route_model_input_fields():
6879 CONTROLLER_OPERATION_HANDLER_KEY , get_car_by_id
6980 )
7081 openapi_route_doc = OpenAPIRouteDocumentation (route = route_operation )
71- assert len (openapi_route_doc .input_fields ) == 3
82+ assert len (openapi_route_doc .input_fields ) == 4
7283
7384 for field in openapi_route_doc .input_fields :
7485 assert field .field_info .in_ .value in ["query" , "path" ]
@@ -97,14 +108,16 @@ def test_open_api_route_model_get_openapi_operation_metadata():
97108 "summary" : "Endpoint Summary" ,
98109 "description" : "Endpoint Description" ,
99110 "operationId" : "get_car_by_id_cars__car_id__post" ,
111+ "deprecated" : True ,
100112 }
101113
102114 result = openapi_route_doc .get_openapi_operation_metadata ("some_http_method" )
103115 assert result == {
104- "tags" : ["endpoint" , "endpoint-25" ],
105- "summary" : "Endpoint Summary" ,
116+ "deprecated" : True ,
106117 "description" : "Endpoint Description" ,
107118 "operationId" : "get_car_by_id_cars__car_id__some_http_method" ,
119+ "summary" : "Endpoint Summary" ,
120+ "tags" : ["endpoint" , "endpoint-25" ],
108121 }
109122
110123
@@ -160,6 +173,18 @@ def test_open_api_route_get_openapi_operation_parameters_works_for_empty_model_n
160173 "title" : "From" ,
161174 },
162175 },
176+ {
177+ "name" : "schema" ,
178+ "in" : "query" ,
179+ "required" : True ,
180+ "schema" : {
181+ "type" : "integer" ,
182+ "description" : "input field description" ,
183+ "title" : "Schema" ,
184+ },
185+ "description" : "input field description" ,
186+ "deprecated" : True ,
187+ },
163188 ]
164189
165190
@@ -416,7 +441,7 @@ def test_open_api_route__get_openapi_path_object_works_for_routes_with_multiple_
416441 CONTROLLER_OPERATION_HANDLER_KEY , list_and_create_car
417442 )
418443 openapi_route_doc = OpenAPIRouteDocumentation (
419- route = route_operation , guards = [CustomCookieAPIKey ()]
444+ route = route_operation , guards = [CustomCookieAPIKey (), JustAGuard () ]
420445 )
421446 field_mapping , _ = get_definitions (
422447 fields = openapi_route_doc .get_route_models (),
0 commit comments