@@ -79,6 +79,7 @@ def __init__(
7979 pagination_default_limit : Optional [int ] = None ,
8080 methods : Iterable [str ] = (),
8181 max_cache_size : int = 0 ,
82+ ending_slash : bool = True ,
8283 ) -> None :
8384 """
8485 Initialize router items.
@@ -118,6 +119,7 @@ def __init__(
118119 self .schema_detail = schema
119120 # tuple and not set, so ordering is persisted
120121 self .methods = tuple (methods ) or self .DEFAULT_METHODS
122+ self .ending_suffix = "/" if ending_slash else ""
121123
122124 if self .type_ in self .all_jsonapi_routers :
123125 msg = f"Resource type { self .type_ !r} already registered"
@@ -187,7 +189,7 @@ def _register_get_resource_list(self, path: str):
187189 status .HTTP_200_OK : {"model" : self .list_response_schema },
188190 }
189191 self ._router .add_api_route (
190- path = path ,
192+ path = path + self . ending_suffix ,
191193 tags = self ._tags ,
192194 responses = list_response_example | self .default_error_responses ,
193195 methods = ["GET" ],
@@ -201,7 +203,7 @@ def _register_post_resource_list(self, path: str):
201203 status .HTTP_201_CREATED : {"model" : self .detail_response_schema },
202204 }
203205 self ._router .add_api_route (
204- path = path ,
206+ path = path + self . ending_suffix ,
205207 tags = self ._tags ,
206208 responses = create_resource_response_example | self .default_error_responses ,
207209 methods = ["POST" ],
@@ -216,7 +218,7 @@ def _register_delete_resource_list(self, path: str):
216218 status .HTTP_200_OK : {"model" : self .detail_response_schema },
217219 }
218220 self ._router .add_api_route (
219- path = path ,
221+ path = path + self . ending_suffix ,
220222 tags = self ._tags ,
221223 responses = detail_response_example | self .default_error_responses ,
222224 methods = ["DELETE" ],
@@ -232,7 +234,7 @@ def _register_get_resource_detail(self, path: str):
232234 self ._router .add_api_route (
233235 # TODO: variable path param name (set default name on DetailView class)
234236 # TODO: trailing slash (optional)
235- path = path + "/{obj_id}" ,
237+ path = path + "/{obj_id}" + self . ending_suffix ,
236238 tags = self ._tags ,
237239 responses = detail_response_example | self .default_error_responses ,
238240 methods = ["GET" ],
@@ -248,7 +250,7 @@ def _register_patch_resource_detail(self, path: str):
248250 self ._router .add_api_route (
249251 # TODO: variable path param name (set default name on DetailView class)
250252 # TODO: trailing slash (optional)
251- path = path + "/{obj_id}" ,
253+ path = path + "/{obj_id}" + self . ending_suffix ,
252254 tags = self ._tags ,
253255 responses = update_response_example | self .default_error_responses ,
254256 methods = ["PATCH" ],
@@ -267,7 +269,7 @@ def _register_delete_resource_detail(self, path: str):
267269 self ._router .add_api_route (
268270 # TODO: variable path param name (set default name on DetailView class)
269271 # TODO: trailing slash (optional)
270- path = path + "/{obj_id}" ,
272+ path = path + "/{obj_id}" + self . ending_suffix ,
271273 tags = self ._tags ,
272274 responses = delete_response_example | self .default_error_responses ,
273275 methods = ["DELETE" ],
0 commit comments