33import json
44from collections .abc import Callable , Sequence
55from dataclasses import dataclass , field
6- from typing import Annotated , Literal
6+ from typing import Annotated , Any , Literal , cast
77
88import numpy
99from fastapi import HTTPException , Query
10- from pydantic import BeforeValidator , Field
10+ from pydantic import AfterValidator , BeforeValidator , Field
1111from rasterio .crs import CRS
1212from rio_tiler .colormap import ColorMaps
1313from rio_tiler .colormap import cmap as default_cmap
1414from rio_tiler .colormap import parse_color
15- from rio_tiler .types import RIOResampling , WarpResampling
15+ from rio_tiler .types import AssetType , AssetWithOptions , RIOResampling , WarpResampling
1616from starlette .requests import Request
1717
1818from titiler .core .resources .enums import ImageType , MediaType
@@ -134,12 +134,37 @@ class BidxExprParams(ExpressionParams, BidxParams):
134134
135135
136136# Dependencies for MultiBaseReader (e.g STACReader)
137+ def _parse_asset (values : list [str ]) -> list [AssetType ]:
138+ """Parse assets with optional parameter."""
139+ assets : list [AssetType ] = []
140+ for v in values :
141+ if "|" in v :
142+ asset_name , params = v .split ("|" , 1 )
143+ opts : dict [str , Any ] = {"name" : asset_name }
144+ for option in params .split ("|" ):
145+ key , value = option .split ("=" , 1 )
146+ if key == "bidx" :
147+ opts ["indexes" ] = list (map (int , value .split ("," )))
148+ elif key == "expression" :
149+ opts ["expression" ] = value
150+ elif key == "bands" :
151+ opts ["bands" ] = value .split ("," )
152+
153+ asset = cast (AssetWithOptions , opts )
154+ assets .append (asset )
155+ else :
156+ assets .append (v )
157+
158+ return assets
159+
160+
137161@dataclass
138162class AssetsParams (DefaultDependency ):
139163 """Assets parameters."""
140164
141165 assets : Annotated [
142166 list [str ],
167+ AfterValidator (_parse_asset ),
143168 Query (
144169 title = "Asset names" ,
145170 description = "Asset's names." ,
@@ -153,6 +178,10 @@ class AssetsParams(DefaultDependency):
153178 "description" : "Return results for assets `data` and `cog`." ,
154179 "value" : ["data" , "cog" ],
155180 },
181+ "multi-assets-with-options" : {
182+ "description" : "Return results for assets `data` and `cog`." ,
183+ "value" : ["data|bidx=1" , "cog|bidx=1,2" ],
184+ },
156185 },
157186 ),
158187 ]
0 commit comments