Skip to content
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

Use of file variables in file variables only works if declarations are in reverse #208

Closed
AmbrosiaDevelopments opened this issue May 13, 2018 · 15 comments

Comments

@AmbrosiaDevelopments
Copy link

  • VSCode Version: 1.24.0-insider (commit: 987c3dcc..)
  • OS Version: Windows 10 x64
  • REST Client Version: 0.18.4

Steps to Reproduce:

  1. Create test file: lidarr.http:
@root = http://localhost:8686/api/v1/
@calendar = calendar?start={{start}}&end={{end}}&includeArtist=true
@start = 2018-01-01
@end = 2018-12-31
###
GET {{root}}{{calendar}}
###
  1. Right click on the GET URL and select "copy request as cURL", output is:
curl --request GET \
  --url 'http://localhost:8686/api/v1/calendar?includeArtist=true&end=2018-12-31&start=2018-01-01'
  1. Move @start and @end variables to be above the @calendar variable like this:
@start = 2018-01-01
@end = 2018-12-31
@calendar = calendar?start={{start}}&end={{end}}&includeArtist=true
  1. Again right click on the GET URL and select "copy request as cURL", output is:
curl --request GET \
  --url 'http://localhost:8686/api/v1/calendar?includeArtist=true&end=%7B%7Bend%7D%7D&start=%7B%7Bstart%7D%7D'

I am not terribly bothered by this now I've figured out a way around it but it isn't obvious as to why it works only like this. I'm not sure using variables in variables was even mentioned in any documentation I found. Not sure if it's relevant but the generated URL has also swapped the order of query parameters.

@Huachao
Copy link
Owner

Huachao commented May 13, 2018

@SimonDever actually it just happens to work. We don't support for variable value references other variables, the reason you work is related to current variable resolving logic in code. I will check if any file variables exist in declaration order, so in your case, I found calendar there, I will replace the calendar in request by its value, which introduces a new variable start. And the resolving logic continues, the next checking variable is start, and it's there, I replace it too. That's the reason why it works. I will modify the implementation later.

@AmbrosiaDevelopments
Copy link
Author

Modify to remove the ability to use variables in other variables or modify to be able to declare them in the reverse order as well?

@Huachao
Copy link
Owner

Huachao commented May 19, 2018

@SimonDever I am planning the feature that the actual value of a file variable can reference other request variables and file variables.

@vladvino
Copy link

vladvino commented Jul 6, 2018

Referencing environment variables from a file variable used to work for me. Looks like something in 2018/6/28 release broke it. Would be great to see it working again.

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2018

@vladvino I will fix this ASAP.

@mchelen
Copy link

mchelen commented Jul 24, 2018

@Huachao Is there an issue for the feature enhancement of reusing one file variable in another file variable?

@Huachao
Copy link
Owner

Huachao commented Jul 25, 2018

@mchelen I am afraid not. And I will implement the feature that file variables can depend on any custom variables(environment, file and request variables) finally.

@schallm
Copy link

schallm commented Nov 7, 2018

Would/Could this also support storing "resolved" dynamic variables in variables? I would like to store a date in a variable so it can be used multiple times in an array of objects being posted

@enteredDate = {{$datetime iso8601}}

So it could be used in a post like the following

[
  {
    "firstName": "joe",
    "enteredDate": "{{enteredDate}}"
  },
  {
    "firstName": "bob",
    "enteredDate": "{{enteredDate}}",
  }
]

@Huachao
Copy link
Owner

Huachao commented Nov 8, 2018

@schallm Thanks for your suggestion. The file variables definition can already support referencing request variables, and allowing supporting other types of variables like System Variable, Environment Variables and File Variables are in my todo list.

@Huachao
Copy link
Owner

Huachao commented Nov 21, 2018

@SimonDever @vladvino @mchelen @Mellbourn @schallm I have implemented the feature that file variables can reference other file variables. And the work that references environment variables and system variables is still WIP.

@AmbrosiaDevelopments
Copy link
Author

Do you have issues open for those other things mentioned here and can I close this or do you want to keep it open until the environment variables/system variables work is complete?

@Huachao
Copy link
Owner

Huachao commented Nov 21, 2018

Let's keep it open, I will finally close this issue before next release

@Huachao
Copy link
Owner

Huachao commented Nov 22, 2018

@SimonDever @vladvino @mchelen @Mellbourn @schallm I have implemented the feature that file variables can reference file/system/request/environment variables. I will publish this feature in next release

@Huachao
Copy link
Owner

Huachao commented Dec 2, 2018

@SimonDever @vladvino @mchelen @Mellbourn @schallm you can try the latest version 0.20.4 to verify

@schallm
Copy link

schallm commented Dec 3, 2018

I can confirm my use case is now supported. One interesting/awesome thing is that the dynamic variables are re-evaluated each time "Send Request" is clicked. So in my example above, enteredDate is updated to "now" with each request.

Thanks for implementing this feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants