next-openapi-gen 0.10.3 → 0.10.5
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.
|
@@ -148,9 +148,9 @@ export class PagesRouterStrategy {
|
|
|
148
148
|
if (respSetMatch) {
|
|
149
149
|
responseSet = respSetMatch[1].trim();
|
|
150
150
|
}
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
addResponses =
|
|
151
|
+
const addMatches = [...cleanedComment.matchAll(/@add\s+([^\n\r@]*)/g)];
|
|
152
|
+
if (addMatches.length > 0) {
|
|
153
|
+
addResponses = addMatches.map((m) => m[1].trim()).join(",");
|
|
154
154
|
}
|
|
155
155
|
const opIdMatch = cleanedComment.match(/@operationId\s+(\S+)/);
|
|
156
156
|
if (opIdMatch) {
|
|
@@ -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);
|
|
@@ -102,6 +102,8 @@ export class RouteProcessor {
|
|
|
102
102
|
customResponses.forEach((responseRef) => {
|
|
103
103
|
const [code, ref] = responseRef.split(":");
|
|
104
104
|
if (ref) {
|
|
105
|
+
// Ensure the referenced schema is resolved (triggers Zod converter)
|
|
106
|
+
this.schemaProcessor.getSchemaContent({ responseType: ref });
|
|
105
107
|
// Custom schema: "409:ConflictResponse"
|
|
106
108
|
// 204 No Content should not have a content section per HTTP/OpenAPI spec
|
|
107
109
|
if (code === "204") {
|
|
@@ -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) {
|
package/dist/lib/utils.js
CHANGED
|
@@ -123,10 +123,9 @@ export function extractJSDocComments(path) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
if (commentValue.includes("@add")) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
addResponses = match[1].trim();
|
|
126
|
+
const matches = [...commentValue.matchAll(/@add\s+([^\n\r@]*)/g)];
|
|
127
|
+
if (matches.length > 0) {
|
|
128
|
+
addResponses = matches.map((m) => m[1].trim()).join(",");
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
if (commentValue.includes("@operationId")) {
|
|
@@ -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