refactor: move print_openapi_schema into main

This commit is contained in:
Jack Michaud
2023-01-01 12:34:03 -05:00
committed by Andreas Köpf
parent ea40a22049
commit 29b08875d4
3 changed files with 31 additions and 13 deletions
+30
View File
@@ -179,3 +179,33 @@ if settings.DEBUG_USE_SEED_DATA:
app.include_router(api_router, prefix=settings.API_V1_STR)
def get_openapi_schema():
return json.dumps(app.openapi())
if __name__ == "__main__":
# Importing here so we don't import packages unnecessarily if we're
# importing main as a module.
import argparse
import json
import uvicorn
parser = argparse.ArgumentParser()
parser.add_argument(
"--print-openapi-schema",
help="Dumps the openapi schema to stdout",
action=argparse.BooleanOptionalAction,
)
parser.add_argument("--host", help="The host to run the server")
parser.add_argument("--port", help="The port to run the server")
args = parser.parse_args()
if args.print_openapi_schema:
print(get_openapi_schema())
else:
uvicorn.run(app, host=args.host, port=args.port)
-12
View File
@@ -1,12 +0,0 @@
# -*- coding: utf-8 -*-
import json
from main import app
def get_openapi_schema():
return json.dumps(app.openapi())
if __name__ == "__main__":
print(get_openapi_schema())
@@ -8,7 +8,7 @@ MOCK_SERVER_PORT=8080
OPENAPI_JSON_FILE_NAME=openapi.json
echo "Generating OpenAPI schema..."
python -m print_openapi_schema > $OPENAPI_JSON_FILE_NAME
python -m main --print-openapi-schema > $OPENAPI_JSON_FILE_NAME
echo "Done!"
# If oasst-mock-backend docker container is already running,