@@ -4,10 +4,12 @@ import { createMcpOAuthDiscoveryRoutes } from "@codelitdev/oauth-server-kit/mcp"
44import { readOrCreateRequestId } from "@codelitdev/platform" ;
55import { createExpressEndpoints , initServer } from "@ts-rest/express" ;
66import { toNodeHandler } from "better-auth/node" ;
7- import express , { type Express } from "express" ;
7+ import express , { type Express , type RequestHandler } from "express" ;
8+ import swaggerUi from "swagger-ui-express" ;
89import { AUTH_BASE_PATH , MCP_SCOPES_SUPPORTED } from "./auth/options.js" ;
910import type { DispatchDeps } from "./deps.js" ;
1011import { dispatch } from "./dispatch.js" ;
12+ import { createOpenApiDocument } from "./openapi.js" ;
1113
1214export function createExpressApp ( deps : DispatchDeps ) : Express {
1315 const app = express ( ) ;
@@ -64,6 +66,21 @@ export function createExpressApp(deps: DispatchDeps): Express {
6466 loginMethods : [ { type : "email-otp" } ] ,
6567 } ) ,
6668 ) ;
69+ // The Swagger typings can resolve a separate Express type version in a
70+ // freshly generated workspace, so normalize its handlers at this boundary.
71+ app . use (
72+ "/docs" ,
73+ ...( swaggerUi . serve as unknown as RequestHandler [ ] ) ,
74+ swaggerUi . setup ( createOpenApiDocument ( deps . auth . publicApiUrl ) , {
75+ explorer : true ,
76+ swaggerOptions : {
77+ persistAuthorization : true ,
78+ displayRequestDuration : true ,
79+ docExpansion : "none" ,
80+ defaultModelsExpandDepth : - 1 ,
81+ } ,
82+ } ) as unknown as RequestHandler ,
83+ ) ;
6784 app . use ( express . json ( { limit : "32kb" } ) ) ;
6885
6986 const server = initServer ( ) ;
0 commit comments