@visulima/api-platform
Version:
Visulima API platform is a set of tools to build and consume web APIs
1 lines • 4.82 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,CAAsH,CAAA,CAACC,CAAU,CAAA,EACnIC,GAAAA,CAAAA,CAAeD,CAAO,CAAA,CAGnBE,CAAQH,CAAAA,MCFTI,CACF,CAAA,CAAC,CACG,UAAA,CAAAC,CACA,CAAA,MAAA,CAAAC,CAAS,CAAA,sBAAA,CACT,QAAAC,CACA,CAAA,OAAA,CAAAC,CACJ,CAAA,GAMCC,CACI,GAAA,CACG,GAAGA,CAAAA,CACH,QAAS,CAACC,CAAAA,CAAuBT,CAAkC,GAAA,CAC/D,GAAI,CAACA,CAAQ,CAAA,QAAA,CACT,OAAOS,CAQX,CAAA,GALIJ,CAAO,CAAA,UAAA,CAAW,GAAG,CAAA,GAErBA,CAASA,CAAAA,CAAAA,CAAO,MAAM,CAAC,CAAA,CAAA,CAGvB,CAACA,CAAAA,CAAO,QAAS,CAAA,OAAO,CACxB,CAAA,MAAM,IAAI,KAAM,CAAA,qCAAqC,CA6BzD,CAAA,OAzBAI,CAAS,CAAA,CACL,GAAGA,CAAAA,CACH,OAAS,CAAA,CAEL,GAAGA,CAAAA,CAAO,OACV,CAAA,IAAIC,qBACA,CAAA,CAAA,EAAGV,EAAQ,GAAG,CAAA,CAAA,EAAIK,CAAM,CAAA,CAAA,CACxBC,CAAQ,CAAA,GAAA,CAAKK,CAAW,EAAA,CACpB,IAAMC,CAAeC,CAAAA,IAAAA,CAAKb,CAAQ,CAAA,GAAA,CAAeW,CAAO,CAAA,OAAA,CAAQ,IAAM,CAAA,EAAE,CAAC,CAGzE,CAAA,OAAAG,CAAG,CAAA,SAAA,CAAUF,CAAY,CAAA,CAAE,WAAY,EAAA,CAEhCA,CACX,CAAC,CAAA,CACD,CAEI,OAAA,CAAS,OACT,CAAA,GAAGR,CACP,CAAA,CACA,CAAE,OAAAG,CAAAA,CAAQ,CACd,CACJ,CACJ,CAAA,CAEI,OAAOC,CAAAA,CAAW,SAAY,UACvBA,CAAAA,CAAAA,CAAW,OAAQC,CAAAA,CAAAA,CAAQT,CAAO,CAAA,CAGtCS,CACX,CACJ,GAEDM,CAAQZ,CAAAA","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"]}