Skip to content

Commit ddfafbc

Browse files
committed
🚧 Update buildPath
1 parent 1b42934 commit ddfafbc

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/buildPath.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
const {loadYaml, loadConfig} = require("./common");
22

3-
function buildPath(url, configFile) {
3+
function buildPath(url, configFile, opts) {
44
const path = _buildPath(url, configFile)
55
const pathArr = path.replacedUrl.split("/")
66
const pkg = pathArr[pathArr.length - 2].replace(/\./g, '')
77
const last = pathArr[pathArr.length - 1] || "index"
88
const struct = _capitalize(last)
99
pathArr.pop()
1010
const dir = pathArr.join("/")
11+
let method = opts?.method.toLowerCase()
12+
1113
return {
1214
path,
1315
struct,
1416
pkg,
1517
dir,
16-
jsonFilePath: `${dir}/${last}.json`,
17-
goFilePath: `${dir}/${last}.go`,
18-
paramJsonFilePath: `${dir}/${last}_param.json`,
19-
paramGoFilePath: `${dir}/${last}_param.go`,
18+
jsonFilePath: `${dir}/${last}_${method}.json`,
19+
goFilePath: `${dir}/${last}_${method}.go`,
20+
queryJsonFilePath: `${dir}/${last}_${method}_query.json`,
21+
queryGoFilePath: `${dir}/${last}_${method}_query.go`,
22+
bodyJsonFilePath: `${dir}/${last}_${method}_body.json`,
23+
bodyGoFilePath: `${dir}/${last}_${method}_body.go`,
2024
}
2125
}
2226

src/buildPath.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ const buildPath = require('./buildPath');
33
test('build path', () => {
44
const expected = {
55
"dir": "api.github.com/users/user",
6-
"goFilePath": "api.github.com/users/user/repos.go",
7-
"jsonFilePath": "api.github.com/users/user/repos.json",
8-
"paramGoFilePath": "api.github.com/users/user/repos_param.go",
9-
"paramJsonFilePath": "api.github.com/users/user/repos_param.json",
6+
"goFilePath": "api.github.com/users/user/repos_get.go",
7+
"jsonFilePath": "api.github.com/users/user/repos_get.json",
8+
"queryGoFilePath": "api.github.com/users/user/repos_get_query.go",
9+
"queryJsonFilePath": "api.github.com/users/user/repos_get_query.json",
10+
"bodyGoFilePath": "api.github.com/users/user/repos_get_body.go",
11+
"bodyJsonFilePath": "api.github.com/users/user/repos_get_body.json",
1012
"path": {
1113
"pathFormat": "/users/{user}/repos",
1214
"pathname": "/users/github/repos",
@@ -16,9 +18,13 @@ test('build path', () => {
1618
"pkg": "user",
1719
"struct": "Repos"
1820
}
21+
let opts = {
22+
method: "GET",
23+
}
1924
const received = buildPath(
2025
new URL("https://api.github.com/users/github/repos"),
21-
"./src/.api-to-go.test.yml"
26+
"./src/.api-to-go.test.yml",
27+
opts
2228
)
2329
expect(received).toEqual(expected);
2430
});

src/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function run(urlStr, body, options) {
2424
const apiUrl = urlStr.replace(/\/$/, '')
2525
url = new URL(apiUrl);
2626
cfg = loadConfig(url, cliOpts.config)
27-
path = buildPath(url, cliOpts.config)
27+
path = buildPath(url, cliOpts.config, opts)
2828

2929
console.log(`Status: ${res.status} ${res.statusText}`)
3030
console.log(`Request: ${opts.method} ${url}`)

0 commit comments

Comments
 (0)