swagger
This commit is contained in:
parent
cf2fbf5955
commit
04846eb8a2
|
@ -0,0 +1,10 @@
|
||||||
|
from api.swagger import router as swagger_router
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from config import settings
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
router.include_router(
|
||||||
|
swagger_router,
|
||||||
|
prefix=settings.prefix.swagger,
|
||||||
|
)
|
|
@ -0,0 +1,19 @@
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from fastapi.openapi.docs import get_swagger_ui_html
|
||||||
|
|
||||||
|
from config import settings
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("", include_in_schema=False)
|
||||||
|
async def custom_swagger_ui_html():
|
||||||
|
return get_swagger_ui_html(
|
||||||
|
openapi_url=settings.swagger.openapi_url,
|
||||||
|
title=settings.swagger.title,
|
||||||
|
oauth2_redirect_url=settings.swagger.oauth2_redirect_url,
|
||||||
|
swagger_js_url=settings.swagger.swagger_js_url,
|
||||||
|
swagger_css_url=settings.swagger.swagger_css_url,
|
||||||
|
swagger_favicon_url=settings.swagger.swagger_favicon_url,
|
||||||
|
)
|
19
config.py
19
config.py
|
@ -9,7 +9,9 @@ from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__)
|
BASE_DIR = Path(__file__).parent
|
||||||
|
TEMPLATES_DIR = BASE_DIR / "templates"
|
||||||
|
STATIC_DIR = TEMPLATES_DIR / "static"
|
||||||
|
|
||||||
|
|
||||||
class RunConfig(BaseModel):
|
class RunConfig(BaseModel):
|
||||||
|
@ -18,6 +20,19 @@ class RunConfig(BaseModel):
|
||||||
reload: bool = True
|
reload: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
class PrefixConfig(BaseModel):
|
||||||
|
swagger: str = "/docs"
|
||||||
|
|
||||||
|
|
||||||
|
class SwaggerConfig(BaseModel):
|
||||||
|
openapi_url: str = "/openapi.json"
|
||||||
|
title: str = "Netadm API"
|
||||||
|
oauth2_redirect_url: str = "/docs/oauth2-redirect"
|
||||||
|
swagger_js_url: str = "/static/swagger/swagger-ui-bundle.js"
|
||||||
|
swagger_css_url: str = "/static/swagger/swagger-ui.css"
|
||||||
|
swagger_favicon_url: str = "/static/swagger/favicon.png"
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
env_file=(
|
env_file=(
|
||||||
|
@ -29,6 +44,8 @@ class Settings(BaseSettings):
|
||||||
env_prefix="NETADM_CONFIG__",
|
env_prefix="NETADM_CONFIG__",
|
||||||
)
|
)
|
||||||
run: RunConfig = RunConfig()
|
run: RunConfig = RunConfig()
|
||||||
|
swagger: SwaggerConfig = SwaggerConfig()
|
||||||
|
prefix: PrefixConfig = PrefixConfig()
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
7
main.py
7
main.py
|
@ -1,9 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
from config import settings
|
from config import settings, STATIC_DIR
|
||||||
from scripts.сheck_available_ports import start_check
|
from scripts.сheck_available_ports import start_check
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import ORJSONResponse
|
from fastapi.responses import ORJSONResponse
|
||||||
|
from starlette.staticfiles import StaticFiles
|
||||||
|
from api import router as swagger_router
|
||||||
|
|
||||||
|
|
||||||
input_text = """
|
input_text = """
|
||||||
|
@ -27,6 +29,9 @@ main_app = FastAPI(
|
||||||
default_response_class=ORJSONResponse,
|
default_response_class=ORJSONResponse,
|
||||||
docs_url=None,
|
docs_url=None,
|
||||||
)
|
)
|
||||||
|
main_app.include_router(swagger_router)
|
||||||
|
|
||||||
|
main_app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue