Skip to content

Commit

Permalink
fix: parsing of nested tables in request body
Browse files Browse the repository at this point in the history
  • Loading branch information
udayvir-singh committed Aug 28, 2022
1 parent 744bd43 commit 46441b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
25 changes: 9 additions & 16 deletions lua/rest-nvim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@ local config = {
formatters = {
json = "jq",
html = function(body)
return vim.fn
.system({
"tidy",
"-i",
"-q",
"--tidy-mark",
"no",
"--show-body-only",
"auto",
"--show-errors",
"0",
"--show-warnings",
"0",
"-",
}, body)
:gsub("\n$", "")
-- stylua: ignore
return vim.fn.system({
"tidy", "-i", "-q",
"--tidy-mark", "no",
"--show-body-only", "auto",
"--show-errors", "0",
"--show-warnings", "0",
"-",
}, body):gsub("\n$", "")
end,
},
},
Expand Down
8 changes: 8 additions & 0 deletions lua/rest-nvim/request/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ local function get_body(bufnr, start_line, stop_line, has_json)
end

local is_json, json_body = pcall(vim.fn.json_decode, body)

if is_json then
if has_json then
-- convert entire json body to string.
return vim.fn.json_encode(json_body)
else
-- convert nested tables to string.
for key, val in pairs(json_body) do
if type(val) == "table" then
json_body[key] = vim.fn.json_encode(val)
end
end
return json_body
end
end
Expand Down

0 comments on commit 46441b6

Please sign in to comment.