@omer-x/next-openapi-json-generator 1.2.2 → 1.3.1
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.
- package/dist/index.cjs +10 -5
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -122,17 +122,19 @@ async function isDocumentedRoute(routePath2) {
|
|
|
122
122
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
123
123
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
124
124
|
|
|
125
|
-
// src/
|
|
125
|
+
// src/utils/generateRandomString.ts
|
|
126
126
|
function generateRandomString(length) {
|
|
127
127
|
return [...Array(length)].map(() => Math.random().toString(36)[2]).join("");
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
// src/utils/string-preservation.ts
|
|
129
131
|
function preserveStrings(code2) {
|
|
130
132
|
let replacements = {};
|
|
131
|
-
const output = code2.replace(/(['"`])(
|
|
133
|
+
const output = code2.replace(/(['"`])((?:\\.|(?!\1).)*)\1/g, (match, quote, content) => {
|
|
132
134
|
const replacementId = generateRandomString(32);
|
|
133
135
|
replacements = {
|
|
134
136
|
...replacements,
|
|
135
|
-
[replacementId]:
|
|
137
|
+
[replacementId]: `${quote}${content}${quote}`
|
|
136
138
|
};
|
|
137
139
|
return `<@~${replacementId}~@>`;
|
|
138
140
|
});
|
|
@@ -143,6 +145,8 @@ function restoreStrings(code2, replacements) {
|
|
|
143
145
|
return replacements[replacementId];
|
|
144
146
|
});
|
|
145
147
|
}
|
|
148
|
+
|
|
149
|
+
// src/core/injectSchemas.ts
|
|
146
150
|
function injectSchemas(code2, refName) {
|
|
147
151
|
const { output: preservedCode, replacements } = preserveStrings(code2);
|
|
148
152
|
const preservedCodeWithSchemasInjected = preservedCode.replace(new RegExp(`\\b${refName}\\.`, "g"), `global.schemas[${refName}].`).replace(new RegExp(`\\b${refName}\\b`, "g"), `"${refName}"`);
|
|
@@ -429,7 +433,8 @@ async function generateOpenApiSpec(schemas, {
|
|
|
429
433
|
rootPath: additionalRootPath,
|
|
430
434
|
servers,
|
|
431
435
|
security,
|
|
432
|
-
securitySchemes
|
|
436
|
+
securitySchemes,
|
|
437
|
+
clearUnusedSchemas: clearUnusedSchemasOption = true
|
|
433
438
|
} = {}) {
|
|
434
439
|
const verifiedOptions = verifyOptions(includeOption, excludeOption);
|
|
435
440
|
const appFolderPath = await findAppFolderPath();
|
|
@@ -467,7 +472,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
467
472
|
version: metadata.version
|
|
468
473
|
},
|
|
469
474
|
servers,
|
|
470
|
-
...clearUnusedSchemas(pathsAndComponents),
|
|
475
|
+
...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
|
|
471
476
|
security,
|
|
472
477
|
tags: []
|
|
473
478
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -11,7 +11,8 @@ type GeneratorOptions = {
|
|
|
11
11
|
servers?: ServerObject[];
|
|
12
12
|
security?: OpenApiDocument["security"];
|
|
13
13
|
securitySchemes?: ComponentsObject["securitySchemes"];
|
|
14
|
+
clearUnusedSchemas?: boolean;
|
|
14
15
|
};
|
|
15
|
-
declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
|
|
16
|
+
declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
|
|
16
17
|
|
|
17
18
|
export { generateOpenApiSpec as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ type GeneratorOptions = {
|
|
|
11
11
|
servers?: ServerObject[];
|
|
12
12
|
security?: OpenApiDocument["security"];
|
|
13
13
|
securitySchemes?: ComponentsObject["securitySchemes"];
|
|
14
|
+
clearUnusedSchemas?: boolean;
|
|
14
15
|
};
|
|
15
|
-
declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
|
|
16
|
+
declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
|
|
16
17
|
|
|
17
18
|
export { generateOpenApiSpec as default };
|
package/dist/index.js
CHANGED
|
@@ -86,17 +86,19 @@ async function isDocumentedRoute(routePath2) {
|
|
|
86
86
|
import fs3 from "node:fs/promises";
|
|
87
87
|
import path2 from "node:path";
|
|
88
88
|
|
|
89
|
-
// src/
|
|
89
|
+
// src/utils/generateRandomString.ts
|
|
90
90
|
function generateRandomString(length) {
|
|
91
91
|
return [...Array(length)].map(() => Math.random().toString(36)[2]).join("");
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
// src/utils/string-preservation.ts
|
|
93
95
|
function preserveStrings(code2) {
|
|
94
96
|
let replacements = {};
|
|
95
|
-
const output = code2.replace(/(['"`])(
|
|
97
|
+
const output = code2.replace(/(['"`])((?:\\.|(?!\1).)*)\1/g, (match, quote, content) => {
|
|
96
98
|
const replacementId = generateRandomString(32);
|
|
97
99
|
replacements = {
|
|
98
100
|
...replacements,
|
|
99
|
-
[replacementId]:
|
|
101
|
+
[replacementId]: `${quote}${content}${quote}`
|
|
100
102
|
};
|
|
101
103
|
return `<@~${replacementId}~@>`;
|
|
102
104
|
});
|
|
@@ -107,6 +109,8 @@ function restoreStrings(code2, replacements) {
|
|
|
107
109
|
return replacements[replacementId];
|
|
108
110
|
});
|
|
109
111
|
}
|
|
112
|
+
|
|
113
|
+
// src/core/injectSchemas.ts
|
|
110
114
|
function injectSchemas(code2, refName) {
|
|
111
115
|
const { output: preservedCode, replacements } = preserveStrings(code2);
|
|
112
116
|
const preservedCodeWithSchemasInjected = preservedCode.replace(new RegExp(`\\b${refName}\\.`, "g"), `global.schemas[${refName}].`).replace(new RegExp(`\\b${refName}\\b`, "g"), `"${refName}"`);
|
|
@@ -393,7 +397,8 @@ async function generateOpenApiSpec(schemas, {
|
|
|
393
397
|
rootPath: additionalRootPath,
|
|
394
398
|
servers,
|
|
395
399
|
security,
|
|
396
|
-
securitySchemes
|
|
400
|
+
securitySchemes,
|
|
401
|
+
clearUnusedSchemas: clearUnusedSchemasOption = true
|
|
397
402
|
} = {}) {
|
|
398
403
|
const verifiedOptions = verifyOptions(includeOption, excludeOption);
|
|
399
404
|
const appFolderPath = await findAppFolderPath();
|
|
@@ -431,7 +436,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
431
436
|
version: metadata.version
|
|
432
437
|
},
|
|
433
438
|
servers,
|
|
434
|
-
...clearUnusedSchemas(pathsAndComponents),
|
|
439
|
+
...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
|
|
435
440
|
security,
|
|
436
441
|
tags: []
|
|
437
442
|
};
|