next-openapi-gen 0.1.2 → 0.2.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/README.md +18 -14
- package/dist/commands/generate.js +21 -21
- package/dist/commands/init.js +111 -104
- package/dist/components/rapidoc.js +4 -4
- package/dist/components/redoc.js +4 -4
- package/dist/components/scalar.js +20 -0
- package/dist/components/stoplight.js +4 -4
- package/dist/components/swagger.js +8 -8
- package/dist/index.js +22 -22
- package/dist/lib/openapi-generator.js +34 -34
- package/dist/lib/route-processor.js +173 -145
- package/dist/lib/schema-processor.js +295 -250
- package/dist/lib/utils.js +88 -83
- package/dist/openapi-template.js +29 -29
- package/dist/types.js +1 -1
- package/package.json +2 -1
package/dist/lib/utils.js
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
1
|
-
export function capitalize(string) {
|
|
2
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
3
|
-
}
|
|
4
|
-
export function extractJSDocComments(path) {
|
|
5
|
-
const comments = path.node.leadingComments;
|
|
6
|
-
let summary = "";
|
|
7
|
-
let description = "";
|
|
8
|
-
let paramsType = "";
|
|
9
|
-
let
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
export function capitalize(string) {
|
|
2
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
3
|
+
}
|
|
4
|
+
export function extractJSDocComments(path) {
|
|
5
|
+
const comments = path.node.leadingComments;
|
|
6
|
+
let summary = "";
|
|
7
|
+
let description = "";
|
|
8
|
+
let paramsType = "";
|
|
9
|
+
let pathParamsType = "";
|
|
10
|
+
let bodyType = "";
|
|
11
|
+
let responseType = "";
|
|
12
|
+
let auth = "";
|
|
13
|
+
let isOpenApi = false;
|
|
14
|
+
if (comments) {
|
|
15
|
+
comments.forEach((comment) => {
|
|
16
|
+
const commentValue = cleanComment(comment.value);
|
|
17
|
+
isOpenApi = commentValue.includes("@openapi");
|
|
18
|
+
if (!summary) {
|
|
19
|
+
const summaryIndex = isOpenApi ? 1 : 0;
|
|
20
|
+
summary = commentValue.split("\n")[summaryIndex];
|
|
21
|
+
}
|
|
22
|
+
if (commentValue.includes("@auth")) {
|
|
23
|
+
const regex = /@auth:\s*(.*)/;
|
|
24
|
+
const value = commentValue.match(regex)[1].trim();
|
|
25
|
+
switch (value) {
|
|
26
|
+
case "bearer":
|
|
27
|
+
auth = "BearerAuth";
|
|
28
|
+
break;
|
|
29
|
+
case "basic":
|
|
30
|
+
auth = "BasicAuth";
|
|
31
|
+
break;
|
|
32
|
+
case "apikey":
|
|
33
|
+
auth = "ApiKeyAuth";
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (commentValue.includes("@desc")) {
|
|
38
|
+
const regex = /@desc:\s*(.*)/;
|
|
39
|
+
description = commentValue.match(regex)[1].trim();
|
|
40
|
+
}
|
|
41
|
+
if (commentValue.includes("@params")) {
|
|
42
|
+
paramsType = extractTypeFromComment(commentValue, "@params");
|
|
43
|
+
}
|
|
44
|
+
if (commentValue.includes("@pathParams")) {
|
|
45
|
+
pathParamsType = extractTypeFromComment(commentValue, "@pathParams");
|
|
46
|
+
}
|
|
47
|
+
if (commentValue.includes("@body")) {
|
|
48
|
+
bodyType = extractTypeFromComment(commentValue, "@body");
|
|
49
|
+
}
|
|
50
|
+
if (commentValue.includes("@response")) {
|
|
51
|
+
responseType = extractTypeFromComment(commentValue, "@response");
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
auth,
|
|
57
|
+
summary,
|
|
58
|
+
description,
|
|
59
|
+
paramsType,
|
|
60
|
+
pathParamsType,
|
|
61
|
+
bodyType,
|
|
62
|
+
responseType,
|
|
63
|
+
isOpenApi,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function extractTypeFromComment(commentValue, tag) {
|
|
67
|
+
return commentValue.match(new RegExp(`${tag}\\s*:\\s*(\\w+)`))?.[1] || "";
|
|
68
|
+
}
|
|
69
|
+
export function cleanComment(commentValue) {
|
|
70
|
+
return commentValue.replace(/\*\s*/g, "").trim();
|
|
71
|
+
}
|
|
72
|
+
export function cleanSpec(spec) {
|
|
73
|
+
const propsToRemove = [
|
|
74
|
+
"apiDir",
|
|
75
|
+
"schemaDir",
|
|
76
|
+
"docsUrl",
|
|
77
|
+
"ui",
|
|
78
|
+
"outputFile",
|
|
79
|
+
"includeOpenApiRoutes",
|
|
80
|
+
];
|
|
81
|
+
const newSpec = { ...spec };
|
|
82
|
+
propsToRemove.forEach((key) => delete newSpec[key]);
|
|
83
|
+
return newSpec;
|
|
84
|
+
}
|
|
85
|
+
export function getOperationId(routePath, method) {
|
|
86
|
+
const operation = routePath.replaceAll(/\//g, "-").replace(/^-/, "");
|
|
87
|
+
return `${method}-${operation}`;
|
|
88
|
+
}
|
package/dist/openapi-template.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
openapi: "3.0.0",
|
|
3
|
-
info: {
|
|
4
|
-
title: "API Documentation",
|
|
5
|
-
version: "1.0.0",
|
|
6
|
-
description: "This is the OpenAPI specification for your project.",
|
|
7
|
-
},
|
|
8
|
-
servers: [
|
|
9
|
-
{
|
|
10
|
-
url: "http://localhost:3000/api",
|
|
11
|
-
description: "Local development server",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
components: {
|
|
15
|
-
securitySchemes: {
|
|
16
|
-
BearerAuth: {
|
|
17
|
-
type: "http",
|
|
18
|
-
scheme: "bearer",
|
|
19
|
-
bearerFormat: "JWT",
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
apiDir: "./src/app/api",
|
|
24
|
-
schemaDir: "./src",
|
|
25
|
-
docsUrl: "api-docs",
|
|
26
|
-
ui: "
|
|
27
|
-
outputFile: "
|
|
28
|
-
includeOpenApiRoutes: false,
|
|
29
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
openapi: "3.0.0",
|
|
3
|
+
info: {
|
|
4
|
+
title: "API Documentation",
|
|
5
|
+
version: "1.0.0",
|
|
6
|
+
description: "This is the OpenAPI specification for your project.",
|
|
7
|
+
},
|
|
8
|
+
servers: [
|
|
9
|
+
{
|
|
10
|
+
url: "http://localhost:3000/api",
|
|
11
|
+
description: "Local development server",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
components: {
|
|
15
|
+
securitySchemes: {
|
|
16
|
+
BearerAuth: {
|
|
17
|
+
type: "http",
|
|
18
|
+
scheme: "bearer",
|
|
19
|
+
bearerFormat: "JWT",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
apiDir: "./src/app/api",
|
|
24
|
+
schemaDir: "./src",
|
|
25
|
+
docsUrl: "api-docs",
|
|
26
|
+
ui: "scalar",
|
|
27
|
+
outputFile: "openapi.json",
|
|
28
|
+
includeOpenApiRoutes: false,
|
|
29
|
+
};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-openapi-gen",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Super fast and easy way to generate OpenAPI documentation automatically from API routes in NextJS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"react",
|
|
25
25
|
"nextjs",
|
|
26
26
|
"openapi",
|
|
27
|
+
"scalar",
|
|
27
28
|
"swagger",
|
|
28
29
|
"docs",
|
|
29
30
|
"api",
|