next-openapi-gen 0.10.5 → 1.0.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.
Files changed (44) hide show
  1. package/README.md +407 -1047
  2. package/dist/cli.d.ts +4 -0
  3. package/dist/cli.js +8599 -0
  4. package/dist/index.d.ts +18 -0
  5. package/dist/index.js +8645 -26
  6. package/dist/next/index.d.ts +1 -0
  7. package/dist/next/index.js +7965 -0
  8. package/dist/react-router/index.d.ts +1 -0
  9. package/dist/react-router/index.js +7134 -0
  10. package/dist/vite/index.d.ts +1 -0
  11. package/dist/vite/index.js +7134 -0
  12. package/package.json +103 -79
  13. package/{dist/components/rapidoc.js → templates/init/ui/nextjs/rapidoc.tsx} +16 -20
  14. package/templates/init/ui/nextjs/redoc.tsx +11 -0
  15. package/{dist/components/scalar.js → templates/init/ui/nextjs/scalar.tsx} +15 -21
  16. package/{dist/components/stoplight.js → templates/init/ui/nextjs/stoplight.tsx} +11 -17
  17. package/templates/init/ui/nextjs/swagger.tsx +17 -0
  18. package/templates/init/ui/reactrouter/rapidoc.tsx +15 -0
  19. package/templates/init/ui/reactrouter/redoc.tsx +9 -0
  20. package/templates/init/ui/reactrouter/scalar.tsx +14 -0
  21. package/templates/init/ui/reactrouter/stoplight.tsx +10 -0
  22. package/templates/init/ui/reactrouter/swagger.tsx +11 -0
  23. package/templates/init/ui/tanstack/rapidoc.tsx +21 -0
  24. package/templates/init/ui/tanstack/redoc.tsx +14 -0
  25. package/templates/init/ui/tanstack/scalar.tsx +19 -0
  26. package/templates/init/ui/tanstack/stoplight.tsx +15 -0
  27. package/templates/init/ui/tanstack/swagger.tsx +16 -0
  28. package/templates/init/ui/template-types.d.ts +9 -0
  29. package/dist/commands/generate.js +0 -24
  30. package/dist/commands/init.js +0 -194
  31. package/dist/components/redoc.js +0 -17
  32. package/dist/components/swagger.js +0 -21
  33. package/dist/lib/app-router-strategy.js +0 -66
  34. package/dist/lib/drizzle-zod-processor.js +0 -329
  35. package/dist/lib/logger.js +0 -39
  36. package/dist/lib/openapi-generator.js +0 -171
  37. package/dist/lib/pages-router-strategy.js +0 -198
  38. package/dist/lib/route-processor.js +0 -349
  39. package/dist/lib/router-strategy.js +0 -1
  40. package/dist/lib/schema-processor.js +0 -1612
  41. package/dist/lib/utils.js +0 -283
  42. package/dist/lib/zod-converter.js +0 -2133
  43. package/dist/openapi-template.js +0 -99
  44. package/dist/types.js +0 -1
