aspida / aspida

TypeScript friendly HTTP client wrapper for the browser and node.js.

Home Page:https://github.com/aspida/aspida

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[$api generation] Route /123 and /$123 conflict. Now it's time to re-think what can we use for dir names and how escaping?

LumaKernel opened this issue · comments

commented

123 would be mapped as $123 because it starts with numbers, so /$123/$api.ts will not be generated.
Official bypass is supplying /$123 as /%24123 (note that %24 denotes $), but /123 and /%24123 also conflicts. The key $123: ... is generated in one object in $api.ts.

commented

I think we should determine when should we escape the route name, and if the folder $123 is invalid, it should be warned.

commented

when should we escape the route name

My opinion is stop using automatic prepending dollar sign($) and use original text as JS object key.

$api['2'].$get()
$api['foo/bar'].$get() // not /foo/bar
$api['あいう'].$get()

And percent escape is left as optional. This is required for escape _ (underscore) starting paths because aspida uses this pattern as path param.
This means, we can make api path for /あいう by directory named as あいう, %e3%81%82いう, or other combinations.
Route for /_abc..., we should make the directory named as %5fabc... because directory _abc... is treated as path param.

Additionally, I have an idea for routes starting with dollar signs.
Dollar signs conflicts with internal abstraction like .$get, $url and others.
My idea controls as mapping paths /123, /$123, /$$123 to $api['123'], $api.$['123'], $api.$.$['123']. This can be treated as $ itself is reserved by aspida system. Path /$get will be mapped $api.$.get.

My these ideas are comprehensive, but breaking backward compatibility.

This should be determined before aspida/openapi2aspida#150 , additionally whether to allow . and other characters as path param name or not. If not allowed, this issue's example should be mapped to directory channel_point%2efunding_txid_str but this lacks readability.

commented

What will be broken with my idea?

  • Route /123: $api.$123$api['123']
  • Route /a%2fb: $api.a_b (originally, $api.a_2fb) → $api['a\x2fb'] (or in this case, $api['a/b'])