Skip to content

Commit 090c503

Browse files
authored
Merge pull request #119 from teto/support-variables-in-json-path
2 parents 8c719ed + b54af37 commit 090c503

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

lua/rest-nvim/request/init.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ local function get_importfile_name(bufnr, start_line, stop_line)
1818
if import_line > 0 then
1919
local fileimport_string
2020
local fileimport_line
21+
local fileimport_spliced
2122
fileimport_line = vim.api.nvim_buf_get_lines(bufnr, import_line - 1, import_line, false)
22-
fileimport_string =
23-
string.gsub(fileimport_line[1], "<", "", 1):gsub("^%s+", ""):gsub("%s+$", "")
24-
-- local fileimport_path = path:new(fileimport_string)
25-
-- if fileimport_path:is_absolute() then
26-
if path:new(fileimport_string):is_absolute() then
27-
return fileimport_string
23+
fileimport_string = string.gsub(fileimport_line[1], "<", "", 1)
24+
:gsub("^%s+", "")
25+
:gsub("%s+$", "")
26+
fileimport_spliced = utils.replace_vars(fileimport_string)
27+
if path:new(fileimport_spliced):is_absolute() then
28+
return fileimport_spliced
2829
else
2930
local file_dirname = vim.fn.expand("%:p:h")
30-
local file_name = path:new(path:new(file_dirname), fileimport_string)
31+
local file_name = path:new(path:new(file_dirname), fileimport_spliced)
3132
return file_name:absolute()
3233
end
3334
end

tests/env_vars/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
URL=https://reqres.in/api/users
22
USERNAME=morpheus
33
TOKEN=emacs-is-pinky-stop-using-it
4+
5+
PAYLOAD=user.json

tests/env_vars/post_create_user.http

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ Authorization: Bearer {{TOKEN}}
1515
"job": "leader",
1616
"id" : "{{$uuid}}"
1717
}
18+
19+
----
20+
21+
POST {{URL}}
22+
Content-Type: application/json
23+
Authorization: Bearer {{TOKEN}}
24+
25+
< {{PAYLOAD]}}

tests/env_vars/user.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
{
3+
"name": "toto",
4+
"job": "leader",
5+
"id" : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
6+
}

0 commit comments

Comments
 (0)