-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanapi-codegen.py
executable file
·37 lines (27 loc) · 1.07 KB
/
nanapi-codegen.py
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
#!/usr/bin/env python3
import asyncio
from pathlib import Path
from mahou.parsers.openapi import OpenAPIParser
from mahou.serializers.aiohttp_client import OpenAPIaiohttpClientSerializer
from mahou.serializers.model import OpenAPIModelSerializer
import nanachan.nanapi
from nanachan.settings import JAPAN7_AUTH, NANAPI_URL
from nanachan.utils.misc import get_session
async def main():
module = Path(nanachan.nanapi.__file__).parent
async with get_session().get(f"{NANAPI_URL}/openapi.json",
auth=JAPAN7_AUTH) as resp:
raw = await resp.read()
data = raw.decode()
parser = OpenAPIParser()
server = parser.parse(data)
model_serializer = OpenAPIModelSerializer()
data = model_serializer.serialize(list(server.schemas.values()))
with open(module / 'model.py', 'w') as f:
f.write(data)
client_serializer = OpenAPIaiohttpClientSerializer()
model = client_serializer.serialize(server)
with open(module / '_client.py', 'w') as f:
f.write(model)
if __name__ == '__main__':
asyncio.run(main())