@dotflash/openapi-semantic-generator 0.1.2 → 0.1.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.
- package/dist/{chunk-PLFFT6WD.js → chunk-4WJ3XNRD.js} +20 -5
- package/dist/cli.cjs +20 -5
- package/dist/cli.js +1 -1
- package/dist/index.cjs +20 -5
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -37,7 +37,9 @@ async function extractMetadata(specPath) {
|
|
|
37
37
|
if (typedDetails.requestBody) {
|
|
38
38
|
}
|
|
39
39
|
operations.push({
|
|
40
|
-
operationId:
|
|
40
|
+
operationId: toCamelCase(
|
|
41
|
+
typedDetails.operationId || `${method}_${path4.replace(/\//g, "_")}`
|
|
42
|
+
),
|
|
41
43
|
summary: typedDetails.summary,
|
|
42
44
|
description: typedDetails.description,
|
|
43
45
|
httpMethod: method.toUpperCase(),
|
|
@@ -65,6 +67,10 @@ async function extractMetadata(specPath) {
|
|
|
65
67
|
}))
|
|
66
68
|
};
|
|
67
69
|
}
|
|
70
|
+
function toCamelCase(str) {
|
|
71
|
+
const camel = str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "");
|
|
72
|
+
return camel.charAt(0).toLowerCase() + camel.slice(1);
|
|
73
|
+
}
|
|
68
74
|
function cleanDescription(desc) {
|
|
69
75
|
if (!desc) return "";
|
|
70
76
|
return desc.split("\n").filter((line) => {
|
|
@@ -84,10 +90,13 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
84
90
|
if (!await fs2.pathExists(fullDir)) continue;
|
|
85
91
|
const files = await fs2.readdir(fullDir);
|
|
86
92
|
for (const file of files) {
|
|
87
|
-
|
|
93
|
+
const lowerFile = file.toLowerCase();
|
|
94
|
+
const isCodeFile = file.endsWith(".ts") || file.endsWith(".js");
|
|
95
|
+
const isTestFile = lowerFile.endsWith(".test.ts") || lowerFile.endsWith(".spec.ts");
|
|
96
|
+
const isIndexFile = lowerFile === "index.ts" || lowerFile === "index.js";
|
|
97
|
+
if (isCodeFile && !isTestFile && !isIndexFile) {
|
|
88
98
|
apis.push({
|
|
89
|
-
className: file.replace(
|
|
90
|
-
// Simplified
|
|
99
|
+
className: file.replace(/\.[jt]s$/, ""),
|
|
91
100
|
sourceFile: path.join(dirName, file)
|
|
92
101
|
});
|
|
93
102
|
}
|
|
@@ -96,12 +105,18 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
96
105
|
if (metadata.operations) {
|
|
97
106
|
for (const op of metadata.operations) {
|
|
98
107
|
if (apis.length === 0) continue;
|
|
108
|
+
if (apis.length === 1) {
|
|
109
|
+
op.className = apis[0].className;
|
|
110
|
+
op.sourceFile = apis[0].sourceFile;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
99
113
|
let matchedApi = apis[0];
|
|
100
114
|
if (op.tags && op.tags.length > 0) {
|
|
101
115
|
const primaryTag = op.tags[0].toLowerCase();
|
|
116
|
+
const normalizedTag = primaryTag.replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
102
117
|
const found = apis.find((api) => {
|
|
103
118
|
const fileName = api.className.toLowerCase();
|
|
104
|
-
return fileName.includes(primaryTag);
|
|
119
|
+
return fileName.includes(normalizedTag) || fileName.includes(primaryTag.replace(/\s+/g, ""));
|
|
105
120
|
});
|
|
106
121
|
if (found) {
|
|
107
122
|
matchedApi = found;
|
package/dist/cli.cjs
CHANGED
|
@@ -75,7 +75,9 @@ async function extractMetadata(specPath) {
|
|
|
75
75
|
if (typedDetails.requestBody) {
|
|
76
76
|
}
|
|
77
77
|
operations.push({
|
|
78
|
-
operationId:
|
|
78
|
+
operationId: toCamelCase(
|
|
79
|
+
typedDetails.operationId || `${method}_${path5.replace(/\//g, "_")}`
|
|
80
|
+
),
|
|
79
81
|
summary: typedDetails.summary,
|
|
80
82
|
description: typedDetails.description,
|
|
81
83
|
httpMethod: method.toUpperCase(),
|
|
@@ -103,6 +105,10 @@ async function extractMetadata(specPath) {
|
|
|
103
105
|
}))
|
|
104
106
|
};
|
|
105
107
|
}
|
|
108
|
+
function toCamelCase(str) {
|
|
109
|
+
const camel = str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "");
|
|
110
|
+
return camel.charAt(0).toLowerCase() + camel.slice(1);
|
|
111
|
+
}
|
|
106
112
|
function cleanDescription(desc) {
|
|
107
113
|
if (!desc) return "";
|
|
108
114
|
return desc.split("\n").filter((line) => {
|
|
@@ -122,10 +128,13 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
122
128
|
if (!await import_fs_extra2.default.pathExists(fullDir)) continue;
|
|
123
129
|
const files = await import_fs_extra2.default.readdir(fullDir);
|
|
124
130
|
for (const file of files) {
|
|
125
|
-
|
|
131
|
+
const lowerFile = file.toLowerCase();
|
|
132
|
+
const isCodeFile = file.endsWith(".ts") || file.endsWith(".js");
|
|
133
|
+
const isTestFile = lowerFile.endsWith(".test.ts") || lowerFile.endsWith(".spec.ts");
|
|
134
|
+
const isIndexFile = lowerFile === "index.ts" || lowerFile === "index.js";
|
|
135
|
+
if (isCodeFile && !isTestFile && !isIndexFile) {
|
|
126
136
|
apis.push({
|
|
127
|
-
className: file.replace(
|
|
128
|
-
// Simplified
|
|
137
|
+
className: file.replace(/\.[jt]s$/, ""),
|
|
129
138
|
sourceFile: import_path.default.join(dirName, file)
|
|
130
139
|
});
|
|
131
140
|
}
|
|
@@ -134,12 +143,18 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
134
143
|
if (metadata.operations) {
|
|
135
144
|
for (const op of metadata.operations) {
|
|
136
145
|
if (apis.length === 0) continue;
|
|
146
|
+
if (apis.length === 1) {
|
|
147
|
+
op.className = apis[0].className;
|
|
148
|
+
op.sourceFile = apis[0].sourceFile;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
137
151
|
let matchedApi = apis[0];
|
|
138
152
|
if (op.tags && op.tags.length > 0) {
|
|
139
153
|
const primaryTag = op.tags[0].toLowerCase();
|
|
154
|
+
const normalizedTag = primaryTag.replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
140
155
|
const found = apis.find((api) => {
|
|
141
156
|
const fileName = api.className.toLowerCase();
|
|
142
|
-
return fileName.includes(primaryTag);
|
|
157
|
+
return fileName.includes(normalizedTag) || fileName.includes(primaryTag.replace(/\s+/g, ""));
|
|
143
158
|
});
|
|
144
159
|
if (found) {
|
|
145
160
|
matchedApi = found;
|
package/dist/cli.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -84,7 +84,9 @@ async function extractMetadata(specPath) {
|
|
|
84
84
|
if (typedDetails.requestBody) {
|
|
85
85
|
}
|
|
86
86
|
operations.push({
|
|
87
|
-
operationId:
|
|
87
|
+
operationId: toCamelCase(
|
|
88
|
+
typedDetails.operationId || `${method}_${path4.replace(/\//g, "_")}`
|
|
89
|
+
),
|
|
88
90
|
summary: typedDetails.summary,
|
|
89
91
|
description: typedDetails.description,
|
|
90
92
|
httpMethod: method.toUpperCase(),
|
|
@@ -112,6 +114,10 @@ async function extractMetadata(specPath) {
|
|
|
112
114
|
}))
|
|
113
115
|
};
|
|
114
116
|
}
|
|
117
|
+
function toCamelCase(str) {
|
|
118
|
+
const camel = str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "");
|
|
119
|
+
return camel.charAt(0).toLowerCase() + camel.slice(1);
|
|
120
|
+
}
|
|
115
121
|
function cleanDescription(desc) {
|
|
116
122
|
if (!desc) return "";
|
|
117
123
|
return desc.split("\n").filter((line) => {
|
|
@@ -131,10 +137,13 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
131
137
|
if (!await import_fs_extra2.default.pathExists(fullDir)) continue;
|
|
132
138
|
const files = await import_fs_extra2.default.readdir(fullDir);
|
|
133
139
|
for (const file of files) {
|
|
134
|
-
|
|
140
|
+
const lowerFile = file.toLowerCase();
|
|
141
|
+
const isCodeFile = file.endsWith(".ts") || file.endsWith(".js");
|
|
142
|
+
const isTestFile = lowerFile.endsWith(".test.ts") || lowerFile.endsWith(".spec.ts");
|
|
143
|
+
const isIndexFile = lowerFile === "index.ts" || lowerFile === "index.js";
|
|
144
|
+
if (isCodeFile && !isTestFile && !isIndexFile) {
|
|
135
145
|
apis.push({
|
|
136
|
-
className: file.replace(
|
|
137
|
-
// Simplified
|
|
146
|
+
className: file.replace(/\.[jt]s$/, ""),
|
|
138
147
|
sourceFile: import_path.default.join(dirName, file)
|
|
139
148
|
});
|
|
140
149
|
}
|
|
@@ -143,12 +152,18 @@ async function scanGeneratedFiles(outputDir, metadata, options = {}) {
|
|
|
143
152
|
if (metadata.operations) {
|
|
144
153
|
for (const op of metadata.operations) {
|
|
145
154
|
if (apis.length === 0) continue;
|
|
155
|
+
if (apis.length === 1) {
|
|
156
|
+
op.className = apis[0].className;
|
|
157
|
+
op.sourceFile = apis[0].sourceFile;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
146
160
|
let matchedApi = apis[0];
|
|
147
161
|
if (op.tags && op.tags.length > 0) {
|
|
148
162
|
const primaryTag = op.tags[0].toLowerCase();
|
|
163
|
+
const normalizedTag = primaryTag.replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
149
164
|
const found = apis.find((api) => {
|
|
150
165
|
const fileName = api.className.toLowerCase();
|
|
151
|
-
return fileName.includes(primaryTag);
|
|
166
|
+
return fileName.includes(normalizedTag) || fileName.includes(primaryTag.replace(/\s+/g, ""));
|
|
152
167
|
});
|
|
153
168
|
if (found) {
|
|
154
169
|
matchedApi = found;
|
package/dist/index.js
CHANGED