/** * @since 4.0.0 */ import * as Effect from "../../Effect.ts" import type * as Layer from "../../Layer.ts" import * as HttpRouter from "../http/HttpRouter.ts" import * as HttpServerResponse from "../http/HttpServerResponse.ts" import type * as HttpApi from "./HttpApi.ts" import type * as HttpApiGroup from "./HttpApiGroup.ts" import * as Html from "./internal/html.ts" import * as internal from "./internal/httpApiSwagger.ts" import * as OpenApi from "./OpenApi.ts" const makeHandler = (options: { readonly api: HttpApi.HttpApi }) => { const spec = OpenApi.fromApi(options.api) const response = HttpServerResponse.html(` ${Html.escape(spec.info.title)} Documentation
`) return Effect.succeed(response) } /** * Exported layer mounting Swagger/OpenAPI documentation UI. * * @param options.path Optional mount path (default "/docs"). * * @since 4.0.0 * @category layers */ export const layer = ( api: HttpApi.HttpApi, options?: { readonly path?: `/${string}` | undefined } ): Layer.Layer => HttpRouter.use(Effect.fnUntraced(function*(router) { const handler = makeHandler({ api }) yield* router.add("GET", options?.path ?? "/docs", handler) }))