-
Notifications
You must be signed in to change notification settings - Fork 646
Expand file tree
/
Copy pathgenerate-code.py
More file actions
92 lines (74 loc) · 3.01 KB
/
Copy pathgenerate-code.py
File metadata and controls
92 lines (74 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import subprocess
import sys
COMPONENTS = [
{"sourceYaml": "channel-access-token.yml", "invokerPackage": "LINE\\Clients\\ChannelAccessToken"},
{"sourceYaml": "insight.yml", "invokerPackage": "LINE\\Clients\\Insight"},
{"sourceYaml": "manage-audience.yml", "invokerPackage": "LINE\\Clients\\ManageAudience"},
{"sourceYaml": "messaging-api.yml", "invokerPackage": "LINE\\Clients\\MessagingApi"},
{"sourceYaml": "liff.yml", "invokerPackage": "LINE\\Clients\\Liff"},
]
# Pin the copyright year so generated code is byte-for-byte reproducible across
# runs. Bumping this is an explicit choice, not a side effect of running the
# generator on a new year.
COPYRIGHT_YEAR = "2026"
def run_command(command):
print(command)
proc = subprocess.run(command, shell=True, text=True, capture_output=True)
if len(proc.stdout) != 0:
print("\n\nSTDOUT:\n\n")
print(proc.stdout)
if len(proc.stderr) != 0:
print("\n\nSTDERR:\n\n")
print(proc.stderr)
print("\n\n")
if proc.returncode != 0:
print(f"\n\nCommand '{command}' returned non-zero exit status {proc.returncode}.")
sys.exit(1)
return proc.stdout.strip()
def generate_clients(jar_path):
for component in COMPONENTS:
source_yaml = component["sourceYaml"]
schema = source_yaml.replace(".yml", "")
output_path = f"src/clients/{schema}"
run_command(f"rm -rf {output_path}")
run_command(f"mkdir {output_path}")
command = f"""java \
-cp {jar_path} \
org.openapitools.codegen.OpenAPIGenerator generate \
-i line-openapi/{source_yaml} \
-e pebble \
-g line-bot-sdk-php-generator \
-o {output_path} \
--additional-properties="invokerPackage={component['invokerPackage']}" \
--additional-properties="variableNamingConvention=camelCase" \
--additional-properties="copyrightYear={COPYRIGHT_YEAR}"
"""
run_command(command)
def generate_webhook(jar_path):
output_path = "src/webhook"
run_command(f"rm -rf {output_path}/lib")
run_command(f"rm -rf {output_path}/.openapi-generator")
run_command(f"rm -f {output_path}/.openapi-generator-ignore")
command = f"""java \
-cp {jar_path} \
org.openapitools.codegen.OpenAPIGenerator generate \
-i line-openapi/webhook.yml \
-e pebble \
-g line-bot-sdk-php-generator \
-o {output_path} \
--additional-properties="invokerPackage=LINE\\Webhook" \
--additional-properties="variableNamingConvention=camelCase" \
--additional-properties="copyrightYear={COPYRIGHT_YEAR}"
"""
run_command(command)
def main():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
os.chdir("generator")
run_command('mvn package -DskipTests=true')
os.chdir("..")
jar_path = "generator/target/line-bot-sdk-php-generator-1.0.0.jar"
generate_clients(jar_path)
generate_webhook(jar_path)
if __name__ == "__main__":
main()