@visulima/api-platform
Version:
Visulima API platform is a set of tools to build and consume web APIs
1 lines • 4.84 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/framework/next/routes/api/swagger.ts","../../../src/framework/next/webpack/with-open-api.ts"],"names":["swaggerApiRoute","options","swagger_handler_default","swagger_default","withOpenApi","definition","output","sources","verbose","nextConfig","config","SwaggerCompilerPlugin","source","combinedPath","join","fs","with_open_api_default"],"mappings":"4PAOA,IAAMA,CAAAA,CAAsH,CAACC,CAAAA,CAAU,EAAC,GACpIC,CAAAA,CAAeD,CAAO,CAAA,CAGnBE,CAAAA,CAAQH,MCFTI,CAAAA,CACF,CAAC,CACG,UAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CAAS,sBAAA,CACT,QAAAC,CAAAA,CACA,OAAA,CAAAC,CACJ,CAAA,GAMCC,CAAAA,GACI,CACG,GAAGA,CAAAA,CACH,QAAS,CAACC,CAAAA,CAAuBT,CAAAA,GAAkC,CAC/D,GAAI,CAACA,CAAAA,CAAQ,QAAA,CACT,OAAOS,CAAAA,CAQX,GALIJ,CAAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAErBA,CAAAA,CAASA,CAAAA,CAAO,MAAM,CAAC,CAAA,CAAA,CAGvB,CAACA,CAAAA,CAAO,QAAA,CAAS,OAAO,CAAA,CACxB,MAAM,IAAI,KAAA,CAAM,qCAAqC,CAAA,CA6BzD,OAzBAI,CAAAA,CAAS,CACL,GAAGA,CAAAA,CACH,OAAA,CAAS,CAEL,GAAGA,CAAAA,CAAO,OAAA,CACV,IAAIC,qBAAAA,CACA,CAAA,EAAGV,EAAQ,GAAG,CAAA,CAAA,EAAIK,CAAM,CAAA,CAAA,CACxBC,CAAAA,CAAQ,GAAA,CAAKK,CAAAA,EAAW,CACpB,IAAMC,CAAAA,CAAeC,IAAAA,CAAKb,CAAAA,CAAQ,GAAA,CAAeW,CAAAA,CAAO,OAAA,CAAQ,IAAA,CAAM,EAAE,CAAC,CAAA,CAGzE,OAAAG,CAAAA,CAAG,SAAA,CAAUF,CAAY,CAAA,CAAE,WAAA,EAAY,CAEhCA,CACX,CAAC,CAAA,CACD,CAEI,OAAA,CAAS,OAAA,CACT,GAAGR,CACP,CAAA,CACA,CAAE,OAAA,CAAAG,CAAQ,CACd,CACJ,CACJ,CAAA,CAEI,OAAOC,CAAAA,CAAW,SAAY,UAAA,CACvBA,CAAAA,CAAW,OAAA,CAAQC,CAAAA,CAAQT,CAAO,CAAA,CAGtCS,CACX,CACJ,GAEDM,CAAAA,CAAQZ","file":"index-server.mjs","sourcesContent":["import type { SwaggerHandlerOptions } from \"../../../../swagger/api/swagger-handler\";\nimport swaggerHandler from \"../../../../swagger/api/swagger-handler\";\n\n/**\n * @deprecated Use `import { swaggerHandler } from \"@visulima/api-platform\"` instead.\n */\n\nconst swaggerApiRoute: <M extends string, PrismaClient>(options: Partial<SwaggerHandlerOptions<M, PrismaClient>>) => void = (options = {}) =>\n swaggerHandler(options);\n\n// eslint-disable-next-line deprecation/deprecation\nexport default swaggerApiRoute;\n","import fs from \"node:fs\";\n\nimport type { BaseDefinition } from \"@visulima/jsdoc-open-api\";\nimport { SwaggerCompilerPlugin } from \"@visulima/jsdoc-open-api\";\nimport { join } from \"@visulima/path\";\nimport type { NextJsWebpackConfig, WebpackConfigContext } from \"next/dist/server/config-shared\";\nimport type { NextConfig } from \"next/types\";\nimport type { Configuration } from \"webpack\";\n\nconst withOpenApi =\n ({\n definition,\n output = \"swagger/swagger.json\",\n sources,\n verbose,\n }: {\n definition: Exclude<BaseDefinition, \"openapi\"> & { openapi?: string };\n output: string;\n sources: string[];\n verbose?: boolean;\n }) =>\n (nextConfig: NextConfig): NextConfig =>\n ({\n ...nextConfig,\n webpack: (config: Configuration, options: WebpackConfigContext) => {\n if (!options.isServer) {\n return config;\n }\n\n if (output.startsWith(\"/\")) {\n // eslint-disable-next-line no-param-reassign\n output = output.slice(1);\n }\n\n if (!output.endsWith(\".json\")) {\n throw new Error(\"The output path must end with .json\");\n }\n\n // eslint-disable-next-line no-param-reassign\n config = {\n ...config,\n plugins: [\n // @ts-expect-error: ignore\n ...config.plugins,\n new SwaggerCompilerPlugin(\n `${options.dir}/${output}`,\n sources.map((source) => {\n const combinedPath = join(options.dir as string, source.replace(\"./\", \"\"));\n\n // Check if the path is a directory\n fs.lstatSync(combinedPath).isDirectory();\n\n return combinedPath;\n }),\n {\n // @ts-expect-error: This property should be overwritten\n openapi: \"3.0.0\",\n ...definition,\n },\n { verbose },\n ),\n ],\n };\n\n if (typeof nextConfig.webpack === \"function\") {\n return nextConfig.webpack(config, options) as NextJsWebpackConfig;\n }\n\n return config as NextJsWebpackConfig;\n },\n }) as NextConfig;\n\nexport default withOpenApi;\n"]}