""" Initialize the WebFinger server with FastAPI """ from fastapi import FastAPI import webfinger.lookup app = FastAPI( title = "webfinger", version = "1" ) app.include_router(webfinger.lookup.router) def cleanup_openapi(fastapi_app: FastAPI) -> None: """Cleanup inconsistencies in the OpenAPI documentation""" openapi_schema = fastapi_app.openapi() # 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)