Spaces:
Runtime error
Runtime error
Silicon Valley - Admin commited on
Commit ·
26b4d36
1
Parent(s): 1d7545f
Refactor server.py to integrate OpenAPI specification and enhance middleware configuration
Browse files- Updated QuartSchema initialization to include OpenAPI specification for improved API documentation.
- Reorganized middleware setup for better clarity and maintainability.
- Removed unused OpenAPI endpoint to streamline the codebase.
server.py
CHANGED
|
@@ -29,17 +29,20 @@ app = cors(app,
|
|
| 29 |
allow_headers=["Content-Type"],
|
| 30 |
max_age=3600
|
| 31 |
)
|
| 32 |
-
QuartSchema(app)
|
| 33 |
-
app.asgi_app = ProxyHeadersMiddleware(app.asgi_app, trusted_hosts=TRUSTED_HOSTS)
|
| 34 |
-
app.logger.setLevel(LOG_LEVEL)
|
| 35 |
-
|
| 36 |
-
broker = SessionBroker()
|
| 37 |
|
| 38 |
# Cargar OpenAPI spec
|
| 39 |
OPENAPI_PATH = Path(__file__).parent / "openapi.yaml"
|
| 40 |
with open(OPENAPI_PATH) as f:
|
| 41 |
openapi_spec = yaml.safe_load(f)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Modelos de datos
|
| 44 |
@dataclass
|
| 45 |
class Status:
|
|
@@ -93,10 +96,6 @@ async def root():
|
|
| 93 |
async def docs():
|
| 94 |
return redirect('/')
|
| 95 |
|
| 96 |
-
@app.route('/openapi.yaml')
|
| 97 |
-
async def openapi():
|
| 98 |
-
return openapi_spec
|
| 99 |
-
|
| 100 |
@app.get("/status")
|
| 101 |
@validate_response(Status)
|
| 102 |
async def status() -> Status:
|
|
|
|
| 29 |
allow_headers=["Content-Type"],
|
| 30 |
max_age=3600
|
| 31 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Cargar OpenAPI spec
|
| 34 |
OPENAPI_PATH = Path(__file__).parent / "openapi.yaml"
|
| 35 |
with open(OPENAPI_PATH) as f:
|
| 36 |
openapi_spec = yaml.safe_load(f)
|
| 37 |
|
| 38 |
+
# Configurar Quart Schema con la especificación OpenAPI
|
| 39 |
+
QuartSchema(app, openapi_spec)
|
| 40 |
+
|
| 41 |
+
app.asgi_app = ProxyHeadersMiddleware(app.asgi_app, trusted_hosts=TRUSTED_HOSTS)
|
| 42 |
+
app.logger.setLevel(LOG_LEVEL)
|
| 43 |
+
|
| 44 |
+
broker = SessionBroker()
|
| 45 |
+
|
| 46 |
# Modelos de datos
|
| 47 |
@dataclass
|
| 48 |
class Status:
|
|
|
|
| 96 |
async def docs():
|
| 97 |
return redirect('/')
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
@app.get("/status")
|
| 100 |
@validate_response(Status)
|
| 101 |
async def status() -> Status:
|