mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-27 16:10:30 +08:00
refactor: move print_openapi_schema into main
This commit is contained in:
committed by
Andreas Köpf
parent
ea40a22049
commit
29b08875d4
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user