auto generate openapi

This commit is contained in:
Alex 2023-11-29 13:42:50 +08:00
parent 320ed63c69
commit 018f9c2e3b
2 changed files with 21 additions and 9 deletions

View File

@ -34,7 +34,7 @@ jobs:
run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & run: pwd && cd release/linux/Debug && sudo ./MediaServer -d &
- name: generate openapi - name: generate openapi
run: cd tools/openapi && python3 generates.py run: cd tools/openapi && python3 generates.py install-dependencies
- name: Commit and push if www/swagger/openapi.json changed - name: Commit and push if www/swagger/openapi.json changed
run: | run: |

View File

@ -43,18 +43,26 @@ def run_cmd(cmd: str, assert_success=False, capture_output=False, env=None) -> b
return True return True
def check_dependencies() -> None: def check_dependencies(need_install:bool = False) -> None:
""" """
check dependencies check dependencies
:return: :return:
""" """
if not check_installed("p2o"): if not check_installed("p2o"):
print() if not need_install:
print("p2o is not installed, please install it first!") print()
print("If you use npm, you can install it by the following command:") print("p2o is not installed, please install it first!")
print("npm install -g postman-to-openapi") print("If you use npm, you can install it by the following command:")
print() print("npm install -g postman-to-openapi")
sys.exit(1) print()
sys.exit(1)
else:
# 先检查是否安装了npm, 没有就自动安装
if not check_installed("npm"):
print("npm is not installed, install it first")
run_cmd("sudo apt install npm -y")
print("p2o is not installed, install it")
run_cmd("sudo npm install -g postman-to-openapi")
else: else:
print("p2o is installed") print("p2o is installed")
@ -138,7 +146,11 @@ def generate() -> None:
if __name__ == "__main__": if __name__ == "__main__":
check_dependencies() # 如果有参数install-dependencies则安装依赖
if len(sys.argv) > 1 and sys.argv[1] == "install-dependencies":
check_dependencies(True)
else:
check_dependencies()
version = get_version() version = get_version()
secret = get_secret() secret = get_secret()
update_options(version, secret) update_options(version, secret)