@@ -76,6 +76,7 @@ def __init__(
7676 pagination_default_limit : Optional [int ] = None ,
7777 methods : Iterable [str ] = (),
7878 max_cache_size : int = 0 ,
79+ ending_slash : bool = True ,
7980 ) -> None :
8081 """
8182 Initialize router items.
@@ -115,6 +116,7 @@ def __init__(
115116 self .schema_detail = schema
116117 # tuple and not set, so ordering is persisted
117118 self .methods = tuple (methods ) or self .DEFAULT_METHODS
119+ self .ending_suffix = "/" if ending_slash else ""
118120
119121 if self .type_ in self .all_jsonapi_routers :
120122 msg = f"Resource type { self .type_ !r} already registered"
@@ -184,7 +186,7 @@ def _register_get_resource_list(self, path: str):
184186 status .HTTP_200_OK : {"model" : self .list_response_schema },
185187 }
186188 self .router .add_api_route (
187- path = path ,
189+ path = path + self . ending_suffix ,
188190 tags = self .tags ,
189191 responses = list_response_example | self .default_error_responses ,
190192 methods = ["GET" ],
@@ -198,7 +200,7 @@ def _register_post_resource_list(self, path: str):
198200 status .HTTP_201_CREATED : {"model" : self .detail_response_schema },
199201 }
200202 self .router .add_api_route (
201- path = path ,
203+ path = path + self . ending_suffix ,
202204 tags = self .tags ,
203205 responses = create_resource_response_example | self .default_error_responses ,
204206 methods = ["POST" ],
@@ -213,7 +215,7 @@ def _register_delete_resource_list(self, path: str):
213215 status .HTTP_200_OK : {"model" : self .detail_response_schema },
214216 }
215217 self .router .add_api_route (
216- path = path ,
218+ path = path + self . ending_suffix ,
217219 tags = self .tags ,
218220 responses = detail_response_example | self .default_error_responses ,
219221 methods = ["DELETE" ],
@@ -229,7 +231,7 @@ def _register_get_resource_detail(self, path: str):
229231 self .router .add_api_route (
230232 # TODO: variable path param name (set default name on DetailView class)
231233 # TODO: trailing slash (optional)
232- path = path + "/{obj_id}" ,
234+ path = path + "/{obj_id}" + self . ending_suffix ,
233235 tags = self .tags ,
234236 responses = detail_response_example | self .default_error_responses ,
235237 methods = ["GET" ],
@@ -245,7 +247,7 @@ def _register_patch_resource_detail(self, path: str):
245247 self .router .add_api_route (
246248 # TODO: variable path param name (set default name on DetailView class)
247249 # TODO: trailing slash (optional)
248- path = path + "/{obj_id}" ,
250+ path = path + "/{obj_id}" + self . ending_suffix ,
249251 tags = self .tags ,
250252 responses = update_response_example | self .default_error_responses ,
251253 methods = ["PATCH" ],
@@ -264,7 +266,7 @@ def _register_delete_resource_detail(self, path: str):
264266 self .router .add_api_route (
265267 # TODO: variable path param name (set default name on DetailView class)
266268 # TODO: trailing slash (optional)
267- path = path + "/{obj_id}" ,
269+ path = path + "/{obj_id}" + self . ending_suffix ,
268270 tags = self .tags ,
269271 responses = delete_response_example | self .default_error_responses ,
270272 methods = ["DELETE" ],
0 commit comments