Download .opencode/node_modules/effect/src/unstable/httpapi/HttpApiSwagger.ts from Chenloong999/opencode-data: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/httpapi/HttpApiSwagger.ts
- Command line
-
hf download hf://datasets/Chenloong999/opencode-data@84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/httpapi/HttpApiSwagger.ts
-
curl -L -o HttpApiSwagger.ts https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/httpapi/HttpApiSwagger.ts
1.94 kB
| /** | |
| * @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 = <Id extends string, Groups extends HttpApiGroup.Any>(options: { | |
| readonly api: HttpApi.HttpApi<Id, Groups> | |
| }) => { | |
| const spec = OpenApi.fromApi(options.api) | |
| const response = HttpServerResponse.html(`<!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>${Html.escape(spec.info.title)} Documentation</title> | |
| <style>${internal.css}</style> | |
| </head> | |
| <body> | |
| <div id="swagger-ui"></div> | |
| <script id="swagger-spec" type="application/json"> | |
| ${Html.escapeJson(spec)} | |
| </script> | |
| <script> | |
| ${internal.javascript} | |
| window.onload = () => { | |
| window.ui = SwaggerUIBundle({ | |
| spec: JSON.parse(document.getElementById("swagger-spec").textContent), | |
| dom_id: "#swagger-ui", | |
| }); | |
| }; | |
| </script> | |
| </body> | |
| </html>`) | |
| 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 = <Id extends string, Groups extends HttpApiGroup.Any>( | |
| api: HttpApi.HttpApi<Id, Groups>, | |
| options?: { | |
| readonly path?: `/${string}` | undefined | |
| } | |
| ): Layer.Layer<never, never, HttpRouter.HttpRouter> => | |
| HttpRouter.use(Effect.fnUntraced(function*(router) { | |
| const handler = makeHandler({ api }) | |
| yield* router.add("GET", options?.path ?? "/docs", handler) | |
| })) | |