@@ -79,6 +79,7 @@ def __init__(
79
79
pagination_default_limit : Optional [int ] = None ,
80
80
methods : Iterable [str ] = (),
81
81
max_cache_size : int = 0 ,
82
+ ending_slash : bool = True ,
82
83
) -> None :
83
84
"""
84
85
Initialize router items.
@@ -118,6 +119,7 @@ def __init__(
118
119
self .schema_detail = schema
119
120
# tuple and not set, so ordering is persisted
120
121
self .methods = tuple (methods ) or self .DEFAULT_METHODS
122
+ self .ending_suffix = "/" if ending_slash else ""
121
123
122
124
if self .type_ in self .all_jsonapi_routers :
123
125
msg = f"Resource type { self .type_ !r} already registered"
@@ -187,7 +189,7 @@ def _register_get_resource_list(self, path: str):
187
189
status .HTTP_200_OK : {"model" : self .list_response_schema },
188
190
}
189
191
self ._router .add_api_route (
190
- path = path ,
192
+ path = path + self . ending_suffix ,
191
193
tags = self ._tags ,
192
194
responses = list_response_example | self .default_error_responses ,
193
195
methods = ["GET" ],
@@ -201,7 +203,7 @@ def _register_post_resource_list(self, path: str):
201
203
status .HTTP_201_CREATED : {"model" : self .detail_response_schema },
202
204
}
203
205
self ._router .add_api_route (
204
- path = path ,
206
+ path = path + self . ending_suffix ,
205
207
tags = self ._tags ,
206
208
responses = create_resource_response_example | self .default_error_responses ,
207
209
methods = ["POST" ],
@@ -216,7 +218,7 @@ def _register_delete_resource_list(self, path: str):
216
218
status .HTTP_200_OK : {"model" : self .detail_response_schema },
217
219
}
218
220
self ._router .add_api_route (
219
- path = path ,
221
+ path = path + self . ending_suffix ,
220
222
tags = self ._tags ,
221
223
responses = detail_response_example | self .default_error_responses ,
222
224
methods = ["DELETE" ],
@@ -232,7 +234,7 @@ def _register_get_resource_detail(self, path: str):
232
234
self ._router .add_api_route (
233
235
# TODO: variable path param name (set default name on DetailView class)
234
236
# TODO: trailing slash (optional)
235
- path = path + "/{obj_id}" ,
237
+ path = path + "/{obj_id}" + self . ending_suffix ,
236
238
tags = self ._tags ,
237
239
responses = detail_response_example | self .default_error_responses ,
238
240
methods = ["GET" ],
@@ -248,7 +250,7 @@ def _register_patch_resource_detail(self, path: str):
248
250
self ._router .add_api_route (
249
251
# TODO: variable path param name (set default name on DetailView class)
250
252
# TODO: trailing slash (optional)
251
- path = path + "/{obj_id}" ,
253
+ path = path + "/{obj_id}" + self . ending_suffix ,
252
254
tags = self ._tags ,
253
255
responses = update_response_example | self .default_error_responses ,
254
256
methods = ["PATCH" ],
@@ -267,7 +269,7 @@ def _register_delete_resource_detail(self, path: str):
267
269
self ._router .add_api_route (
268
270
# TODO: variable path param name (set default name on DetailView class)
269
271
# TODO: trailing slash (optional)
270
- path = path + "/{obj_id}" ,
272
+ path = path + "/{obj_id}" + self . ending_suffix ,
271
273
tags = self ._tags ,
272
274
responses = delete_response_example | self .default_error_responses ,
273
275
methods = ["DELETE" ],
0 commit comments