Simple join of baseUrl
and path
may result in invalid URLs
#1150
Labels
baseUrl
and path
may result in invalid URLs
#1150
Description
Hello! I noticed that when you have a
baseUrl
with a trailing slash (e.g.https://example.com/api/
) andpaths
with a leading slash (e.g./create-post
) it results in an invalid URL/request. If I am reading the code correctly I think the problem surfaces in this line:https://github.com/drwpow/openapi-typescript/blob/65ff4b1826f1a70bce2acf5cd0ba77ca18b08502/packages/openapi-fetch/src/index.ts#L69
I think it assumes those two strings can always just be joined directly. If this is the case then I think the README is also suggesting this would work when it may not.
Reproduction
Here is a tiny types file for making a request to
https://jsonplaceholder.typicode.com
:And the script I ran:
Expected result
I think it'd be helpful if
openapi-fetch
smoothed this over! Maybe the leading slash of apath
should be removed pre-joining if thebaseUrl
has a trailing slash. I could also see this using theURL()
constructor instead to get a proper join for free.Checklist
The text was updated successfully, but these errors were encountered: