Skip to content

Commit 88c333a

Browse files
committed
docs: refactor variables doc
1 parent f29b2d7 commit 88c333a

1 file changed

Lines changed: 35 additions & 21 deletions

File tree

docs/references/variables.md

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,59 @@
11
---
22
title: Variables
33
---
4-
### Introduction
54

65
Variables are ways to hold value or computed values in specification files, like in programming language.
76

8-
### Variables
7+
## Variables node
98

10-
Variables can be defined with `variables` node on a supported specification document.
9+
Variables can be defined with `variables` node on a specification document. This node is support on all kind of spec.
1110

12-
```yml
11+
```yml {3-4}
1312
version: default:http:0.7.2
1413

1514
variables:
1615
var1: 22
16+
17+
...
1718
```
1819

19-
This variables can be later used, i.e.
20+
This variables can be used later, e.g.
2021

21-
```yml
22+
```yml {3-4,7}
2223
version: default:http:0.7.2
2324

2425
variables:
2526
emailAddr: "user@domain.ext"
2627

2728
request:
2829
url: "https://httpbin.org/get?emailAddress=<% emailAddr %>"
29-
30-
...
30+
...
3131
```
3232

33-
It is not possible to name a variable prefixing an *underscore* (`_`). So, `_Name` is an invalid name. Variable names can include `A-Z, a-z, 0-9, ., -, _`.
33+
::::tip [Naming variables]
34+
35+
Variable names can include
36+
37+
- `A-Z`
38+
- `a-z`
39+
- `0-9`
40+
- `.` dot
41+
- `-` dash
42+
- `_` underscore
43+
44+
:::warning
3445

35-
### Passing variables from console
46+
It is not possible to start a variable name with _underscore_ (`_`). Therefore, `_Name` is an invalid name, when `Name_` is valid.
3647

37-
It's possible to pass variables from console while invoking `chk` command. e.g:
48+
:::
3849

39-
So, for following HTTP specification:
50+
::::
4051

41-
```yml [title="request-someurl.chk"]
52+
## Passing variables from console
53+
54+
It's possible to pass variables from console while invoking `chk` command. Let's have following HTTP specification:
55+
56+
```yml [title="request-someurl.chk"] {5,10}
4257
---
4358
version: default:http:0.7.2
4459

@@ -49,9 +64,9 @@ request:
4964
url: "https://httpbin.org/get"
5065
url_params:
5166
emailAddress: <% emailAddr %>
52-
5367
...
5468
```
69+
5570
```shell
5671
chk fetch request-someurl.chk -V {"emailAddress": "user@domain.ext"}
5772
```
@@ -62,7 +77,7 @@ Then CHKware will replace `<% emailAddr %>` with `"user@domain.ext"`, before mak
6277

6378
It's possible to set a default value for a variable. Consider following example:
6479

65-
```yml [title="request-someurl.chk"]
80+
```yml [title="request-someurl.chk"] {5,10}
6681
---
6782
version: default:http:0.7.2
6883

@@ -76,27 +91,27 @@ request:
7691
...
7792
```
7893

79-
When invoked like:
94+
When invoked in the console like:
8095

8196
```shell
8297
chk fetch request-someurl.chk -V {"emailAddress": "user@domain.ext"}
8398
```
8499

85100
Then CHKware will replace `<% emailAddr %>` with `"user@domain.ext"`, before making request.
86101

87-
However, if invoked like:
102+
However, if invoked in the console like:
88103

89104
```shell
90105
chk fetch request-someurl.chk
91106
```
92107

93-
Then CHKware will replace `<% emailAddr %>` with something like `"user-2@domain.ext"` (or with an email of randomly picked number).
108+
Then CHKware will replace `<% emailAddr %>` with something like `"user-2@domain.ext"` (or with an email of randomly picked number) since we set default value to `user-<% range(1, 5) | random %>@domain.ext`.
94109

95110
### Variable templating with Jinja2
96111

97-
For variable templating *CHKware* uses Jinja2. Almost all of the [Jinja2 features](https://jinja.palletsprojects.com/en/stable/templates/) are supported. That makes it possible to change variables values. e.g:
112+
For variable templating _CHKware_ uses Jinja2. Almost all of the [Jinja2 features](https://jinja.palletsprojects.com/en/stable/templates/) are supported. That makes it possible to change variables values. e.g:
98113

99-
```yml
114+
```yml [title="request-someurl.chk"] {4-5,10-11}
100115
version: default:http:0.7.2
101116

102117
variables:
@@ -108,6 +123,5 @@ request:
108123
url_params:
109124
userId: <% userId %>
110125
emailAddress: <% emailAddr %>
111-
112126
...
113127
```

0 commit comments

Comments
 (0)