-
Notifications
You must be signed in to change notification settings - Fork 6
/
openapi.py
45 lines (35 loc) · 1.46 KB
/
openapi.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
import json
import os
import sys
from pathlib import Path
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from flasgger import APISpec # type: ignore
from flasgger import Swagger
from pantos.servicenode.restapi import _BidSchema
from pantos.servicenode.restapi import _BidsSchema
from pantos.servicenode.restapi import _TransferResponseSchema
from pantos.servicenode.restapi import _TransferSchema
from pantos.servicenode.restapi import _TransferStatusResponseSchema
from pantos.servicenode.restapi import _TransferStatusSchema
from pantos.servicenode.restapi import flask_app
DOCS_PATH = "docs/openapi.json"
if len(sys.argv) > 1:
DOCS_PATH = sys.argv[1]
plugins = [FlaskPlugin(), MarshmallowPlugin()]
spec = APISpec("Pantos Service Node APISpec", '1.0', "3.0.2", plugins=plugins)
template = spec.to_flasgger(
flask_app, definitions=[
_BidSchema, _BidsSchema, _TransferSchema, _TransferResponseSchema,
_TransferStatusSchema, _TransferStatusResponseSchema
])
swagger = Swagger(flask_app, template=template, parse=True)
with flask_app.test_request_context():
data = swagger.get_apispecs()
data.pop('definitions')
data.pop('swagger')
data['servers'] = [{'url': 'https://sn1.testnet.pantos.io'}]
if not (Path.cwd() / DOCS_PATH).exists():
os.makedirs(os.path.dirname(DOCS_PATH), exist_ok=True)
with open(DOCS_PATH, "w") as f:
f.write(json.dumps(data, indent=4))