-
-
Notifications
You must be signed in to change notification settings - Fork 779
Expand file tree
/
Copy pathgenerate_api_client.py
More file actions
33 lines (22 loc) · 1.41 KB
/
generate_api_client.py
File metadata and controls
33 lines (22 loc) · 1.41 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
import json
import os
import sys
from urllib.request import urlretrieve
os.chdir('vue3/src/openapi')
# generate base API client for all models
os.system('openapi-generator-cli generate -g typescript-fetch -t templates -i http://127.0.0.1:8000/openapi/')
sys.exit(0)
# TODO this code was written as a test and commited for archiving
# TODO it is currently not used because the generator creates interfaces not classes, thus cannot be annotated by functions
# get the latest template from openapi generator and tell it to include the custom model functions
with open('openapitools.json','r') as f:
openapi_tools_config = json.loads(f.read())
TEMPLATE_URL = f'https://raw.githubusercontent.com/OpenAPITools/openapi-generator/refs/tags/v{openapi_tools_config['generator-cli']['version']}/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache'
TEMPLATE_FILE_NAME = 'templates/modelGeneric.mustache'
OVERRIDE_FILE_NAME = 'templates/customModelFunctions.mustache'
urlretrieve(TEMPLATE_URL, TEMPLATE_FILE_NAME)
with open(TEMPLATE_FILE_NAME, 'a') as template_file, open(OVERRIDE_FILE_NAME, 'r') as override_file:
template_file.write(override_file.read())
# generate API client with custom template for specified models
MODELS = ['Keyword', 'Food']
os.system(f'openapi-generator-cli generate -g typescript-fetch -t templates -i http://127.0.0.1:8000/openapi/ --global-property models={':'.join(MODELS)}')