Skip to content

Commit 24d5b8b

Browse files
committed
download json schemas recursively
this should make us a bit more resilient against renaming/moving of JSON schema files in apm-server
1 parent 1e0b7b5 commit 24d5b8b

File tree

3 files changed

+26
-60
lines changed

3 files changed

+26
-60
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ docs:
1919
bash ./scripts/build_docs.sh apm-agent-python ./docs ${BUILD_DIR}
2020

2121
update-json-schema:
22-
bash ./tests/scripts/download_json_schema.sh
22+
python3 ./tests/scripts/download_json_schema.py master tests/.schemacache
2323

2424
.PHONY: isort flake8 test coverage docs update-json-schema

tests/scripts/download_json_schema.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
import json
3+
import os
4+
import sys
5+
from urllib import request
6+
7+
BASE_URL = "https://api.github.com/repos/elastic/apm-server/contents/{path}?ref={branch}"
8+
9+
10+
def download_folder(name, branch, base_folder):
11+
response = request.urlopen(BASE_URL.format(path=name, branch=branch))
12+
data = json.loads(response.read().decode("utf-8"))
13+
for item in data:
14+
if item["type"] == "dir":
15+
download_folder(item["path"], branch, base_folder)
16+
elif item["type"] == "file":
17+
path = base_folder + item["path"][9:]
18+
os.makedirs(os.path.dirname(path), exist_ok=True)
19+
request.urlretrieve(item["download_url"], base_folder + item["path"][9:])
20+
print("downloaded {} to {}".format(item["path"][9:], os.path.dirname(path)))
21+
22+
23+
if __name__ == "__main__":
24+
path = os.path.abspath(sys.argv[2])
25+
download_folder("docs/spec", sys.argv[1], path)

tests/scripts/download_json_schema.sh

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)