-
-
Notifications
You must be signed in to change notification settings - Fork 147
[feat] Response body stored (only for JSON responses) #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blackadress
wants to merge
17
commits into
rest-nvim:main
Choose a base branch
from
blackadress:response_body_stored
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
68b5ecf
added json parser, and req variable parser
blackadress b9b6dd9
allow for request variables on file
blackadress 3e7e2a2
format and some light refactoring
blackadress 7c3e92b
basic usage example, and removed dev stuff
blackadress 9204928
deleted json library, using vim.json instead
blackadress e935082
removed lua global variable
blackadress 615c997
Merge branch 'main' into response_body_stored
NTBBloodbath 8319426
chore: updated variables to new changes from main
blackadress bb9ada0
chore: debugger print deleted
blackadress 455d813
Merge branch 'rest-nvim:main' into response_body_stored
blackadress ffcb016
Merge branch 'main' into response_body_stored
blackadress db64cd6
added support for accesing elements in array
blackadress 20aa804
sync repo
blackadress 966b855
Merge branch 'main' into response_body_stored
blackadress 7bdc941
Merge branch 'main' into response_body_stored
blackadress 92b80bc
Sync to main
blackadress d8e3339
Merge remote-tracking branch 'refs/remotes/origin/response_body_store…
blackadress File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,10 +207,13 @@ M.read_document_variables = function() | |
|
|
||
| for node in root:iter_children() do | ||
| local type = node:type() | ||
|
|
||
| if type == "header" then | ||
| local name = node:named_child(0) | ||
| local value = node:named_child(1) | ||
| variables[M.get_node_value(name, bufnr)] = M.get_node_value(value, bufnr) | ||
| -- check if variable has assigned other variable, e.g. foo: {{bar}} | ||
| local value_processed = M.replace_req_varibles(M.get_node_value(value, bufnr)) | ||
| variables[M.get_node_value(name, bufnr)] = value_processed | ||
| elseif type ~= "comment" then | ||
| break | ||
| end | ||
|
|
@@ -226,6 +229,51 @@ M.read_variables = function() | |
| return vim.tbl_extend("force", first, second, third) | ||
| end | ||
|
|
||
| -- replaces the variables that have assigned another variable, e.g. foo: {{bar}} or foo: {{bar.baz}} | ||
| -- if so, then replace {{bar}} or {{bar.baz}} with the proper value else return the same string | ||
| -- only works if `bar` is a key in req_var_store | ||
| -- @param value_str the value to evaluate | ||
| M.replace_req_varibles = function(value_str) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lacks a |
||
| -- first check if 'value_str' has the form {{bar}} if not then return them as is | ||
| local match = string.match(value_str, "{{[^}]+}}") | ||
| if match == nil then | ||
| return value_str | ||
| end | ||
|
|
||
| match = match:gsub("{", ""):gsub("}", "") | ||
|
|
||
| -- split the value_str, e.g. 'foo.bar.baz' -> {'foo', 'bar', 'baz'} | ||
| local splitted_values = {} | ||
| for var in match:gmatch("([^.]+)") do | ||
| -- try to parse 'var' as number | ||
| local x = tonumber(var) | ||
| if x then | ||
| var = x + 1 | ||
| end | ||
| table.insert(splitted_values, var) | ||
| end | ||
|
|
||
| local result = vim.api.nvim_get_var("req_var_store") | ||
| if not result.__loaded then | ||
| error( | ||
| string.format( | ||
| "rest-nvim's global JSON variable has been unset, it is needed to get %s from there", | ||
| match | ||
| ) | ||
| ) | ||
| end | ||
| for _, val in pairs(splitted_values) do | ||
| if result[val] then | ||
| result = result[val] | ||
| else | ||
| result = "" | ||
| break | ||
| end | ||
| end | ||
|
|
||
| return result | ||
| end | ||
|
|
||
| -- replace_vars replaces the env variables fields in the provided string | ||
| -- with the env variable value | ||
| -- @param str Where replace the placers for the env variables | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| page: {{response.page}} | ||
| url: {{response.support.url}} | ||
| userid: {{response.data.0.id}} | ||
|
|
||
| # normal var | ||
| foo: 4 | ||
|
|
||
| #@response | ||
| GET https://reqres.in/api/users?page=2 | ||
|
|
||
| GET https://reqres.in/api/users?page={{foo}} | ||
|
|
||
| GET https://reqres.in/api/users?page={{page}} | ||
|
|
||
| GET {{url}} | ||
|
|
||
| GET https://reqres.in/api/users/{{userid}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this due to the formatter ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik