Skip to content

Commit ccc512e

Browse files
committed
added json-schema validation in CI
1 parent da6374f commit ccc512e

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

.github/workflows/json-schema.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Json Schema
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install Python dependencies
21+
run: |
22+
pip install jsonschema
23+
24+
- name: Run proxy URL tests
25+
run: python tests/test_jsonschema.py --wallets-file=wallets-v2.json --json-schema-file=wallets-v2.schema.json

tests/test_jsonschema.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import argparse
2+
import json
3+
import sys
4+
5+
import jsonschema
6+
from pathlib import Path
7+
8+
from jsonschema import Draft7Validator
9+
10+
11+
class JsonSchemaNamespace(argparse.Namespace):
12+
wallets_file: Path
13+
json_schema_file: Path
14+
15+
16+
def create_argument_parser() -> argparse.ArgumentParser:
17+
"""Create and configure argument parser."""
18+
parser = argparse.ArgumentParser(
19+
description="Checking a json file using json-schema",
20+
formatter_class=argparse.RawDescriptionHelpFormatter,
21+
epilog="""
22+
Examples:
23+
python test_jsonschema.py --wallets-file=wallets-v2.json --json-schema-file=wallets-v2.schema.json
24+
""".strip(),
25+
)
26+
27+
parser.add_argument(
28+
"--wallets-file",
29+
type=Path,
30+
required=True,
31+
help="Path to the 'wallets-v2.json' file",
32+
)
33+
34+
parser.add_argument(
35+
"--json-schema-file",
36+
type=Path,
37+
required=True,
38+
help="Path to the 'wallets-v2.json' schema file",
39+
)
40+
41+
return parser
42+
43+
44+
def main() -> None:
45+
"""Main entry point."""
46+
parser = create_argument_parser()
47+
args = parser.parse_args(namespace=JsonSchemaNamespace())
48+
49+
wallets = json.loads(args.wallets_file.read_bytes())
50+
json_schema = json.loads(args.json_schema_file.read_bytes())
51+
52+
error_message: str | None = None
53+
try:
54+
jsonschema.validate(instance=wallets, schema=json_schema, cls=Draft7Validator)
55+
except jsonschema.exceptions.ValidationError as e:
56+
error_message = str(e)
57+
58+
if error_message is None:
59+
print("ALL TESTS PASSED")
60+
sys.exit(0)
61+
else:
62+
print("TESTS FAILED:\n")
63+
print(error_message)
64+
sys.exit(1)
65+
66+
67+
if __name__ == "__main__":
68+
main()

wallets-v2.schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"image": {
2020
"type": "string",
2121
"description": "URL to the icon of your wallet",
22-
"pattern": "^https?://.+\\.png$"
22+
"pattern": "^https://.+.png$"
2323
},
2424
"tondns": {
2525
"type": "string",
@@ -28,12 +28,12 @@
2828
"about_url": {
2929
"type": "string",
3030
"description": "Info or landing page of your wallet",
31-
"pattern": "^https?://"
31+
"pattern": "^https://+"
3232
},
3333
"universal_url": {
3434
"type": "string",
3535
"description": "Base part of your wallet universal url",
36-
"pattern": "^https?://"
36+
"pattern": "^https://+"
3737
},
3838
"deepLink": {
3939
"type": "string",
@@ -77,7 +77,7 @@
7777
},
7878
"url": {
7979
"type": "string",
80-
"pattern": "^https?://"
80+
"pattern": "^https://+"
8181
}
8282
},
8383
"required": [

0 commit comments

Comments
 (0)