@visulima/api-platform 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/bin/index.js +46 -0
  3. package/dist/chunk-AOL5OFCG.mjs +284 -0
  4. package/dist/chunk-AOL5OFCG.mjs.map +1 -0
  5. package/dist/chunk-ATZDRT65.js +284 -0
  6. package/dist/chunk-ATZDRT65.js.map +1 -0
  7. package/dist/{chunk-AJKZCWFG.js → chunk-F7RHRCUQ.js} +2 -2
  8. package/dist/chunk-F7RHRCUQ.js.map +1 -0
  9. package/dist/{chunk-XXZ56SKG.mjs → chunk-RPHC5ZGB.mjs} +2 -2
  10. package/dist/chunk-RPHC5ZGB.mjs.map +1 -0
  11. package/dist/index-server.d.ts +4 -14
  12. package/dist/index-server.js +9 -10
  13. package/dist/index-server.js.map +1 -1
  14. package/dist/index-server.mjs +7 -8
  15. package/dist/index-server.mjs.map +1 -1
  16. package/dist/next/cli/index.js +8 -8
  17. package/dist/next/cli/index.js.map +1 -1
  18. package/dist/next/cli/index.mjs +8 -8
  19. package/dist/next/cli/index.mjs.map +1 -1
  20. package/dist/next/index-browser.js +2 -2
  21. package/dist/next/index-browser.mjs +1 -1
  22. package/dist/next/index-server.d.ts +14 -13
  23. package/dist/next/index-server.js +4 -4
  24. package/dist/next/index-server.js.map +1 -1
  25. package/dist/next/index-server.mjs +2 -2
  26. package/dist/next/index-server.mjs.map +1 -1
  27. package/dist/swagger-handler-ffed72c2.d.ts +19 -0
  28. package/next/cli/package.json +12 -3
  29. package/next/package.json +9 -0
  30. package/package.json +20 -20
  31. package/recipes/api/swagger.ts +12 -0
  32. package/recipes/pages/redoc-ui.tsx +5 -0
  33. package/recipes/pages/swagger-ui.tsx +5 -0
  34. package/dist/chunk-2LATTLUM.mjs +0 -166
  35. package/dist/chunk-2LATTLUM.mjs.map +0 -1
  36. package/dist/chunk-AJKZCWFG.js.map +0 -1
  37. package/dist/chunk-S7GUPAL4.js +0 -166
  38. package/dist/chunk-S7GUPAL4.js.map +0 -1
  39. package/dist/chunk-XXZ56SKG.mjs.map +0 -1
  40. package/src/connect/create-node-router.ts +0 -44
  41. package/src/connect/handler.ts +0 -46
  42. package/src/connect/middleware/cors-middleware.ts +0 -10
  43. package/src/connect/middleware/http-header-normalizer.ts +0 -93
  44. package/src/connect/middleware/rate-limiter-middleware.ts +0 -43
  45. package/src/connect/middleware/serializers-middleware.ts +0 -121
  46. package/src/connect/serializers/types.d.ts +0 -1
  47. package/src/connect/serializers/xml.ts +0 -13
  48. package/src/connect/serializers/yaml.ts +0 -7
  49. package/src/error-handler/jsonapi-error-handler.ts +0 -46
  50. package/src/error-handler/problem-error-handler.ts +0 -44
  51. package/src/error-handler/types.d.ts +0 -14
  52. package/src/error-handler/utils.ts +0 -39
  53. package/src/index-browser.tsx +0 -1
  54. package/src/index-server.ts +0 -75
  55. package/src/next/cli/index.ts +0 -2
  56. package/src/next/cli/list/api-route-file-parser.ts +0 -74
  57. package/src/next/cli/list/collect-api-route-files.ts +0 -42
  58. package/src/next/cli/list/list-command.ts +0 -105
  59. package/src/next/cli/list/routes-render.ts +0 -62
  60. package/src/next/cli/list/types.d.ts +0 -1
  61. package/src/next/index-browser.tsx +0 -3
  62. package/src/next/index-server.ts +0 -6
  63. package/src/next/routes/api/swagger.ts +0 -23
  64. package/src/next/routes/pages/swagger/get-static-properties-swagger.ts +0 -32
  65. package/src/next/routes/pages/swagger/redoc.tsx +0 -35
  66. package/src/next/routes/pages/swagger/swagger.tsx +0 -44
  67. package/src/next/webpack/with-open-api.ts +0 -63
  68. package/src/swagger/extend-swagger-spec.ts +0 -167
  69. package/src/swagger/swagger-handler.ts +0 -83
  70. package/src/utils.ts +0 -37
  71. package/src/zod/date-in-schema.ts +0 -57
  72. package/src/zod/date-out-schema.ts +0 -41
  73. package/src/zod/index.ts +0 -9
