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

Variables reutilization support #10

Open
natenho opened this issue Mar 15, 2019 · 3 comments
Open

Variables reutilization support #10

natenho opened this issue Mar 15, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@natenho
Copy link
Owner

natenho commented Mar 15, 2019

Some generated variables are useful to be repeatedly used inside the template body.

The feature could include "environment" or "global" variables, available to all templates and "scope" variables, available only to a given template.

@natenho natenho added the enhancement New feature or request label Mar 15, 2019
natenho added a commit that referenced this issue Jul 20, 2020
@natenho
Copy link
Owner Author

natenho commented Jul 27, 2020

This is partially supported. Starting in v1.2.0, there is the "Global" object, which can be used to persist global variables shared with all mocks.

It still lacks a way to naturally persist local script variables, so creating a variable inside a script like the example bellow is not supported so far:

<#
var myVariable = "my response";
#>
{
  "request": {
	"method": "GET",
	"route": "ping"
  },
  "response": {
	"status": "OK",
	"body": {
	  "response": "<#=myVariable #>"
	}
  }
}

@gomete
Copy link
Contributor

gomete commented Mar 18, 2022

Hi @natenho,

It would be nice to have this feature. Any idea about how to implement it? I could give it a try but I would appreciate some guidance.

@natenho
Copy link
Owner Author

natenho commented Mar 20, 2022

@gomete We need to do a little research on how to design it and it would affect TempalteTransformer. The problem is that every script block (i.e. <# ... #>) is evaluated as independent scopes, hence not carrying any previous computed variables (even if they are in the same mock template).

The challenge is to implement a clean way to carry these variables along and only along a given mock scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants