/ docs.py
docs.py
 1  from fastapi.openapi.utils import get_openapi
 2  from restai.main import app
 3  from restai.routers import llms, embeddings, projects, tools, users, proxy, statistics, auth, teams, settings, direct, evals
 4  import json
 5  
 6  # Register routers that are normally added in lifespan
 7  app.include_router(llms.router, tags=["LLMs"])
 8  app.include_router(embeddings.router, tags=["Embeddings"])
 9  app.include_router(projects.router)
10  app.include_router(tools.router, tags=["Tools"])
11  app.include_router(users.router, tags=["Users"])
12  app.include_router(proxy.router, tags=["Proxy"])
13  app.include_router(statistics.router, tags=["Statistics"])
14  app.include_router(auth.router, tags=["Auth"])
15  app.include_router(teams.router, tags=["Teams"])
16  app.include_router(settings.router, tags=["Settings"])
17  app.include_router(direct.router, tags=["Direct Access"])
18  app.include_router(evals.router)
19  
20  schema = get_openapi(
21      title=app.title,
22      version=app.version,
23      openapi_version=app.openapi_version,
24      description=app.description,
25      routes=app.routes,
26  )
27  
28  with open('./docs/swagger/openapi.json', 'w') as f:
29      json.dump(schema, f, indent=2)
30  
31  print(f"OpenAPI schema written: {len(schema.get('paths', {}))} endpoints")