Skip to content

Commit 73ba353

Browse files
committed
allow prefix with path parameters
1 parent 3a8ea56 commit 73ba353

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
1111
### fixed
1212

1313
- forward `catalog_dependency` in `OGCFeaturesFactory` and `OGCTilesFactory` when using `Endpoints` factory
14+
- allow Factory's prefix with path parameter
1415

1516
### changed
1617

tipg/factory.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from starlette.datastructures import QueryParams
4646
from starlette.requests import Request
4747
from starlette.responses import HTMLResponse, Response, StreamingResponse
48+
from starlette.routing import compile_path, replace_params
4849
from starlette.templating import Jinja2Templates, _TemplateResponse
4950

5051
tms_settings = TMSSettings()
@@ -226,7 +227,15 @@ def url_for(self, request: Request, name: str, **path_params: Any) -> str:
226227

227228
base_url = str(request.base_url)
228229
if self.router_prefix:
229-
base_url += self.router_prefix.lstrip("/")
230+
prefix = self.router_prefix.lstrip("/")
231+
# If we have prefix with custom path param we check and replace them with
232+
# the path params provided
233+
if "{" in prefix:
234+
_, path_format, param_convertors = compile_path(prefix)
235+
prefix, _ = replace_params(
236+
path_format, param_convertors, request.path_params.copy()
237+
)
238+
base_url += prefix
230239

231240
return str(url_path.make_absolute_url(base_url=base_url))
232241

0 commit comments

Comments
 (0)