diff --git a/CHANGES.md b/CHANGES.md index fa93d35c..2e362ba0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin ### fixed - forward `catalog_dependency` in `OGCFeaturesFactory` and `OGCTilesFactory` when using `Endpoints` factory +- allow Factory's prefix with path parameter ### changed diff --git a/tipg/factory.py b/tipg/factory.py index c7849cd3..b829416e 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -45,6 +45,7 @@ from starlette.datastructures import QueryParams from starlette.requests import Request from starlette.responses import HTMLResponse, Response, StreamingResponse +from starlette.routing import compile_path, replace_params from starlette.templating import Jinja2Templates, _TemplateResponse tms_settings = TMSSettings() @@ -226,7 +227,15 @@ def url_for(self, request: Request, name: str, **path_params: Any) -> str: base_url = str(request.base_url) if self.router_prefix: - base_url += self.router_prefix.lstrip("/") + prefix = self.router_prefix.lstrip("/") + # If we have prefix with custom path param we check and replace them with + # the path params provided + if "{" in prefix: + _, path_format, param_convertors = compile_path(prefix) + prefix, _ = replace_params( + path_format, param_convertors, request.path_params.copy() + ) + base_url += prefix return str(url_path.make_absolute_url(base_url=base_url))