What is FastAPI's OpenAPI specification and how is it customized?

Answer

FastAPI auto-generates an OpenAPI 3.0 spec from your code at /openapi.json and serves interactive UI at /docs (Swagger UI) and /redoc. Customize the spec: app = FastAPI(title="My API", description="Detailed description", version="2.0.0", docs_url="/api-docs", redoc_url=None). Enrich endpoints with metadata: @app.get("/items", tags=["items"], summary="List all items", description="Returns paginated list", response_description="List of items", deprecated=False). Add security schemes: app = FastAPI(); app.openapi_schema = custom_schema or override app.openapi() for full control. Add examples to Pydantic models with model_config = {"json_schema_extra": {"examples": [...]}}. Generate client code from the spec using openapi-generator or fastapi-code-generator. The spec can also be exported to Postman collections for team sharing.