Skip to content

Commit 0d97f72

Browse files
committed
🐛 Fix buildPath when without setting
1 parent 4fb282d commit 0d97f72

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/buildPath.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ function buildPath(apiUrl, configFile = "./.api-to-go.yaml") {
2323
function _buildPath(url, configFile) {
2424
const cfg = _loadConfig(configFile)
2525
const hostCfg = cfg?.[url.hostname]
26-
let ret;
26+
let ret ={
27+
pathname: url.pathname,
28+
pathFormat: null,
29+
replacedPath: url.pathname,
30+
replacedUrl: `${url.hostname}${url.pathname}`,
31+
}
2732
if (hostCfg !== undefined) {
2833
for (let i = 0; i < hostCfg.length; i++) {
29-
ret = _replacePath(url.pathname, hostCfg[i])
30-
if (ret) {
31-
ret["Url"] = `${url.hostname}${ret.replacedPath}`
32-
ret["replacedUrl"] = `${url.hostname}${ret.replacedPath}`
34+
const replaced = _replacePath(url.pathname, hostCfg[i])
35+
if (replaced) {
36+
ret = replaced
37+
ret["replacedUrl"] = `${url.hostname}${replaced.replacedPath}`
3338
return ret
3439
}
3540
}
3641
}
37-
ret["replacedUrl"] = `${url.hostname}${url.pathname}`
3842
return ret
3943
}
4044

src/buildPath.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,18 @@ test('build path', () => {
1919
"./.api-to-go.test.yaml"
2020
)
2121
expect(received).toEqual(expected);
22+
});
23+
24+
test('build path without format setting', () => {
25+
const expected = {
26+
"pathFormat": null,
27+
"pathname": "/organizations",
28+
"replacedPath": "/organizations",
29+
"replacedUrl": "api.github.com/organizations"
30+
}
31+
const received = buildPath(
32+
"https://api.github.com/organizations",
33+
"./.api-to-go.test.yaml"
34+
)
35+
expect(received.path).toEqual(expected);
2236
});

0 commit comments

Comments
 (0)