-
Notifications
You must be signed in to change notification settings - Fork 1
/
etape_1.py
48 lines (36 loc) · 1.12 KB
/
etape_1.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
38
39
40
41
42
43
44
45
46
47
48
# coding: utf-8
import datetime
import json
from dataclasses import dataclass
import aiohttp_autoreload
import serpyco
from aiohttp import web
from hapic import Hapic
from hapic.error.serpyco import SerpycoDefaultErrorBuilder
from hapic.ext.aiohttp.context import AiohttpContext
from hapic.processor.serpyco import SerpycoProcessor
import utils
hapic = Hapic(async_=True)
hapic.set_processor_class(SerpycoProcessor)
@dataclass
class About(object):
current_datetime: datetime.datetime
ip: str
@staticmethod
@serpyco.post_dump
def add_python_version(data: dict) -> dict:
data["python_version"] = utils.get_python_version()
return data
@hapic.with_api_doc()
@hapic.output_body(About)
async def about(request):
return About(current_datetime=datetime.datetime.now(), ip=utils.get_ip())
app = web.Application()
app.add_routes([web.get(r"/about", about)])
hapic.set_context(
AiohttpContext(app, default_error_builder=SerpycoDefaultErrorBuilder())
)
hapic.add_documentation_view("/api/doc", "DOC", "Generated doc")
print(json.dumps(hapic.generate_doc()))
aiohttp_autoreload.start()
web.run_app(app)