Challenge - 5 Problems
OpenAPI Schema Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the effect of setting
openapi_url=None in FastAPI?Consider this FastAPI app initialization:
What will happen when you try to access
app = FastAPI(openapi_url=None)
What will happen when you try to access
/openapi.json?FastAPI
from fastapi import FastAPI app = FastAPI(openapi_url=None)
Attempts:
2 left
💡 Hint
Think about what disabling the OpenAPI schema URL does to the app's documentation endpoints.
✗ Incorrect
Setting openapi_url=None disables the automatic generation of the OpenAPI JSON schema endpoint, so /openapi.json returns 404.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly adds a custom OpenAPI schema title in FastAPI?
You want to customize the OpenAPI schema title to "My API". Which snippet does this correctly?
Attempts:
2 left
💡 Hint
Check the FastAPI constructor parameters for setting the API title.
✗ Incorrect
The correct parameter to set the OpenAPI schema title is 'title'.
🔧 Debug
advanced3:00remaining
Why does this custom OpenAPI schema function cause a recursion error?
Given this code snippet:
What causes the recursion error when calling
def custom_openapi():
return app.openapi()
app.openapi = custom_openapiWhat causes the recursion error when calling
app.openapi()?FastAPI
def custom_openapi(): return app.openapi() app.openapi = custom_openapi
Attempts:
2 left
💡 Hint
Think about what happens when custom_openapi calls app.openapi after reassigning it.
✗ Incorrect
Assigning app.openapi = custom_openapi means calling app.openapi() inside custom_openapi calls itself again, causing infinite recursion.
🧠 Conceptual
advanced3:00remaining
How can you add a custom field to the OpenAPI schema info section in FastAPI?
You want to add a custom field
x-logo with a URL inside the OpenAPI info section. Which approach is correct?Attempts:
2 left
💡 Hint
Think about how to customize the OpenAPI JSON output directly.
✗ Incorrect
Overriding app.openapi() lets you modify the generated OpenAPI schema dictionary, adding custom fields like x-logo.
❓ state_output
expert3:00remaining
What is the output of this FastAPI OpenAPI customization code?
Given this code snippet:
What will be printed?
from fastapi import FastAPI
app = FastAPI()
original_openapi = app.openapi
def custom_openapi():
if not hasattr(app, "_custom_openapi_schema"):
schema = original_openapi()
schema["info"]["title"] = "Custom API"
app._custom_openapi_schema = schema
return app._custom_openapi_schema
app.openapi = custom_openapi
print(app.openapi()["info"]["title"])What will be printed?
FastAPI
from fastapi import FastAPI app = FastAPI() original_openapi = app.openapi def custom_openapi(): if not hasattr(app, "_custom_openapi_schema"): schema = original_openapi() schema["info"]["title"] = "Custom API" app._custom_openapi_schema = schema return app._custom_openapi_schema app.openapi = custom_openapi print(app.openapi()["info"]["title"])
Attempts:
2 left
💡 Hint
Look at how the title is changed and cached in the custom_openapi function.
✗ Incorrect
The custom_openapi function modifies the title to 'Custom API' once and caches it, so the printed title is 'Custom API'.