@povio/openapi-codegen-cli 2.0.8-rc.32 → 2.0.8-rc.34
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from "fs";
|
|
1
|
+
import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
5
4
|
|
|
@@ -24,10 +23,11 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
|
|
|
24
23
|
}));
|
|
25
24
|
const openApiDoc = await getOpenApiDoc(config.input, profiler);
|
|
26
25
|
const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
|
|
27
|
-
if (config.clearOutput) profiler.runSync("files.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
|
|
27
|
+
removeStaleGeneratedFiles({
|
|
28
|
+
output: config.output,
|
|
29
|
+
filesData,
|
|
30
|
+
options: config
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
await profiler.runAsync("files.write", async () => {
|
package/dist/{generateCodeFromOpenAPIDoc-DkNqNy-S.mjs → generateCodeFromOpenAPIDoc-B--xr_dZ.mjs}
RENAMED
|
@@ -3076,6 +3076,51 @@ async function writeFile({ fileName, content }, options) {
|
|
|
3076
3076
|
async function writeGenerateFileData(filesData, options) {
|
|
3077
3077
|
for (const file of filesData) await writeFile(file, options);
|
|
3078
3078
|
}
|
|
3079
|
+
function removeStaleGeneratedFiles({ output, filesData, options }) {
|
|
3080
|
+
if (!fs.existsSync(output)) return;
|
|
3081
|
+
const expectedFiles = new Set(filesData.map((file) => path.resolve(file.fileName)));
|
|
3082
|
+
const generatedSuffixes = new Set(Object.values(options.configs).map((config) => config.outputFileNameSuffix));
|
|
3083
|
+
const staleFiles = [];
|
|
3084
|
+
const visit = (dirPath) => {
|
|
3085
|
+
for (const dirent of fs.readdirSync(dirPath, { withFileTypes: true })) {
|
|
3086
|
+
const entryPath = path.join(dirPath, dirent.name);
|
|
3087
|
+
if (dirent.isDirectory()) {
|
|
3088
|
+
visit(entryPath);
|
|
3089
|
+
continue;
|
|
3090
|
+
}
|
|
3091
|
+
if (isGeneratedFile(entryPath, output, generatedSuffixes) && !expectedFiles.has(path.resolve(entryPath))) staleFiles.push(entryPath);
|
|
3092
|
+
}
|
|
3093
|
+
};
|
|
3094
|
+
visit(output);
|
|
3095
|
+
staleFiles.forEach((filePath) => fs.rmSync(filePath, { force: true }));
|
|
3096
|
+
removeEmptyDirectories(output);
|
|
3097
|
+
}
|
|
3098
|
+
function isGeneratedFile(filePath, output, generatedSuffixes) {
|
|
3099
|
+
const relativePath = path.relative(output, filePath);
|
|
3100
|
+
if (relativePath === ".openapi-codegen-cache.json") return true;
|
|
3101
|
+
const normalizedRelativePath = relativePath.split(path.sep).join("/");
|
|
3102
|
+
if ([
|
|
3103
|
+
"app-rest-client.ts",
|
|
3104
|
+
"queryModules.ts",
|
|
3105
|
+
"acl/app.ability.ts"
|
|
3106
|
+
].includes(normalizedRelativePath)) return true;
|
|
3107
|
+
if (path.parse(filePath).ext !== ".ts") return false;
|
|
3108
|
+
const segments = relativePath.split(path.sep).filter(Boolean);
|
|
3109
|
+
if (segments.length < 2) return false;
|
|
3110
|
+
const moduleName = segments[0];
|
|
3111
|
+
const fileName = segments[segments.length - 1];
|
|
3112
|
+
if (!fileName.startsWith(`${moduleName}.`)) return false;
|
|
3113
|
+
const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
|
|
3114
|
+
return generatedSuffixes.has(suffix);
|
|
3115
|
+
}
|
|
3116
|
+
function removeEmptyDirectories(root) {
|
|
3117
|
+
if (!fs.existsSync(root)) return;
|
|
3118
|
+
const removeIfEmpty = (dirPath) => {
|
|
3119
|
+
for (const dirent of fs.readdirSync(dirPath, { withFileTypes: true })) if (dirent.isDirectory()) removeIfEmpty(path.join(dirPath, dirent.name));
|
|
3120
|
+
if (dirPath !== root && fs.readdirSync(dirPath).length === 0) fs.rmdirSync(dirPath);
|
|
3121
|
+
};
|
|
3122
|
+
removeIfEmpty(root);
|
|
3123
|
+
}
|
|
3079
3124
|
|
|
3080
3125
|
//#endregion
|
|
3081
3126
|
//#region src/generators/generate/generateAcl.ts
|
|
@@ -4087,6 +4132,12 @@ function renderEndpointParams(resolver, endpoint, options) {
|
|
|
4087
4132
|
function renderEndpointArgs(resolver, endpoint, options, replacements) {
|
|
4088
4133
|
return getEndpointParamMapping(resolver, endpoint, options).map((param) => replacements?.[param.name] ?? param.name).join(", ");
|
|
4089
4134
|
}
|
|
4135
|
+
function renderEndpointObjectArgs(resolver, endpoint, options, replacements) {
|
|
4136
|
+
return getEndpointParamMapping(resolver, endpoint, options).map((param) => {
|
|
4137
|
+
const replacement = replacements?.[param.name];
|
|
4138
|
+
return replacement && replacement !== param.name ? `${param.name}: ${replacement}` : param.name;
|
|
4139
|
+
}).join(", ");
|
|
4140
|
+
}
|
|
4090
4141
|
function renderEndpointParamDescription(endpointParam) {
|
|
4091
4142
|
const strs = [`${endpointParam.paramType} parameter`];
|
|
4092
4143
|
const description = endpointParam.parameterObject?.description || endpointParam.bodyObject?.description;
|
|
@@ -4292,7 +4343,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4292
4343
|
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4293
4344
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
4294
4345
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
4295
|
-
const resolvedEndpointArgs =
|
|
4346
|
+
const resolvedEndpointArgs = renderEndpointObjectArgs(resolver, endpoint, {}, workspaceParamReplacements);
|
|
4296
4347
|
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4297
4348
|
optionalPathParams: resolver.options.workspaceContext,
|
|
4298
4349
|
modelNamespaceTag: tag
|
|
@@ -4458,7 +4509,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4458
4509
|
modelNamespaceTag: tag
|
|
4459
4510
|
});
|
|
4460
4511
|
const endpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
4461
|
-
const resolvedEndpointArgsWithoutPage =
|
|
4512
|
+
const resolvedEndpointArgsWithoutPage = renderEndpointObjectArgs(resolver, endpoint, { excludePageParam: true }, workspaceParamReplacements);
|
|
4462
4513
|
const queryOptionsName = getInfiniteQueryOptionsName(endpoint);
|
|
4463
4514
|
const queryOptionsArgs = `${resolvedEndpointArgsWithoutPage ? `{ ${resolvedEndpointArgsWithoutPage} }` : ""}${hasAxiosRequestConfig ? `${resolvedEndpointArgsWithoutPage ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
4464
4515
|
const hasQueryFnOverride = hasAclCheck;
|
|
@@ -4624,4 +4675,4 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler) {
|
|
|
4624
4675
|
}
|
|
4625
4676
|
|
|
4626
4677
|
//#endregion
|
|
4627
|
-
export { VALIDATION_ERROR_TYPE_TITLE as S,
|
|
4678
|
+
export { VALIDATION_ERROR_TYPE_TITLE as C, Profiler as S, groupByType as _, getDataFromOpenAPIDoc as a, invalidVariableNameCharactersToCamel as b, isQuery as c, getTagFileName as d, getTagImportPath as f, GenerateType as g, getNamespaceName as h, writeGenerateFileData as i, getSchemaTsMetaType as l, DEFAULT_GENERATE_OPTIONS as m, getOutputFileName as n, deepMerge as o, getQueryName as p, removeStaleGeneratedFiles as r, isMutation as s, generateCodeFromOpenAPIDoc as t, getTsTypeBase as u, isMediaTypeAllowed as v, formatTag as x, isParamMediaTypeAllowed as y };
|
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-CTwFD7Th.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
@@ -39,7 +39,7 @@ function logBanner(message) {
|
|
|
39
39
|
* Fetch the version from package.json
|
|
40
40
|
*/
|
|
41
41
|
function getVersion() {
|
|
42
|
-
return "2.0.8-rc.
|
|
42
|
+
return "2.0.8-rc.34";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-B--xr_dZ.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-CTwFD7Th.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|
|
@@ -18,6 +18,7 @@ function openApiCodegen(config) {
|
|
|
18
18
|
profiler: new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1")
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
|
+
return queue;
|
|
21
22
|
};
|
|
22
23
|
const setupWatcher = (server) => {
|
|
23
24
|
if (!isLocalInput || !config.input) return;
|
|
@@ -32,10 +33,11 @@ function openApiCodegen(config) {
|
|
|
32
33
|
configResolved(config) {
|
|
33
34
|
resolvedViteConfig = config;
|
|
34
35
|
},
|
|
35
|
-
buildStart() {
|
|
36
|
-
enqueueGenerate();
|
|
36
|
+
async buildStart() {
|
|
37
|
+
await enqueueGenerate();
|
|
37
38
|
},
|
|
38
|
-
configureServer(server) {
|
|
39
|
+
async configureServer(server) {
|
|
40
|
+
await enqueueGenerate();
|
|
39
41
|
setupWatcher(server);
|
|
40
42
|
}
|
|
41
43
|
};
|