feat: endpoints更新時にエンドポイントが消えた場合でも型として残すように

master
yupix 1 year ago
parent 21fbd839fe
commit af81ac3a05
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -1,32 +1,49 @@
import json
import os
from type import OpenAPI
PATHS: list[str] = []
PREFIX = '/api'
TOP_COMMENT = """\"\"\"
TOP_COMMENT = '''\"\"\"
=======================
WARNING
=======================
This file is automatically generated by compiler/endpoints.py.
If this file is modified and then auto-generated, the changes will be lost.
\"\"\"\n
"""
IMPORTS = "from typing import Literal\n\n"
TEMPLATES = "ENDPOINTS = "
'''
IMPORTS = 'from typing import Literal\n\n'
TEMPLATES = 'ENDPOINTS = '
with open('./datas/v13_api.json') as f:
with open('./datas/v13_api.json', mode='r') as f:
api: OpenAPI = json.load(f)
for path in api['paths']:
PATHS.append(f'{PREFIX}{path}')
with open('./datas/ayuskey_api.json') as f:
with open('./datas/ayuskey_api.json', mode='r') as f:
api: OpenAPI = json.load(f)
for path in api['paths']:
PATHS.append(f'{PREFIX}{path}')
old_endpoints = []
if os.path.exists('./datas/endpoints.json'):
with open('./datas/endpoints.json', mode='r') as f:
old_endpoints = json.load(f)
with open('./datas/endpoints.json', mode='w') as f:
removed_endpoints = []
for i in old_endpoints:
if i not in list(dict.fromkeys(PATHS)):
removed_endpoints.append(i)
with open('./datas/removed-endpoints.json', mode='w') as removed_endpoints_f:
json.dump(removed_endpoints, removed_endpoints_f, ensure_ascii=False, indent=4)
old_endpoints.extend(PATHS)
old_endpoints = list(dict.fromkeys(old_endpoints))
json.dump(old_endpoints, f, ensure_ascii=False, indent=4)
with open('../mipac/types/endpoints.py', 'w', encoding='utf-8') as f:
data = json.dumps(list(dict.fromkeys(PATHS)), ensure_ascii=False, indent=4).replace('"', '\'')
f.write(
f'{TOP_COMMENT}{IMPORTS}{TEMPLATES}Literal{data}\n'
)
data = json.dumps(old_endpoints, ensure_ascii=False, indent=4).replace('"', "'")
f.write(f'{TOP_COMMENT}{IMPORTS}{TEMPLATES}Literal{data}\n')

Loading…
Cancel
Save