mirror of
https://github.com/opnsense/docs.git
synced 2025-12-11 10:41:02 -06:00
* collect_api_endpoints.py: require pydantic * collect_api_endpoints.py: adopt pydantic for type-hinting
25 lines
1009 B
Python
25 lines
1009 B
Python
import os
|
|
from . import ApiParser, Controller
|
|
|
|
EXCLUDE_CONTROLLERS = ['Core/Api/FirmwareController.php']
|
|
|
|
def collect_api_modules(source: str, debug: bool = False) -> dict[str, list[Controller]]:
|
|
# collect all endpoints
|
|
all_modules = dict()
|
|
for root, dirs, files in os.walk(source):
|
|
for fname in sorted(files):
|
|
filename = os.path.join(root, fname)
|
|
skip = False
|
|
for to_exclude in EXCLUDE_CONTROLLERS:
|
|
if filename.endswith(to_exclude):
|
|
skip = True
|
|
break
|
|
if not skip and filename.lower().endswith('controller.php') and filename.find('mvc/app/controllers') > -1 \
|
|
and root.endswith('Api'):
|
|
controller = ApiParser(filename, debug).parse_api_php()
|
|
if controller.module not in all_modules:
|
|
all_modules[controller.module] = list()
|
|
all_modules[controller.module].append(controller)
|
|
|
|
return all_modules
|