Skip to content

Commit

Permalink
Support simple math expresssions in json for better documetation (#313)
Browse files Browse the repository at this point in the history
* Use athematic expressions in Json
  • Loading branch information
cedric05 authored Oct 24, 2024
1 parent 793ca60 commit d15cb48
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"docker-in-docker": "latest"
// "docker-in-docker": "latest"
}
}
2 changes: 1 addition & 1 deletion benchmarks/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyperf==2.7.0
pyperf==2.8.0
pytest-benchmark
2 changes: 1 addition & 1 deletion dothttp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.43a20"
__version__ = "0.0.43a23"
18 changes: 17 additions & 1 deletion dothttp/http.tx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,23 @@ Array:
;

Value:
strs += TRIPLE_OR_DOUBLE_STRING | var=VarString | flt=Float | int=Int | bl=Bool | object=Object | array=Array | null="null"
strs += TRIPLE_OR_DOUBLE_STRING | var=VarString | flt=Float | int=Int | bl=Bool | object=Object | array=Array | null="null" | expr=Expression
;

Expression:
Term (('+' | '-') Term)*
;

Term:
Factor (('*' | '/') Factor)*
;

Factor:
Number | '(' Expression ')'
;

Number:
/\d+/
;


Expand Down
2 changes: 2 additions & 0 deletions dothttp/parse/dsl_jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def jsonmodel_to_json(model, update_content_func):
return [jsonmodel_to_json(value, update_content_func) for value in array.values]
elif model == "null":
return None
elif expr := model.expr:
return eval(expr)


def get_json_data(var_value, update_content_func):
Expand Down
5 changes: 3 additions & 2 deletions examples/example.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@name("fetch 100 users, skip first 50")
GET https://req.dothttp.dev/user
POST https://req.dothttp.dev/user
"Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
"content-type": "application/json"
? ("fetch", "100") #
Expand All @@ -9,7 +9,8 @@ GET https://req.dothttp.dev/user
? projection, location

{
"payload": {{$randomSlug}}
"payload": {{$randomSlug}},
"time": (3*60) // three minutes in seconds
}
> {%

Expand Down
416 changes: 228 additions & 188 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dothttp-req"
version = "0.0.43a20"
version = "0.0.43a23"
description = "Dothttp is Simple http client for testing and development"
authors = ["Prasanth <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -30,8 +30,8 @@ requests-pkcs12 = "1.25"
parsys-requests-unixsocket = "0.3.2"
requests-aws4auth = "1.3.1"
requests-ntlm = "1.3.0"
restrictedpython = "7.2"
faker = "28.4.1"
restrictedpython = "7.4"
faker = "30.6.0"
requests-hawk = "1.2.1"
msal = "1.31.0"
pyyaml = "6.0.2"
Expand All @@ -44,7 +44,7 @@ flask = "3.0.2"
python-magic = "^0.4.27"
js2py = "0.74"
flask-cors = "^5.0.0"
pytest = "^8.3.2"
pytest = "^8.3.3"
pytest-html = "^4.1.1"

[tool.poetry.extras]
Expand Down

0 comments on commit d15cb48

Please sign in to comment.