next-openapi-gen 0.10.3 → 0.10.4
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.
|
@@ -16,7 +16,7 @@ export class RouteProcessor {
|
|
|
16
16
|
processFileTracker = {};
|
|
17
17
|
constructor(config) {
|
|
18
18
|
this.config = config;
|
|
19
|
-
this.schemaProcessor = new SchemaProcessor(config.schemaDir, config.schemaType, config.schemaFiles);
|
|
19
|
+
this.schemaProcessor = new SchemaProcessor(config.schemaDir, config.schemaType, config.schemaFiles, config.apiDir);
|
|
20
20
|
this.strategy = config.routerType === "pages"
|
|
21
21
|
? new PagesRouterStrategy(config)
|
|
22
22
|
: new AppRouterStrategy(config);
|
|
@@ -36,12 +36,12 @@ export class SchemaProcessor {
|
|
|
36
36
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
37
37
|
importMap = {}; // { filePath: { importName: importPath } }
|
|
38
38
|
currentFilePath = ""; // Track the file being processed
|
|
39
|
-
constructor(schemaDir, schemaType = "typescript", schemaFiles) {
|
|
39
|
+
constructor(schemaDir, schemaType = "typescript", schemaFiles, apiDir) {
|
|
40
40
|
this.schemaDirs = normalizeSchemaDirs(schemaDir).map((d) => path.resolve(d));
|
|
41
41
|
this.schemaTypes = normalizeSchemaTypes(schemaType);
|
|
42
42
|
// Initialize Zod converter if Zod is enabled
|
|
43
43
|
if (this.schemaTypes.includes("zod")) {
|
|
44
|
-
this.zodSchemaConverter = new ZodSchemaConverter(schemaDir);
|
|
44
|
+
this.zodSchemaConverter = new ZodSchemaConverter(schemaDir, apiDir);
|
|
45
45
|
}
|
|
46
46
|
// Load custom schema files if provided
|
|
47
47
|
if (schemaFiles && schemaFiles.length > 0) {
|
|
@@ -12,6 +12,7 @@ import { DrizzleZodProcessor } from "./drizzle-zod-processor.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export class ZodSchemaConverter {
|
|
14
14
|
schemaDirs;
|
|
15
|
+
apiDir;
|
|
15
16
|
zodSchemas = {};
|
|
16
17
|
processingSchemas = new Set();
|
|
17
18
|
processedModules = new Set();
|
|
@@ -25,9 +26,10 @@ export class ZodSchemaConverter {
|
|
|
25
26
|
currentFilePath;
|
|
26
27
|
currentAST;
|
|
27
28
|
currentImports;
|
|
28
|
-
constructor(schemaDir) {
|
|
29
|
+
constructor(schemaDir, apiDir) {
|
|
29
30
|
const dirs = Array.isArray(schemaDir) ? schemaDir : [schemaDir];
|
|
30
31
|
this.schemaDirs = dirs.map((d) => path.resolve(d));
|
|
32
|
+
this.apiDir = apiDir ? path.resolve(apiDir) : undefined;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Find a Zod schema by name and convert it to OpenAPI spec
|
|
@@ -88,6 +90,14 @@ export class ZodSchemaConverter {
|
|
|
88
90
|
*/
|
|
89
91
|
findRouteFiles() {
|
|
90
92
|
const routeFiles = [];
|
|
93
|
+
// When apiDir is configured, scan only that directory to prevent
|
|
94
|
+
// leaking schemas from routes outside the configured API boundary.
|
|
95
|
+
if (this.apiDir) {
|
|
96
|
+
if (fs.existsSync(this.apiDir)) {
|
|
97
|
+
this.findRouteFilesInDir(this.apiDir, routeFiles);
|
|
98
|
+
}
|
|
99
|
+
return routeFiles;
|
|
100
|
+
}
|
|
91
101
|
// Look for route files in common Next.js API directories
|
|
92
102
|
const possibleApiDirs = [
|
|
93
103
|
path.join(process.cwd(), "src", "app", "api"),
|
package/package.json
CHANGED