package/package.json CHANGED
@@ -1,79 +1,103 @@
1
- {
2
- "name": "next-openapi-gen",
3
- "version": "0.10.5",
4
- "description": "Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/index.mjs",
8
- "typings": "dist/index.d.ts",
9
- "bin": {
10
- "next-openapi-gen": "./dist/index.js"
11
- },
12
- "files": [
13
- "dist"
14
- ],
15
- "scripts": {
16
- "clean": "rm -rf dist",
17
- "build": "npm run clean && tsc",
18
- "prepare": "npm run build",
19
- "test": "vitest run",
20
- "test:watch": "vitest",
21
- "test:ui": "vitest --ui",
22
- "test:coverage": "vitest run --coverage",
23
- "release": "np --no-cleanup --no-tests",
24
- "version": "conventional-changelog -p angular -i CHANGELOG.md -s -n .changelogrc.cjs && git add CHANGELOG.md"
25
- },
26
- "repository": {
27
- "type": "git",
28
- "url": "git+ssh://git@github.com/tazo90/next-openapi-gen.git"
29
- },
30
- "keywords": [
31
- "nextjs",
32
- "openapi",
33
- "swagger",
34
- "typescript",
35
- "zod",
36
- "api-docs",
37
- "api",
38
- "docs",
39
- "react",
40
- "scalar",
41
- "redoc",
42
- "drizzle"
43
- ],
44
- "publishConfig": {
45
- "access": "public"
46
- },
47
- "author": "Mariusz Winnik",
48
- "license": "MIT",
49
- "engines": {
50
- "node": ">=18.0.0"
51
- },
52
- "dependencies": {
53
- "@babel/parser": "^7.28.3",
54
- "@babel/traverse": "^7.28.3",
55
- "@babel/types": "^7.28.2",
56
- "commander": "^14.0.0",
57
- "fs-extra": "^11.3.1",
58
- "js-yaml": "^4.1.0",
59
- "ora": "^8.2.0"
60
- },
61
- "devDependencies": {
62
- "@types/js-yaml": "^4.0.9",
63
- "@types/node": "^24.3.0",
64
- "@vitest/ui": "^3.2.4",
65
- "conventional-changelog-cli": "^5.0.0",
66
- "np": "^10.2.0",
67
- "typescript": "^5.9.2",
68
- "vitest": "^3.2.4"
69
- },
70
- "np": {
71
- "yarn": false,
72
- "anyBranch": false,
73
- "branch": "main",
74
- "cleanup": false,
75
- "tests": false,
76
- "2fa": false,
77
- "releaseDraft": false
78
- }
79
- }
1
+ {
2
+ "name": "next-openapi-gen",
3
+ "version": "1.0.1",
4
+ "description": "Automatically generate OpenAPI 3.0, 3.1, and 3.2 documentation from Next.js projects, with support for Zod schemas, TypeScript types, and reusable OpenAPI fragments.",
5
+ "keywords": [
6
+ "api",
7
+ "api-docs",
8
+ "docs",
9
+ "drizzle",
10
+ "nextjs",
11
+ "openapi",
12
+ "react",
13
+ "redoc",
14
+ "scalar",
15
+ "swagger",
16
+ "typescript",
17
+ "zod"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Mariusz Winnik",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+ssh://git@github.com/tazo90/next-openapi-gen.git"
24
+ },
25
+ "bin": {
26
+ "next-openapi-gen": "./dist/cli.js",
27
+ "openapi-gen": "./dist/cli.js"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "templates",
32
+ "README.md"
33
+ ],
34
+ "type": "module",
35
+ "main": "dist/index.js",
36
+ "module": "dist/index.js",
37
+ "typings": "dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/index.js"
42
+ },
43
+ "./next": {
44
+ "types": "./dist/next/index.d.ts",
45
+ "default": "./dist/next/index.js"
46
+ },
47
+ "./react-router": {
48
+ "types": "./dist/react-router/index.d.ts",
49
+ "default": "./dist/react-router/index.js"
50
+ },
51
+ "./vite": {
52
+ "types": "./dist/vite/index.d.ts",
53
+ "default": "./dist/vite/index.js"
54
+ },
55
+ "./package.json": "./package.json"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "dependencies": {
61
+ "@babel/parser": "^7.29.2",
62
+ "@babel/traverse": "^7.29.0",
63
+ "@babel/types": "^7.29.0",
64
+ "commander": "^14.0.3",
65
+ "fs-extra": "^11.3.4",
66
+ "js-yaml": "^4.1.1",
67
+ "ora": "^9.3.0",
68
+ "typescript": "^5.9.3"
69
+ },
70
+ "devDependencies": {
71
+ "@types/node": "^25.5.0",
72
+ "conventional-changelog-cli": "^5.0.0",
73
+ "np": "^11.0.2",
74
+ "oxfmt": "^0.42.0",
75
+ "oxlint": "^1.57.0",
76
+ "tsup": "^8.5.1"
77
+ },
78
+ "engines": {
79
+ "node": ">=24.0.0"
80
+ },
81
+ "np": {
82
+ "packageManager": "pnpm",
83
+ "anyBranch": false,
84
+ "branch": "main",
85
+ "cleanup": false,
86
+ "tests": false,
87
+ "2fa": false,
88
+ "releaseDraft": false
89
+ },
90
+ "scripts": {
91
+ "check": "pnpm format:check && pnpm lint",
92
+ "clean": "rm -rf dist coverage templates tsconfig.tsbuildinfo",
93
+ "build": "pnpm clean && tsup --config tsup.config.ts && cp -R ../openapi-init/templates ./templates",
94
+ "format": "oxfmt --config ../oxfmt-config/oxfmt.json --ignore-path ../../.gitignore .",
95
+ "format:check": "oxfmt --config ../oxfmt-config/oxfmt.json --ignore-path ../../.gitignore --check .",
96
+ "lint": "oxlint --config ../oxlint-config/base.json . --ignore-path ../../.gitignore --deny-warnings",
97
+ "lint:fix": "oxlint --config ../oxlint-config/base.json . --ignore-path ../../.gitignore --fix --deny-warnings",
98
+ "test": "pnpm --dir ../.. test:unit && pnpm --dir ../.. test:integration",
99
+ "test:coverage": "pnpm --dir ../.. test:coverage:next-openapi-gen",
100
+ "release": "np --no-cleanup --no-tests --no-publish",
101
+ "version": "conventional-changelog -p angular -i ../../CHANGELOG.md -s -n ../../.changelogrc.cjs && git add ../../CHANGELOG.md"
102
+ }
103
+ }
@@ -1,21 +1,17 @@
1
- export const rapidocDeps = ["rapidoc"];
2
- export const rapidocDevDeps = [];
3
- export function RapidocUI(outputFile) {
4
- return `
5
- "use client";
6
-
7
- import "rapidoc";
8
-
9
- export default function ApiDocsPage() {
10
- return (
11
- <section style={{ height: "100vh" }}>
12
- <rapi-doc
13
- spec-url="${outputFile}"
14
- render-style="read"
15
- style={{ height: "100vh", width: "100%" }}
16
- ></rapi-doc>
17
- </section>
18
- );
19
- }
20
- `;
1
+ "use client";
2
+
3
+ import "rapidoc";
4
+
5
+ const RapiDoc = "rapi-doc" as any;
6
+
7
+ export default function ApiDocsPage() {
8
+ return (
9
+ <section style={{ height: "100vh" }}>
10
+ <RapiDoc
11
+ spec-url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__"
12
+ render-style="read"
13
+ style={{ height: "100vh", width: "100%" }}
14
+ ></RapiDoc>
15
+ </section>
16
+ );
21
17
  }
@@ -0,0 +1,11 @@
1
+ "use client";
2
+
3
+ import { RedocStandalone } from "redoc";
4
+
5
+ export default function ApiDocsPage() {
6
+ return (
7
+ <section>
8
+ <RedocStandalone specUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
9
+ </section>
10
+ );
11
+ }
@@ -1,22 +1,16 @@
1
- export const scalarDeps = ["@scalar/api-reference-react", "ajv"];
2
- export const scalarDevDeps = [];
3
- export function ScalarUI(outputFile) {
4
- return `
5
- "use client";
6
-
7
- import { ApiReferenceReact } from "@scalar/api-reference-react";
8
-
9
- import "@scalar/api-reference-react/style.css";
10
-
11
- export default function ApiDocsPage() {
12
- return (
13
- <ApiReferenceReact
14
- configuration={{
15
- _integration: "nextjs",
16
- url: "/${outputFile}",
17
- }}
18
- />
19
- );
20
- }
21
- `;
1
+ "use client";
2
+
3
+ import { ApiReferenceReact } from "@scalar/api-reference-react";
4
+
5
+ import "@scalar/api-reference-react/style.css";
6
+
7
+ export default function ApiDocsPage() {
8
+ return (
9
+ <ApiReferenceReact
10
+ configuration={{
11
+ _integration: "nextjs",
12
+ url: "/__NEXT_OPENAPI_GEN_OUTPUT_FILE__",
13
+ }}
14
+ />
15
+ );
22
16
  }
@@ -1,18 +1,12 @@
1
- export const stoplightDeps = ["@stoplight/elements"];
2
- export const stoplightDevDeps = [];
3
- export function StoplightUI(outputFile) {
4
- return `
5
- "use client";
6
-
7
- import { API } from "@stoplight/elements";
8
- import "@stoplight/elements/styles.min.css";
9
-
10
- export default function ApiDocsPage() {
11
- return (
12
- <section style={{ height: "100vh" }}>
13
- <API apiDescriptionUrl="${outputFile}" />
14
- </section>
15
- );
16
- }
17
- `;
1
+ "use client";
2
+
3
+ import { API } from "@stoplight/elements";
4
+ import "@stoplight/elements/styles.min.css";
5
+
6
+ export default function ApiDocsPage() {
7
+ return (
8
+ <section style={{ height: "100vh" }}>
9
+ <API apiDescriptionUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
10
+ </section>
11
+ );
18
12
  }
@@ -0,0 +1,17 @@
1
+ "use client";
2
+
3
+ import "swagger-ui-react/swagger-ui.css";
4
+
5
+ import dynamic from "next/dynamic";
6
+
7
+ const SwaggerUI = dynamic(() => import("swagger-ui-react"), {
8
+ loading: () => <p>Loading Component...</p>,
9
+ });
10
+
11
+ export default function ApiDocsPage() {
12
+ return (
13
+ <section>
14
+ <SwaggerUI url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
15
+ </section>
16
+ );
17
+ }
@@ -0,0 +1,15 @@
1
+ import "rapidoc";
2
+
3
+ const RapiDoc = "rapi-doc" as any;
4
+
5
+ export default function ApiDocsPage() {
6
+ return (
7
+ <section style={{ height: "100vh" }}>
8
+ <RapiDoc
9
+ spec-url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__"
10
+ render-style="read"
11
+ style={{ height: "100vh", width: "100%" }}
12
+ ></RapiDoc>
13
+ </section>
14
+ );
15
+ }
@@ -0,0 +1,9 @@
1
+ import { RedocStandalone } from "redoc";
2
+
3
+ export default function ApiDocsPage() {
4
+ return (
5
+ <section>
6
+ <RedocStandalone specUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
7
+ </section>
8
+ );
9
+ }
@@ -0,0 +1,14 @@
1
+ import { ApiReferenceReact } from "@scalar/api-reference-react";
2
+
3
+ import "@scalar/api-reference-react/style.css";
4
+
5
+ export default function ApiDocsPage() {
6
+ return (
7
+ <ApiReferenceReact
8
+ configuration={{
9
+ _integration: "react",
10
+ url: "/__NEXT_OPENAPI_GEN_OUTPUT_FILE__",
11
+ }}
12
+ />
13
+ );
14
+ }
@@ -0,0 +1,10 @@
1
+ import { API } from "@stoplight/elements";
2
+ import "@stoplight/elements/styles.min.css";
3
+
4
+ export default function ApiDocsPage() {
5
+ return (
6
+ <section style={{ height: "100vh" }}>
7
+ <API apiDescriptionUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
8
+ </section>
9
+ );
10
+ }
@@ -0,0 +1,11 @@
1
+ import "swagger-ui-react/swagger-ui.css";
2
+
3
+ import SwaggerUI from "swagger-ui-react";
4
+
5
+ export default function ApiDocsPage() {
6
+ return (
7
+ <section>
8
+ <SwaggerUI url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
9
+ </section>
10
+ );
11
+ }
@@ -0,0 +1,21 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+
3
+ import "rapidoc";
4
+
5
+ const RapiDoc = "rapi-doc" as any;
6
+
7
+ export const Route = createFileRoute("__NEXT_OPENAPI_GEN_ROUTE_PATH__")({
8
+ component: ApiDocsPage,
9
+ });
10
+
11
+ function ApiDocsPage() {
12
+ return (
13
+ <section style={{ height: "100vh" }}>
14
+ <RapiDoc
15
+ spec-url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__"
16
+ render-style="read"
17
+ style={{ height: "100vh", width: "100%" }}
18
+ ></RapiDoc>
19
+ </section>
20
+ );
21
+ }
@@ -0,0 +1,14 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { RedocStandalone } from "redoc";
3
+
4
+ export const Route = createFileRoute("__NEXT_OPENAPI_GEN_ROUTE_PATH__")({
5
+ component: ApiDocsPage,
6
+ });
7
+
8
+ function ApiDocsPage() {
9
+ return (
10
+ <section>
11
+ <RedocStandalone specUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
12
+ </section>
13
+ );
14
+ }
@@ -0,0 +1,19 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { ApiReferenceReact } from "@scalar/api-reference-react";
3
+
4
+ import "@scalar/api-reference-react/style.css";
5
+
6
+ export const Route = createFileRoute("__NEXT_OPENAPI_GEN_ROUTE_PATH__")({
7
+ component: ApiDocsPage,
8
+ });
9
+
10
+ function ApiDocsPage() {
11
+ return (
12
+ <ApiReferenceReact
13
+ configuration={{
14
+ _integration: "react",
15
+ url: "/__NEXT_OPENAPI_GEN_OUTPUT_FILE__",
16
+ }}
17
+ />
18
+ );
19
+ }
@@ -0,0 +1,15 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { API } from "@stoplight/elements";
3
+ import "@stoplight/elements/styles.min.css";
4
+
5
+ export const Route = createFileRoute("__NEXT_OPENAPI_GEN_ROUTE_PATH__")({
6
+ component: ApiDocsPage,
7
+ });
8
+
9
+ function ApiDocsPage() {
10
+ return (
11
+ <section style={{ height: "100vh" }}>
12
+ <API apiDescriptionUrl="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
13
+ </section>
14
+ );
15
+ }
@@ -0,0 +1,16 @@
1
+ import "swagger-ui-react/swagger-ui.css";
2
+
3
+ import { createFileRoute } from "@tanstack/react-router";
4
+ import SwaggerUI from "swagger-ui-react";
5
+
6
+ export const Route = createFileRoute("__NEXT_OPENAPI_GEN_ROUTE_PATH__")({
7
+ component: ApiDocsPage,
8
+ });
9
+
10
+ function ApiDocsPage() {
11
+ return (
12
+ <section>
13
+ <SwaggerUI url="/__NEXT_OPENAPI_GEN_OUTPUT_FILE__" />
14
+ </section>
15
+ );
16
+ }
@@ -0,0 +1,9 @@
1
+ declare const React: unknown;
2
+
3
+ declare module "@scalar/api-reference-react" {
4
+ export const ApiReferenceReact: (props: any) => any;
5
+ }
6
+
7
+ declare module "redoc" {
8
+ export const RedocStandalone: (props: any) => any;
9
+ }
@@ -1,24 +0,0 @@
1
- import fs from "fs";
2
- import fse from "fs-extra";
3
- import path from "path";
4
- import ora from "ora";
5
- import { OpenApiGenerator } from "../lib/openapi-generator.js";
6
- export async function generate(options) {
7
- const { template } = options;
8
- const spinner = ora("Generating OpenAPI specification...\n").start();
9
- const generator = new OpenApiGenerator({
10
- templatePath: template,
11
- });
12
- const config = generator.getConfig();
13
- // Create api dir if not exists
14
- const apiDir = path.resolve(config.apiDir);
15
- await fse.ensureDir(apiDir);
16
- // Use user-defined output directory
17
- const outputDir = path.resolve(config.outputDir);
18
- await fse.ensureDir(outputDir);
19
- const apiDocs = generator.generate();
20
- // Write api docs
21
- const outputFile = path.join(outputDir, config.outputFile);
22
- fs.writeFileSync(outputFile, JSON.stringify(apiDocs, null, 2));
23
- spinner.succeed(`OpenAPI specification generated at ${outputFile}`);
24
- }