@@ -52,7 +52,12 @@ class ApiDetails:
5252
5353@dataclass
5454class JwtSecurityDefinition :
55- """Represents the JWT security definition for an API."""
55+ """
56+ Represents the JWT security definition for an API.
57+
58+ issuer (str): the JWT issuer
59+ audiences (List[str]): a list of the allowed audiences for the API
60+ """
5661
5762 issuer : str
5863 audiences : List [str ]
@@ -68,16 +73,16 @@ class ApiOptions:
6873 """Represents options when creating an API, such as middleware to be applied to all HTTP request to the API."""
6974
7075 path : str
71- middleware : Union [HttpMiddleware , List [HttpMiddleware ], None ]
72- security_definitions : Union [ dict [str , SecurityDefinition ], None ]
73- security : Union [ dict [str , List [str ]], None ]
76+ middleware : Union [HttpMiddleware , List [HttpMiddleware ]]
77+ security_definitions : dict [str , SecurityDefinition ]
78+ security : dict [str , List [str ]]
7479
7580 def __init__ (
7681 self ,
7782 path : str = "" ,
7883 middleware : List [Middleware ] = [],
79- security_definitions : dict [str , SecurityDefinition ] = None ,
80- security : dict [str , List [str ]] = None ,
84+ security_definitions : dict [str , SecurityDefinition ] = {} ,
85+ security : dict [str , List [str ]] = {} ,
8186 ):
8287 """Construct a new API options object."""
8388 self .middleware = middleware
@@ -102,18 +107,18 @@ def _to_resource(b: Api) -> Resource:
102107
103108def _security_definition_to_grpc_declaration (
104109 security_definitions : dict [str , SecurityDefinition ]
105- ) -> Union [ dict [str , ApiSecurityDefinition ], None ]:
110+ ) -> dict [str , ApiSecurityDefinition ]:
106111 if security_definitions is None or len (security_definitions ) == 0 :
107- return None
112+ return {}
108113 return {
109114 k : ApiSecurityDefinition (jwt = ApiSecurityDefinitionJwt (issuer = v .issuer , audiences = v .audiences ))
110115 for k , v in security_definitions .items ()
111116 }
112117
113118
114- def _security_to_grpc_declaration (security : dict [str , List [str ]]) -> dict [str , ApiScopes ] | None :
119+ def _security_to_grpc_declaration (security : dict [str , List [str ]]) -> dict [str , ApiScopes ]:
115120 if security is None or len (security ) == 0 :
116- return None
121+ return {}
117122 return {k : ApiScopes (v ) for k , v in security .items ()}
118123
119124
@@ -187,7 +192,7 @@ def decorator(function: HttpMiddleware):
187192 return decorator
188193
189194 def methods (self , methods : List [HttpMethod ], match : str , opts : MethodOptions = None ):
190- """Define an HTTP route which will respond to HTTP GET requests."""
195+ """Define an HTTP route which will respond to specific HTTP requests defined by a list of verbs ."""
191196 if opts is None :
192197 opts = MethodOptions ()
193198
@@ -275,7 +280,7 @@ async def _details(self) -> ApiDetails:
275280 except GRPCError as grpc_err :
276281 raise exception_from_grpc_error (grpc_err )
277282
278- async def URL (self ) -> str :
283+ async def url (self ) -> str :
279284 """Get the APIs live URL."""
280285 details = await self ._details ()
281286 return details .url
@@ -291,7 +296,7 @@ class Route:
291296 def __init__ (self , api : Api , path : str , opts : RouteOptions ):
292297 """Define a route to be handled by the provided API."""
293298 self .api = api
294- self .path = api .path . join ( path )
299+ self .path = ( api .path + path ). replace ( "//" , "/" )
295300 self .middleware = opts .middleware if opts .middleware is not None else []
296301
297302 def method (self , methods : List [HttpMethod ], * middleware : HttpMiddleware , opts : MethodOptions = None ):
0 commit comments