webfinger/webfinger/__init__.py

39 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-12-26 00:32:57 +00:00
"""
Initialize the WebFinger server with FastAPI
"""
2022-11-20 05:44:42 +00:00
from fastapi import FastAPI
2022-12-10 10:34:05 +00:00
import webfinger.lookup
app = FastAPI(
title = "webfinger",
version = "1"
2022-12-10 10:34:05 +00:00
)
app.include_router(webfinger.lookup.router)
2022-12-26 00:32:57 +00:00
def cleanup_openapi(fastapi_app: FastAPI) -> None:
2022-12-10 10:34:05 +00:00
"""Cleanup inconsistencies in the OpenAPI documentation"""
2022-12-26 00:32:57 +00:00
openapi_schema = fastapi_app.openapi()
2022-12-10 10:34:05 +00:00
# Remove 422 Validation Error from Webfinger lookup (RFC7033 uses 400 Bad Request)
webfinger_responses: dict = openapi_schema["paths"]["/.well-known/webfinger"]["get"]["responses"]
webfinger_responses.pop("422")
# Remove 422 Validation Error from schemas
schemas: dict = openapi_schema["components"]["schemas"]
schemas.pop("ValidationError")
schemas.pop("HTTPValidationError")
# Mark resource param as required
lookup_params: list[dict] = openapi_schema["paths"]["/.well-known/webfinger"]["get"]["parameters"]
resource_param = [param for param in lookup_params if param["name"] == "resource"][0]
resource_param["required"] = True
cleanup_openapi(app)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app="webfinger:app", port=7033)