-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Finally I figured out what felt off about the "@uriencoded" annotation that is used in the sdk: it applies to the function as a whole and changes incoming function parameters, which may be an issue in a future refactoring where the function body uses the incoming parameters for anything that is not in the URL.
While URL-encoding here is mostly a precaution, the way it happens is too opaque, and if someone doesn't understand what's going on (which is possible given annotations are a pretty obscure feature), this could easily become a nasty footgun.
Locally, I came up with using template strings for this, which are themselves one of the more-obscure features of JavaScript, but at least here it's immediately clear that the transformation applies to the URL itself:
import uriencode from './util/uriencoded';
const response = await axios.get(
uriencode`/api/v2/template/${template}/${fnName}`,
{ baseURL: this.baseUrl }
);I don't have a strong preference for either the TS annotation or the template string, but I would recommend rewriting the annotation to one that only applies to the API request URL.