44from uuid import UUID
55
66from fastapi import APIRouter , HTTPException , Response
7+ from fastapi import Path as PathParam
78from fastapi .responses import FileResponse
89from oicana import BlobInput , CompilationMode , Template
910from pydantic import BaseModel , Field
@@ -131,7 +132,10 @@ def warm_up_templates():
131132 },
132133 description = "Compile a template with given inputs." ,
133134)
134- async def compile_template (template_id : str , payload : CompilationPayload ):
135+ async def compile_template (
136+ payload : CompilationPayload ,
137+ template_id : str = PathParam (example = "table" ),
138+ ):
135139 if template_id not in template_cache :
136140 raise HTTPException (status_code = 404 , detail = f"Template '{ template_id } ' not found!" )
137141
@@ -186,7 +190,10 @@ async def compile_template(template_id: str, payload: CompilationPayload):
186190 },
187191 description = "Generate a PNG preview of the template with given inputs." ,
188192)
189- async def preview_template (template_id : str , payload : CompilationPayload ):
193+ async def preview_template (
194+ payload : CompilationPayload ,
195+ template_id : str = PathParam (example = "table" ),
196+ ):
190197 if template_id not in template_cache :
191198 raise HTTPException (status_code = 404 , detail = f"Template '{ template_id } ' not found!" )
192199
@@ -238,7 +245,7 @@ async def preview_template(template_id: str, payload: CompilationPayload):
238245 "Reset (remove) a template from the cache. The template will be reloaded on next use."
239246 ),
240247)
241- async def reset_template (template_id : str ):
248+ async def reset_template (template_id : str = PathParam ( example = "table" ) ):
242249 if template_id in template_cache :
243250 del template_cache [template_id ]
244251 logger .info (f"Template '{ template_id } ' removed from cache" )
@@ -259,7 +266,7 @@ async def reset_template(template_id: str):
259266 },
260267 description = "Download a packed template." ,
261268)
262- async def get_template (template_id : str ):
269+ async def get_template (template_id : str = PathParam ( example = "table" ) ):
263270 template_path = Path (f"templates/{ template_id } -0.1.0.zip" )
264271 if not template_path .exists ():
265272 raise HTTPException (status_code = 404 , detail = "Template not found" )
0 commit comments