mirror of https://github.com/nicolargo/glances.git
Improve Restful API documentation embeded in FastAPI #2632
This commit is contained in:
parent
813785ff82
commit
15a94f04da
1
Makefile
1
Makefile
|
|
@ -208,6 +208,7 @@ trivy: ## Run Trivy to find vulnerabilities in container images
|
|||
# ===================================================================
|
||||
|
||||
docs: ## Create the documentation
|
||||
$(PYTHON) ./generate_openapi.py
|
||||
$(PYTHON) -m glances -C $(CONF) --api-doc > ./docs/api.rst
|
||||
cd docs && ./build.sh && cd ..
|
||||
|
||||
|
|
|
|||
744
docs/api.rst
744
docs/api.rst
File diff suppressed because it is too large
Load Diff
|
|
@ -28,7 +28,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
|||
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
|
||||
..
|
||||
.TH "GLANCES" "1" "Jun 22, 2025" "4.3.2_dev05" "Glances"
|
||||
.TH "GLANCES" "1" "Jun 29, 2025" "4.3.2_dev05" "Glances"
|
||||
.SH NAME
|
||||
glances \- An eye on your system
|
||||
.SH SYNOPSIS
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,30 @@
|
|||
import json
|
||||
|
||||
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
|
||||
core = GlancesMain(args_begin_at=2)
|
||||
test_config = core.get_config()
|
||||
test_args = core.get_args()
|
||||
|
||||
app = GlancesRestfulApi(config=test_config, args=test_args)._app
|
||||
|
||||
with open('./docs/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,
|
||||
)
|
||||
|
|
@ -219,7 +219,7 @@ class GlancesRestfulApi:
|
|||
# ==========================
|
||||
|
||||
# HEAD
|
||||
router.add_api_route(f'{base_path}/status', self._api_status, methods=['HEAD', 'GET'])
|
||||
router.add_api_route(f'{base_path}/status', self._api_status, methods=['HEAD'])
|
||||
|
||||
# POST
|
||||
router.add_api_route(f'{base_path}/events/clear/warning', self._events_clear_warning, methods=['POST'])
|
||||
|
|
@ -232,6 +232,7 @@ class GlancesRestfulApi:
|
|||
)
|
||||
|
||||
# GET
|
||||
router.add_api_route(f'{base_path}/status', self._api_status, methods=['GET'])
|
||||
route_mapping = {
|
||||
f'{base_path}/config': self._api_config,
|
||||
f'{base_path}/config/{{section}}': self._api_config_section,
|
||||
|
|
@ -266,7 +267,7 @@ class GlancesRestfulApi:
|
|||
router.add_api_route(path, endpoint)
|
||||
|
||||
# Browser WEBUI
|
||||
if self.args.browser:
|
||||
if hasattr(self.args, 'browser') and self.args.browser:
|
||||
# Template for the root browser.html file
|
||||
router.add_api_route('/browser', self._browser, response_class=HTMLResponse)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ API (Restfull/JSON) documentation
|
|||
|
||||
This documentation describes the Glances API version {__apiversion__} (Restfull/JSON) interface.
|
||||
|
||||
For Glances version 3, please have a look on:
|
||||
``https://github.com/nicolargo/glances/blob/support/glancesv3/docs/api.rst``
|
||||
An OpenAPI specification file is available at:
|
||||
``https://raw.githubusercontent.com/nicolargo/glances/refs/heads/develop/docs/openapi.json``
|
||||
|
||||
Run the Glances API server
|
||||
--------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue