()
| 31 | """ |
| 32 | |
| 33 | def custom_openapi(): |
| 34 | # Return cached schema if available |
| 35 | if main_app.openapi_schema: |
| 36 | return main_app.openapi_schema |
| 37 | |
| 38 | # Get the OpenAPI schema for the main app |
| 39 | openapi_schema = get_openapi( |
| 40 | title=title, |
| 41 | version=version, |
| 42 | description=description, |
| 43 | routes=main_app.routes, |
| 44 | ) |
| 45 | |
| 46 | # Add paths from mounted apps with proper prefixes |
| 47 | for mount_path, app in mounted_apps.items(): |
| 48 | # Skip apps mounted at root (these should be handled separately) |
| 49 | if mount_path == "/": |
| 50 | prefix = "" |
| 51 | else: |
| 52 | # Ensure mount_path starts with / and doesn't end with / |
| 53 | mount_path = "/" + mount_path.strip("/") |
| 54 | prefix = mount_path |
| 55 | |
| 56 | # Get schema for the mounted app |
| 57 | app_schema = get_openapi( |
| 58 | title=f"{app.title}" if hasattr(app, 'title') else "API", |
| 59 | version=version, |
| 60 | routes=app.routes, |
| 61 | ) |
| 62 | |
| 63 | # Add paths with appropriate prefix |
| 64 | for path, path_item in app_schema.get("paths", {}).items(): |
| 65 | # Handle root paths specially (e.g., "/" becomes "/api/") |
| 66 | if path == "/": |
| 67 | path = "" |
| 68 | # Add the path with the appropriate prefix |
| 69 | openapi_schema["paths"][f"{prefix}{path}"] = path_item |
| 70 | |
| 71 | # Merge components |
| 72 | if "components" in app_schema and "schemas" in app_schema["components"]: |
| 73 | if "components" not in openapi_schema: |
| 74 | openapi_schema["components"] = {} |
| 75 | if "schemas" not in openapi_schema["components"]: |
| 76 | openapi_schema["components"]["schemas"] = {} |
| 77 | |
| 78 | openapi_schema["components"]["schemas"].update(app_schema["components"]["schemas"]) |
| 79 | |
| 80 | # Merge security schemes if present |
| 81 | if "components" in app_schema and "securitySchemes" in app_schema["components"]: |
| 82 | if "components" not in openapi_schema: |
| 83 | openapi_schema["components"] = {} |
| 84 | if "securitySchemes" not in openapi_schema["components"]: |
| 85 | openapi_schema["components"]["securitySchemes"] = {} |
| 86 | |
| 87 | openapi_schema["components"]["securitySchemes"].update( |
| 88 | app_schema["components"]["securitySchemes"] |
| 89 | ) |
| 90 |
nothing calls this directly
no test coverage detected
searching dependent graphs…