next-openapi-gen 0.7.3 → 0.7.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.
package/README.md CHANGED
@@ -60,6 +60,7 @@ During initialization (`npx next-openapi-gen init`), a configuration file `next.
60
60
  "schemaDir": "src/types", // or "src/schemas" for Zod schemas
61
61
  "schemaType": "zod", // or "typescript" for TypeScript types
62
62
  "outputFile": "openapi.json",
63
+ "outputDir": "./public",
63
64
  "docsUrl": "/api-docs",
64
65
  "includeOpenApiRoutes": false,
65
66
  "debug": false
@@ -68,18 +69,19 @@ During initialization (`npx next-openapi-gen init`), a configuration file `next.
68
69
 
69
70
  ### Configuration Options
70
71
 
71
- | Option | Description |
72
- | ---------------------- | ------------------------------------------------ |
73
- | `apiDir` | Path to the API directory |
74
- | `schemaDir` | Path to the types/schemas directory |
75
- | `schemaType` | Schema type: `"zod"` or `"typescript"` |
76
- | `outputFile` | Path to the OpenAPI output file |
77
- | `docsUrl` | API documentation URL (for Swagger UI) |
78
- | `includeOpenApiRoutes` | Whether to include only routes with @openapi tag |
79
- | `defaultResponseSet` | Default error response set for all endpoints |
80
- | `responseSets` | Named sets of error response codes |
81
- | `errorConfig` | Error schema configuration |
82
- | `debug` | Enable detailed logging during generation |
72
+ | Option | Description |
73
+ | ---------------------- | ---------------------------------------------------------------------- |
74
+ | `apiDir` | Path to the API directory |
75
+ | `schemaDir` | Path to the types/schemas directory |
76
+ | `schemaType` | Schema type: `"zod"` or `"typescript"` |
77
+ | `outputFile` | Name of the OpenAPI output file |
78
+ | `outputDir` | Directory where OpenAPI file will be generated (default: `"./public"`) |
79
+ | `docsUrl` | API documentation URL (for Swagger UI) |
80
+ | `includeOpenApiRoutes` | Whether to include only routes with @openapi tag |
81
+ | `defaultResponseSet` | Default error response set for all endpoints |
82
+ | `responseSets` | Named sets of error response codes |
83
+ | `errorConfig` | Error schema configuration |
84
+ | `debug` | Enable detailed logging during generation |
83
85
 
84
86
  ## Documenting Your API
85
87
 
@@ -192,7 +194,7 @@ This command will generate OpenAPI documentation based on your API code:
192
194
 
193
195
  - Scan API directories for routes
194
196
  - Analyze types/schemas
195
- - Generate OpenAPI file (`openapi.json`) in `public` folder
197
+ - Generate OpenAPI file (`openapi.json`) in specified output directory (default: `public` folder)
196
198
  - Create Scalar/Swagger UI endpoint and page (if enabled)
197
199
 
198
200
  ### 3. View API Documentation
@@ -10,8 +10,8 @@ export async function generate() {
10
10
  // Create api dir if not exists
11
11
  const apiDir = path.resolve(config.apiDir);
12
12
  await fse.ensureDir(apiDir);
13
- // Create public dir if not exists
14
- const outputDir = path.resolve("./public");
13
+ // Use user-defined output directory
14
+ const outputDir = path.resolve(config.outputDir);
15
15
  await fse.ensureDir(outputDir);
16
16
  const apiDocs = generator.generate();
17
17
  // Write api docs
@@ -17,13 +17,14 @@ export class OpenApiGenerator {
17
17
  }
18
18
  getConfig() {
19
19
  // @ts-ignore
20
- const { apiDir, schemaDir, docsUrl, ui, outputFile, includeOpenApiRoutes, schemaType = "typescript", defaultResponseSet, responseSets, errorConfig, debug } = this.template;
20
+ const { apiDir, schemaDir, docsUrl, ui, outputFile, outputDir, includeOpenApiRoutes, schemaType = "typescript", defaultResponseSet, responseSets, errorConfig, debug } = this.template;
21
21
  return {
22
22
  apiDir,
23
23
  schemaDir,
24
24
  docsUrl,
25
25
  ui,
26
26
  outputFile,
27
+ outputDir,
27
28
  includeOpenApiRoutes,
28
29
  schemaType,
29
30
  defaultResponseSet,
@@ -265,6 +265,8 @@ export class RouteProcessor {
265
265
  relativePath = relativePath.replace(/\/route\.tsx?$/, "");
266
266
  // Convert directory separators to URL path format
267
267
  relativePath = relativePath.replaceAll("\\", "/");
268
+ // Remove Next.js route groups (folders in parentheses like (authenticated), (marketing))
269
+ relativePath = relativePath.replace(/\/\([^)]+\)/g, "");
268
270
  // Convert Next.js dynamic route syntax to OpenAPI parameter syntax
269
271
  relativePath = relativePath.replace(/\/\[([^\]]+)\]/g, "/{$1}");
270
272
  // Handle catch-all routes ([...param])
@@ -277,6 +279,7 @@ export class RouteProcessor {
277
279
  .replace(/route\.tsx?$/, "")
278
280
  .replaceAll("\\", "/")
279
281
  .replace(/\/$/, "")
282
+ .replace(/\/\([^)]+\)/g, "") // Remove route groups for pages router too
280
283
  .replace(/\/\[([^\]]+)\]/g, "/{$1}") // Replace [param] with {param}
281
284
  .replace(/\/\[\.\.\.(.*)\]/g, "/{$1}"); // Replace [...param] with {param}
282
285
  }
@@ -91,6 +91,7 @@ export default {
91
91
  docsUrl: "api-docs",
92
92
  ui: "scalar",
93
93
  outputFile: "openapi.json",
94
+ outputDir: "./public",
94
95
  includeOpenApiRoutes: false,
95
96
  debug: false,
96
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,15 +42,15 @@
42
42
  "node": ">=18.0.0"
43
43
  },
44
44
  "dependencies": {
45
- "@babel/parser": "^7.25.7",
46
- "@babel/traverse": "^7.25.7",
47
- "@babel/types": "^7.25.7",
48
- "commander": "^12.1.0",
49
- "fs-extra": "^10.0.0",
50
- "ora": "^8.1.0"
45
+ "@babel/parser": "^7.28.3",
46
+ "@babel/traverse": "^7.28.3",
47
+ "@babel/types": "^7.28.2",
48
+ "commander": "^14.0.0",
49
+ "fs-extra": "^11.3.1",
50
+ "ora": "^8.2.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@types/node": "^22.7.4",
54
- "typescript": "^4.5.4"
53
+ "@types/node": "^24.3.0",
54
+ "typescript": "^5.9.2"
55
55
  }
56
56
  }