-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/docs → Failed to load API definition - Fetch Error - Unauthorized /openapi.json #1
Comments
I have the same problem with AuthLevel = Function, Did someone find the solution? |
Same problem here with AuthLevel = Function... anyone? |
Slightly dirty workaround that makes it possible to view the docs but doesn't allow to "Try out" the API. from fastapi.openapi.docs import get_swagger_ui_html
app = FastAPI(docs_url=None)
@app.get("/docs", include_in_schema=False)
async def get_docs(code: str):
openapi_url = "/openapi.json?code=" + code
return get_swagger_ui_html(openapi_url=openapi_url, title="docs") |
If you want to use the Try it out feature, you can use from fastapi import FastAPI, Security
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.security import APIKeyHeader
app = FastAPI(docs_url=None)
functions_header = APIKeyHeader(
name="x-functions-key", description="Azure Functions key"
)
@app.get("/docs", include_in_schema=False)
async def get_docs(code: str | None = None):
if not code:
code = ""
openapi_url = "/openapi.json?code=" + code
return get_swagger_ui_html(openapi_url=openapi_url, title="docs")
@app.get("/items/{item_id}")
async def get_items(item_id: str, key: str = Security(functions_header)) -> dict:
return {item_id: "Foo"} When deployed to Azure Functions, you would still have to pass the Functions key as a query parameter when accessing the |
I've tried @farrukh-t and @pietz suggestions above above (if the try doesn't not work is not a biggy but at least having the docs working) but I am just getting constantly the same Failed to load API definition. import azure.functions as func
from WrapperFunction import app as fastapi_app
app = func.AsgiFunctionApp(app=fastapi_app, http_auth_level=func.AuthLevel.FUNCTION) from fastapi import FastAPI, Security
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.security import APIKeyHeader
app = FastAPI(docs_url=None)
functions_header = APIKeyHeader(
name="x-functions-key", description="Azure Functions key"
)
@app.get("/docs", include_in_schema=False)
async def get_docs(code: str | None = None):
if not code:
code = ""
openapi_url = "/openapi.json?code=" + code
return get_swagger_ui_html(openapi_url=openapi_url, title="docs")
@app.get("/sample")
async def hello_world(key: str = Security(functions_header)) -> dict:
return {"message": "Hello World"} The 'code' is passed to the docs endpoint but error is the same. Am I missing something or did things change since the above comment were posted ? |
Thank you for providing this example. I believe the template doesn't apply here.
Everything works as described however when trying to access the OpenAPI definition through /docs, I'm getting the following error:
I'm trying to do this on AuthLevel "Function" and couldn't find any other references to this problem.
The text was updated successfully, but these errors were encountered: