File: generate_openapi.py

package info (click to toggle)
glances 4.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,384 kB
  • sloc: python: 23,159; makefile: 470; sh: 430; javascript: 374
file content (33 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download
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
from unittest.mock import patch

from fastapi.openapi.utils import get_openapi

from glances.main import GlancesMain

# sys.path.append('./glances/outputs')
from glances.outputs.glances_restful_api import GlancesRestfulApi

# Init Glances core
testargs = ["glances", "-C", "./conf/glances.conf"]
with patch('sys.argv', testargs):
    core = GlancesMain()
test_config = core.get_config()
test_args = core.get_args()

app = GlancesRestfulApi(config=test_config, args=test_args)._app

with open('./docs/api/openapi.json', 'w') as f:
    json.dump(
        get_openapi(
            title=app.title,
            version=app.version,
            # Set the OenAPI version
            # It's an hack to make openapi.json compatible with tools like https://editor.swagger.io/
            # Please read https://fastapi.tiangolo.com/reference/fastapi/?h=openapi#fastapi.FastAPI.openapi_version
            openapi_version="3.0.2",
            description=app.description,
            routes=app.routes,
        ),
        f,
    )