What you are trying won't work because if you specify @Url, it expects a static URL, it won't take @Path into consideration.
Solution 1
Remove the @Path parameter and just send the formatted string in @Url.
your method declaration will look like this:
@GET
fun searchProductV2(
@Url fullPath: String,
@Query("searchCriteria[pageSize]") pageSize: String,
@QueryMap apiSearchCriteria: Map<String, String>,
@HeaderMap headerMap: Map<String, String> = emptyMap()
): Single<Products>
and your fullPath parameter can be initialized like this:
val fullPath = "https://myBaseUrl/v2/products/%s/search".format("storeCode")
Solution 2
A better approach would be to not use String as the @Url parameter.
(@Url can be okhttp3.HttpUrl, String, java.net.URI, or android.net.Uri)
Here's an example using android.net.Uri:
your method declaration will look like this:
@GET
fun searchProductV2(
@Url fullPath: Uri,
@Query("searchCriteria[pageSize]") pageSize: String,
@QueryMap apiSearchCriteria: Map<String, String>,
@HeaderMap headerMap: Map<String, String> = emptyMap()
): Single<Products>
and your fullPath parameter can be initialized like this:
val fullPath = Uri.parse("https://myBaseUrl/v2/products/%s/search".format("storeCode"))
To make this code more nicer, you can create a helper class:
class DynamicUrl(private val formatString: String, private vararg val args: Any?) {
fun toUri(): Uri = Uri.parse(formatString.format(*args))
}
and now your fullPath parameter can be initialized like this:
val fullPath = DynamicUrl("https://myBaseUrl/v2/products/%s/search", "storeCode").toUri()