@@ -1,44 +0,0 @@
1
- import { HttpError } from "http-errors";
2
- import { getReasonPhrase } from "http-status-codes";
3
-
4
- import type { ErrorHandler } from "./types";
5
- import { addStatusCodeToResponse, sendJson, setErrorHeaders } from "./utils";
6
-
7
- const defaultType = "https://tools.ietf.org/html/rfc2616#section-10";
8
- const defaultTitle = "An error occurred";
9
- /**
10
- * Normalizes errors according to the API Problem spec (RFC 7807).
11
- *
12
- * @see https://tools.ietf.org/html/rfc7807
13
- */
14
- const problemErrorHandler: ErrorHandler = (error: HttpError | Error, _request, response) => {
15
- const { stack, message } = error;
16
-
17
- if (error instanceof HttpError) {
18
- const {
19
- statusCode, expose, title, type,
20
- } = error;
21
-
22
- response.statusCode = statusCode;
23
-
24
- setErrorHeaders(response, error);
25
-
26
- sendJson(response, {
27
- type: type || defaultType,
28
- title: title || getReasonPhrase(statusCode) || defaultTitle,
29
- details: message,
30
- ...(expose ? { trace: stack } : {}),
31
- });
32
- } else {
33
- addStatusCodeToResponse(response, error);
34
-
35
- sendJson(response, {
36
- type: defaultType,
37
- title: getReasonPhrase(response.statusCode) || defaultTitle,
38
- details: message,
39
- ...((error as { expose: boolean } & Error).expose ? { trace: stack } : {}),
40
- });
41
- }
42
- };
43
-
44
- export default problemErrorHandler;
@@ -1,14 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from "node:http";
2
-
3
- export type ErrorHandler = <Request extends IncomingMessage, Response extends ServerResponse>(
4
- error: any,
5
- request: Request,
6
- response: Response,
7
- ) => any | Promise<any>;
8
-
9
- export type ErrorHandlers = {
10
- regex: RegExp;
11
- handler: ErrorHandler;
12
- }[];
13
-
14
- export type ApiFormat = "jsonapi" | "problem";
@@ -1,39 +0,0 @@
1
- import { StatusCodes } from "http-status-codes";
2
- import type { ServerResponse } from "node:http";
3
-
4
- export const setErrorHeaders = (response: ServerResponse, error: any) => {
5
- const headers: { [key: string]: number | string | ReadonlyArray<string> } = error.headers || {};
6
-
7
- Object.keys(headers).forEach((header: string) => {
8
- response.setHeader(header, headers[header] as number | string | ReadonlyArray<string>);
9
- });
10
- };
11
-
12
- /**
13
- * Send `JSON` object
14
- * @param response response object
15
- * @param jsonBody of data
16
- */
17
- export const sendJson = (response: ServerResponse, jsonBody: any): void => {
18
- // Set header to application/json
19
- response.setHeader("content-type", "application/json; charset=utf-8");
20
-
21
- response.end(JSON.stringify(jsonBody));
22
- };
23
-
24
- export const addStatusCodeToResponse = (response: ServerResponse, error: any): void => {
25
- // respect err.statusCode
26
- if (typeof error.statusCode !== "undefined") {
27
- response.statusCode = error.statusCode;
28
- }
29
-
30
- // respect err.status
31
- if (typeof error.status !== "undefined") {
32
- response.statusCode = error.status;
33
- }
34
-
35
- // default status code to 500
36
- if (response.statusCode < 400) {
37
- response.statusCode = StatusCodes.INTERNAL_SERVER_ERROR;
38
- }
39
- };
@@ -1 +0,0 @@
1
- export * as zod from "./zod";
@@ -1,75 +0,0 @@
1
- export * from "./index-browser";
2
-
3
- export {
4
- default as createHttpError,
5
- BadRequest,
6
- Forbidden,
7
- BadGateway,
8
- BandwidthLimitExceeded,
9
- Conflict,
10
- ExpectationFailed,
11
- FailedDependency,
12
- GatewayTimeout,
13
- Gone,
14
- HTTPVersionNotSupported,
15
- ImATeapot,
16
- InsufficientStorage,
17
- InternalServerError,
18
- VariantAlsoNegotiates,
19
- ProxyAuthenticationRequired,
20
- NetworkAuthenticationRequire,
21
- LengthRequired,
22
- LoopDetected,
23
- Locked,
24
- MethodNotAllowed,
25
- MisdirectedRequest,
26
- NotAcceptable,
27
- NotExtended,
28
- NotFound,
29
- NotImplemented,
30
- PayloadTooLarge,
31
- RequestHeaderFieldsTooLarge,
32
- PaymentRequired,
33
- PreconditionFailed,
34
- PreconditionRequired,
35
- RangeNotSatisfiable,
36
- RequestTimeout,
37
- ServiceUnavailable,
38
- TooManyRequests,
39
- Unauthorized,
40
- UnorderedCollection,
41
- UnprocessableEntity,
42
- UnavailableForLegalReasons,
43
- UnsupportedMediaType,
44
- UpgradeRequired,
45
- URITooLong,
46
- } from "http-errors";
47
-
48
- export { default as createNodeRouter } from "./connect/create-node-router";
49
- export { onError, onNoMatch } from "./connect/handler";
50
- export type {
51
- EdgeRequestHandler,
52
- ExpressRequestHandler,
53
- NodeRequestHandler,
54
- Route,
55
- HandlerOptions,
56
- NextHandler,
57
- FunctionLike,
58
- Nextable,
59
- ValueOrPromise,
60
- FindResult,
61
- RouteShortcutMethod,
62
- HttpMethod,
63
- } from "@visulima/connect";
64
- export {
65
- createEdgeRouter, EdgeRouter, expressWrapper, NodeRouter, Router, withZod, sendJson,
66
- } from "@visulima/connect";
67
-
68
- export { default as rateLimiterMiddleware } from "./connect/middleware/rate-limiter-middleware";
69
- export { default as corsMiddleware } from "./connect/middleware/cors-middleware";
70
- export { default as serializersMiddleware } from "./connect/middleware/serializers-middleware";
71
- export { default as httpHeaderNormalizerMiddleware } from "./connect/middleware/http-header-normalizer";
72
-
73
- export { default as swaggerHandler } from "./swagger/swagger-handler";
74
-
75
- export { dateIn, dateOut } from "./zod";
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
- export { default as listCommand } from "./list/list-command";
@@ -1,74 +0,0 @@
1
- import type { OpenApiObject } from "@visulima/jsdoc-open-api";
2
- import { jsDocumentCommentsToOpenApi, parseFile, swaggerJsDocumentCommentsToOpenApi } from "@visulima/jsdoc-open-api";
3
- import fs from "node:fs";
4
- import process from "node:process";
5
-
6
- import type { Route } from "./types";
7
-
8
- const extensionRegex = /\.(js|ts|mjs|cjs)$/;
9
-
10
- const apiRouteFileParser = (apiRouteFile: string, cwdPath: string, verbose: boolean = false): Route[] => {
11
- let specs: OpenApiObject[] = [];
12
-
13
- const parsedJsDocumentFile = parseFile(apiRouteFile, jsDocumentCommentsToOpenApi, verbose);
14
-
15
- specs = [...specs, ...parsedJsDocumentFile.map((item) => item.spec)];
16
-
17
- const parsedSwaggerJsDocumentFile = parseFile(apiRouteFile, swaggerJsDocumentCommentsToOpenApi, verbose);
18
-
19
- specs = [...specs, ...parsedSwaggerJsDocumentFile.map((item) => item.spec)];
20
-
21
- const routes: Route[] = [];
22
-
23
- if (specs.length === 0) {
24
- const apiRouteFileContent = fs.readFileSync(apiRouteFile, "utf8");
25
-
26
- apiRouteFileContent.split(/\r?\n/).forEach((line) => {
27
- const match = line.match(/[=aces|]+\s["'|](GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS)["'|]/);
28
-
29
- if (match) {
30
- let [, method] = match;
31
-
32
- if (method === "GET") {
33
- method = "GET|HEAD";
34
- }
35
-
36
- routes.push({
37
- method: method as string,
38
- path: apiRouteFile.replace(cwdPath, "").replace(extensionRegex, ""),
39
- tags: [],
40
- file: apiRouteFile.replace(`${process.cwd()}/`, ""),
41
- });
42
- }
43
- });
44
-
45
- if (routes.length === 0) {
46
- routes.push({
47
- method: "GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS",
48
- path: apiRouteFile.replace(cwdPath, "").replace(extensionRegex, ""),
49
- tags: [],
50
- file: apiRouteFile.replace(`${process.cwd()}/`, ""),
51
- });
52
- }
53
-
54
- return routes;
55
- }
56
-
57
- specs.forEach((spec) => {
58
- const paths = Object.entries(spec.paths);
59
-
60
- paths.forEach(([path, pathSpec]) => {
61
- const methods = Object.entries(pathSpec);
62
-
63
- methods.forEach(([method, methodSpec]) => {
64
- routes.push({
65
- path, method: method.toUpperCase(), tags: methodSpec.tags, file: apiRouteFile.replace(`${process.cwd()}/`, ""),
66
- });
67
- });
68
- });
69
- });
70
-
71
- return routes;
72
- };
73
-
74
- export default apiRouteFileParser;
@@ -1,42 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import { collect } from "@visulima/readdir";
3
- import fs from "node:fs";
4
- import { join } from "node:path";
5
-
6
- const isDirectory = (path: string): boolean => {
7
- try {
8
- return fs.statSync(path).isDirectory();
9
- } catch {
10
- return false;
11
- }
12
- };
13
-
14
- const collectApiRouteFiles = async (path: string = "", verbose: boolean = false): Promise<string[]> => {
15
- let apiFolderPath = join(path, "pages/api");
16
-
17
- // src/pages will be ignored if pages is present in the root directory
18
- if (!isDirectory(apiFolderPath)) {
19
- apiFolderPath = join(path, "src/pages/api");
20
-
21
- if (!isDirectory(apiFolderPath)) {
22
- return [];
23
- }
24
- }
25
-
26
- return collect(apiFolderPath, {
27
- extensions: [".js", ".cjs", ".mjs", ".ts"],
28
- includeDirs: false,
29
- minimatchOptions: {
30
- match: {
31
- debug: verbose,
32
- matchBase: true,
33
- },
34
- skip: {
35
- debug: verbose,
36
- matchBase: true,
37
- },
38
- },
39
- });
40
- };
41
-
42
- export default collectApiRouteFiles;
@@ -1,105 +0,0 @@
1
- import colors from "chalk";
2
- import { join } from "node:path";
3
- import process from "node:process";
4
-
5
- import apiRouteFileParser from "./api-route-file-parser";
6
- import collectApiRouteFiles from "./collect-api-route-files";
7
- import routesRender from "./routes-render";
8
- import type { Route } from "./types";
9
-
10
- type RenderOptions = {
11
- includePaths: string[];
12
- excludePaths: string[];
13
- methods: string[];
14
- group: string;
15
- };
16
-
17
- const groupBy = (list: Route[], keyGetter: (item: Route) => keyof Route): Map<string, Route[]> => {
18
- const map = new Map();
19
-
20
- list.forEach((item) => {
21
- const key = keyGetter(item);
22
- const collection = map.get(key);
23
-
24
- if (!collection) {
25
- map.set(key, [item]);
26
- } else {
27
- collection.push(item);
28
- }
29
- });
30
-
31
- return map;
32
- };
33
-
34
- const listCommand = async (
35
- path: string = "",
36
- options: Partial<
37
- {
38
- verbose: boolean;
39
- } & RenderOptions
40
- > = {},
41
- // eslint-disable-next-line radar/cognitive-complexity
42
- ) => {
43
- const routePath = join(process.cwd(), path);
44
-
45
- const apiRouteFiles = await collectApiRouteFiles(routePath, options.verbose || false);
46
-
47
- if (apiRouteFiles.length === 0) {
48
- // eslint-disable-next-line no-console
49
- console.error(`No API routes found, in "${routePath}".`);
50
- // eslint-disable-next-line unicorn/no-process-exit
51
- process.exit(1);
52
- }
53
-
54
- let parsedApiRoutes = apiRouteFiles.flatMap((apiRouteFile) => apiRouteFileParser(apiRouteFile, routePath, options.verbose || false));
55
-
56
- if (options.includePaths) {
57
- parsedApiRoutes = options.includePaths.flatMap((ipath) => parsedApiRoutes.filter((route) => route.path.startsWith(ipath)));
58
- }
59
-
60
- if (options.excludePaths) {
61
- parsedApiRoutes = options.excludePaths.flatMap((epath) => parsedApiRoutes.filter((route) => !route.path.startsWith(epath)));
62
- }
63
-
64
- if (typeof options.group !== "undefined") {
65
- const groupedMap = groupBy(parsedApiRoutes, (route) => {
66
- if (options.group === "path") {
67
- return route.path.replace("/pages", "").split("/")[1];
68
- }
69
-
70
- return route.tags[0] || "unsorted";
71
- });
72
-
73
- let counter = 0;
74
-
75
- groupedMap.forEach((routes, key) => {
76
- if (counter > 0) {
77
- // eslint-disable-next-line no-console
78
- console.log();
79
- }
80
-
81
- const dotsCount = (process.stdout.columns - 16 - key.length) / 2;
82
- const dots = dotsCount > 0 ? Array.from({ length: dotsCount }).fill(" ").join("") : "";
83
- // eslint-disable-next-line no-console
84
- console.log(dots + colors.bold.underline(key));
85
-
86
- routesRender(routes, options).forEach((renderedRoute) => {
87
- // eslint-disable-next-line no-console
88
- console.log(renderedRoute);
89
- });
90
-
91
- counter += 1;
92
- });
93
- } else {
94
- routesRender([], options).forEach((renderedRoute) => {
95
- // eslint-disable-next-line no-console
96
- console.log(renderedRoute);
97
- });
98
- }
99
- // });
100
-
101
- // eslint-disable-next-line no-console
102
- console.log(`\n Listed ${colors.greenBright(String(apiRouteFiles.length))} HTTP ${apiRouteFiles.length === 1 ? "route" : "routes"}.\n`);
103
- };
104
-
105
- export default listCommand;
@@ -1,62 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import colors from "chalk";
3
-
4
- import type { Route } from "./types";
5
-
6
- const renderRoute = (method: string, routePath: string): string => {
7
- const colorMap = {
8
- GET: colors.blue,
9
- POST: colors.yellow,
10
- PATCH: colors.yellow,
11
- PUT: colors.yellow,
12
- DELETE: colors.redBright,
13
- OPTIONS: colors.hex("#6C7280"),
14
- ANY: colors.redBright,
15
- HEAD: colors.hex("#6C7280"),
16
- };
17
-
18
- let methodText: string;
19
-
20
- if (method === "GET|HEAD") {
21
- methodText = `${colors.blue("GET")}${colors.grey("|HEAD")}`;
22
- } else {
23
- const coloredMethod = colorMap[method as keyof typeof colorMap](method);
24
-
25
- methodText = method === "GET" ? `${coloredMethod}${colors.grey("|HEAD")}` : coloredMethod;
26
- }
27
-
28
- const spacesCount = method === "GET" ? 6 : 14 - method.length;
29
- const spaces = Array.from({ length: spacesCount }).fill(" ").join("");
30
-
31
- const dotsCount = process.stdout.columns - 16 - routePath.length - 4;
32
- const dots = dotsCount > 0 ? Array.from({ length: dotsCount }).fill(".").join("") : "";
33
-
34
- const routeText = routePath
35
- .split("/")
36
- .map((segment) => {
37
- const isDynamicSegment = ["[", ":"].includes(segment[0] || "");
38
-
39
- return isDynamicSegment ? colors.yellowBright(segment) : segment;
40
- })
41
- .join("/");
42
-
43
- return ` ${methodText}${spaces}${routeText}${colors.grey(dots)}`;
44
- };
45
-
46
- const routesRender = (routesMap: Route[], options: { methods?: string[]; } = {}) => routesMap
47
- .map((route) => {
48
- if (options.methods && options.methods.includes(route.method)) {
49
- return;
50
- }
51
-
52
- if (route.method === "GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS") {
53
- // eslint-disable-next-line no-param-reassign
54
- route.method = "ANY";
55
- }
56
-
57
- // eslint-disable-next-line consistent-return
58
- return renderRoute(route.method, route.path.replace("/pages", ""));
59
- })
60
- .filter(Boolean);
61
-
62
- export default routesRender;
@@ -1 +0,0 @@
1
- export type Route = { path: string; method: string; tags: any; file: string };
@@ -1,3 +0,0 @@
1
- export { default as RedocPage } from "./routes/pages/swagger/redoc";
2
- export { default as SwaggerPage } from "./routes/pages/swagger/swagger";
3
- export { default as getSwaggerStaticProps } from "./routes/pages/swagger/get-static-properties-swagger";
@@ -1,6 +0,0 @@
1
- export * from "./index-browser";
2
-
3
- // eslint-disable-next-line import/prefer-default-export
4
- export { default as withOpenApi } from "./webpack/with-open-api";
5
-
6
- export { default as swaggerApiRoute } from "./routes/api/swagger";
@@ -1,23 +0,0 @@
1
- import { createNodeRouter } from "@visulima/connect";
2
- // eslint-disable-next-line unicorn/prevent-abbreviations,import/no-extraneous-dependencies
3
- import type { ModelsToOpenApiParameters } from "@visulima/crud";
4
- import type { NextApiRequest, NextApiResponse } from "next";
5
-
6
- import swaggerHandler from "../../../swagger/swagger-handler";
7
-
8
- // eslint-disable-next-line max-len
9
- const swaggerApiRoute = (
10
- options: Partial<{
11
- allowedMediaTypes: { [key: string]: boolean };
12
- swaggerFilePath: string;
13
- crud: Exclude<ModelsToOpenApiParameters, "swagger.allowedMediaTypes">;
14
- }> = {},
15
- ) => {
16
- const handler = swaggerHandler(options);
17
-
18
- const router = createNodeRouter<NextApiRequest, NextApiResponse>().get(handler);
19
-
20
- return router.handler();
21
- };
22
-
23
- export default swaggerApiRoute;
@@ -1,32 +0,0 @@
1
- // eslint-disable-next-line unicorn/prevent-abbreviations
2
- import debug from "debug";
3
- import type { GetStaticProps } from "next";
4
- import type { OAS3Definition } from "swagger-jsdoc";
5
-
6
- // eslint-disable-next-line testing-library/no-debugging-utils
7
- const swaggerDebug = debug("visulima:api-platform:swagger:get-static-properties-swagger");
8
-
9
- // eslint-disable-next-line unicorn/consistent-function-scoping
10
- const getStaticProps: (
11
- swaggerUrl: string,
12
- ) => GetStaticProps = (swaggerUrl) => async (): Promise<{
13
- props: {
14
- swaggerUrl: string;
15
- swaggerData: OAS3Definition;
16
- };
17
- }> => {
18
- // eslint-disable-next-line compat/compat
19
- const response = await fetch(swaggerUrl);
20
- const swaggerData = await response.json();
21
-
22
- swaggerDebug(swaggerData);
23
-
24
- return {
25
- props: {
26
- swaggerUrl,
27
- swaggerData: JSON.parse(JSON.stringify(swaggerData)),
28
- },
29
- };
30
- };
31
-
32
- export default getStaticProps;
@@ -1,35 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import type { InferGetStaticPropsType, NextPage } from "next";
3
- // eslint-disable-next-line import/no-extraneous-dependencies
4
- import Head from "next/head";
5
- import React from "react";
6
- // eslint-disable-next-line import/no-extraneous-dependencies
7
- import type { RedocStandaloneProps } from "redoc";
8
- // eslint-disable-next-line import/no-extraneous-dependencies
9
- import { RedocStandalone } from "redoc";
10
-
11
- import getStaticProps from "./get-static-properties-swagger";
12
-
13
- // eslint-disable-next-line max-len
14
- const RedocApiDocument: (
15
- name: string,
16
- swagger?: Exclude<RedocStandaloneProps, "spec">,
17
- // eslint-disable-next-line max-len,unicorn/no-useless-undefined
18
- ) => NextPage<InferGetStaticPropsType<typeof getStaticProps>> = (name, swagger = {}) => ({ swaggerData }: InferGetStaticPropsType<typeof getStaticProps>) => (
19
- <>
20
- <Head>
21
- <title>{name}</title>
22
- <style>
23
- {`
24
- body {
25
- background: #fafafa !important;
26
- }
27
- `}
28
- </style>
29
- </Head>
30
- {/* eslint-disable-next-line react/jsx-props-no-spreading */}
31
- <RedocStandalone {...swagger} spec={swaggerData} />
32
- </>
33
- );
34
-
35
- export default RedocApiDocument;
@@ -1,44 +0,0 @@
1
- import type { InferGetStaticPropsType, NextPage } from "next";
2
- import dynamic from "next/dynamic";
3
- // eslint-disable-next-line import/no-extraneous-dependencies
4
- import Head from "next/head";
5
- // eslint-disable-next-line import/no-extraneous-dependencies
6
- import React from "react";
7
- import type { SwaggerUIProps } from "swagger-ui-react";
8
-
9
- import getStaticProps from "./get-static-properties-swagger";
10
- // eslint-disable-next-line import/no-extraneous-dependencies
11
- const SwaggerUI = dynamic<{
12
- spec: any;
13
- // @ts-ignore
14
- // eslint-disable-next-line import/no-extraneous-dependencies
15
- }>(import("swagger-ui-react"), { ssr: false });
16
- dynamic<{
17
- spec: any;
18
- // @ts-ignore
19
- // eslint-disable-next-line import/no-extraneous-dependencies
20
- }>(import("swagger-ui-react/swagger-ui.css"), { ssr: false });
21
-
22
- // eslint-disable-next-line max-len
23
- const SwaggerApiDocument: (
24
- name: string,
25
- swagger?: Exclude<SwaggerUIProps, "spec">,
26
- // eslint-disable-next-line max-len,unicorn/no-useless-undefined
27
- ) => NextPage<InferGetStaticPropsType<typeof getStaticProps>> = (name, swagger = {}) => ({ swaggerData }: InferGetStaticPropsType<typeof getStaticProps>) => (
28
- <>
29
- <Head>
30
- <title>{name}</title>
31
- <style>
32
- {`
33
- body {
34
- background: #fafafa !important;
35
- }
36
- `}
37
- </style>
38
- </Head>
39
- {/* eslint-disable-next-line react/jsx-props-no-spreading */}
40
- <SwaggerUI {...swagger} spec={swaggerData} />
41
- </>
42
- );
43
-
44
- export default SwaggerApiDocument;