|
11 | 11 | from fastapi.responses import HTMLResponse, FileResponse |
12 | 12 | from fastapi.middleware.cors import CORSMiddleware |
13 | 13 | from fastapi.staticfiles import StaticFiles |
| 14 | +from fastapi.openapi.utils import get_openapi |
14 | 15 |
|
15 | 16 |
|
16 | 17 | config = {} |
|
37 | 38 |
|
38 | 39 | app = FastAPI( |
39 | 40 | title = "Linuxmuster.net API", |
40 | | - version="7.2.21", |
| 41 | + version="7.3.12", |
41 | 42 | description = description, |
42 | 43 | swagger_ui_parameters = {"tryItOutEnabled": True, "swagger_favicon_url": "/static/favicon.png"}, |
43 | 44 | license_info={ |
@@ -124,6 +125,31 @@ def home(): |
124 | 125 | app.include_router(printers.router, prefix="/v1") |
125 | 126 | app.include_router(server.router, prefix="/v1") |
126 | 127 |
|
| 128 | +def custom_openapi(): |
| 129 | + if app.openapi_schema: |
| 130 | + return app.openapi_schema |
| 131 | + openapi_schema = get_openapi( |
| 132 | + title = "Linuxmuster.net API", |
| 133 | + version = "7.3.13", |
| 134 | + summary = "Linuxmuster.net API", |
| 135 | + description = description, |
| 136 | + routes=app.routes, |
| 137 | + ) |
| 138 | + openapi_schema["components"]["securitySchemes"] = { |
| 139 | + 'HTTPBasic': {'type': 'http', 'scheme': 'basic'}, |
| 140 | + 'ApiKeyUserAuth': {'type': 'apiKey', 'in': 'header', 'name': 'X-API-Key'}, |
| 141 | + 'ApiKeyHostAuth': {'type': 'apiKey', 'in': 'header', 'name': 'X-HOST-Key'}, |
| 142 | + } |
| 143 | + for path, details in openapi_schema["paths"].items(): |
| 144 | + if path != '/v1/auth/' and path != '/': |
| 145 | + for method in details.keys(): |
| 146 | + details[method]['security'] = [{'ApiKeyUserAuth': [], 'ApiKeyHostAuth': []}] |
| 147 | + |
| 148 | + app.openapi_schema = openapi_schema |
| 149 | + return app.openapi_schema |
| 150 | + |
| 151 | +app.openapi = custom_openapi |
| 152 | + |
127 | 153 | if __name__ == "__main__": |
128 | 154 | secret = config.get('secret', None) |
129 | 155 | if not secret: |
|
0 commit comments