@povio/openapi-codegen-cli 2.0.8-rc.24 → 2.0.8-rc.25
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 +5 -0
- package/dist/{config-BHkVxL6S.d.mts → config-HbwoMgWr.d.mts} +1 -1
- package/dist/{generate.runner-DRRxZ7ZJ.mjs → generate.runner-C7QVcw6n.mjs} +5 -3
- package/dist/{generateCodeFromOpenAPIDoc-DYOqSvuQ.mjs → generateCodeFromOpenAPIDoc-C7btBlMx.mjs} +17 -5
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/{options-BNqkO_OS.d.mts → options-PQDrYdAn.d.mts} +2 -1
- package/dist/sh.mjs +3 -3
- package/dist/vite.d.mts +7 -4
- package/dist/vite.mjs +4 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -242,12 +242,17 @@ export default defineConfig({
|
|
|
242
242
|
output: "./src/data",
|
|
243
243
|
inlineEndpoints: true,
|
|
244
244
|
incremental: true,
|
|
245
|
+
formatGeneratedFile: async ({ fileName, content }) => {
|
|
246
|
+
void fileName;
|
|
247
|
+
return content;
|
|
248
|
+
},
|
|
245
249
|
}),
|
|
246
250
|
],
|
|
247
251
|
});
|
|
248
252
|
```
|
|
249
253
|
|
|
250
254
|
The plugin runs on both `vite serve` and `vite build`, and watches local OpenAPI files in dev mode.
|
|
255
|
+
If you provide `formatGeneratedFile`, the plugin formats each generated file in memory before comparing and writing it, which helps avoid unnecessary HMR when the formatted output is unchanged.
|
|
251
256
|
|
|
252
257
|
### Enums
|
|
253
258
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-C7btBlMx.mjs";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
@@ -17,7 +17,7 @@ function resolveConfig({ fileConfig = {}, params: { excludeTags, inlineEndpoints
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/generators/run/generate.runner.ts
|
|
19
19
|
const CACHE_FILE_NAME = ".openapi-codegen-cache.json";
|
|
20
|
-
async function runGenerate({ fileConfig, params, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
|
|
20
|
+
async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
|
|
21
21
|
const config = profiler.runSync("config.resolve", () => resolveConfig({
|
|
22
22
|
fileConfig,
|
|
23
23
|
params: params ?? {}
|
|
@@ -38,7 +38,9 @@ async function runGenerate({ fileConfig, params, profiler = new Profiler(process
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
|
|
41
|
-
profiler.
|
|
41
|
+
await profiler.runAsync("files.write", async () => {
|
|
42
|
+
await writeGenerateFileData(filesData, { formatGeneratedFile });
|
|
43
|
+
});
|
|
42
44
|
const stats = getGenerateStats(filesData, config);
|
|
43
45
|
if (config.incremental) writeCache(cacheFilePath, {
|
|
44
46
|
openApiHash,
|
package/dist/{generateCodeFromOpenAPIDoc-DYOqSvuQ.mjs → generateCodeFromOpenAPIDoc-C7btBlMx.mjs}
RENAMED
|
@@ -3044,19 +3044,31 @@ function getTagElement(tag, data) {
|
|
|
3044
3044
|
function getOutputFileName({ output, fileName }) {
|
|
3045
3045
|
return `${output}/${fileName}`;
|
|
3046
3046
|
}
|
|
3047
|
+
function hashString(input) {
|
|
3048
|
+
let hash = 2166136261;
|
|
3049
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
3050
|
+
hash ^= input.charCodeAt(i);
|
|
3051
|
+
hash = Math.imul(hash, 16777619);
|
|
3052
|
+
}
|
|
3053
|
+
return (hash >>> 0).toString(16);
|
|
3054
|
+
}
|
|
3047
3055
|
function writeFileWithDirSync(file, data) {
|
|
3048
3056
|
const dir = path.dirname(file);
|
|
3049
3057
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
3050
3058
|
if (fs.existsSync(file)) {
|
|
3051
|
-
|
|
3059
|
+
const existingData = fs.readFileSync(file, "utf-8");
|
|
3060
|
+
if (hashString(existingData) === hashString(data) && existingData === data) return;
|
|
3052
3061
|
}
|
|
3053
3062
|
fs.writeFileSync(file, data, "utf-8");
|
|
3054
3063
|
}
|
|
3055
|
-
function
|
|
3056
|
-
writeFileWithDirSync(fileName,
|
|
3064
|
+
async function writeFile({ fileName, content }, options) {
|
|
3065
|
+
writeFileWithDirSync(fileName, options?.formatGeneratedFile ? await options.formatGeneratedFile({
|
|
3066
|
+
fileName,
|
|
3067
|
+
content
|
|
3068
|
+
}) : content);
|
|
3057
3069
|
}
|
|
3058
|
-
function writeGenerateFileData(filesData) {
|
|
3059
|
-
filesData
|
|
3070
|
+
async function writeGenerateFileData(filesData, options) {
|
|
3071
|
+
for (const file of filesData) await writeFile(file, options);
|
|
3060
3072
|
}
|
|
3061
3073
|
|
|
3062
3074
|
//#endregion
|
package/dist/generator.d.mts
CHANGED
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-C7btBlMx.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-CXeVTk1T.mjs";
|
|
2
|
-
import "./options-
|
|
3
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
2
|
+
import "./options-PQDrYdAn.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-HbwoMgWr.mjs";
|
|
4
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import "i18next";
|
|
@@ -12,6 +12,7 @@ interface GenerateFileData {
|
|
|
12
12
|
fileName: string;
|
|
13
13
|
content: string;
|
|
14
14
|
}
|
|
15
|
+
type GenerateFileFormatter = (file: GenerateFileData) => string | Promise<string>;
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/generators/types/options.d.ts
|
|
17
18
|
interface ZodGenerateOptions {
|
|
@@ -88,4 +89,4 @@ interface BaseGenerateOptions {
|
|
|
88
89
|
}
|
|
89
90
|
interface GenerateOptions extends BaseGenerateOptions, ZodGenerateOptions, EndpointsGenerateOptions, QueriesGenerateOptions, InfiniteQueriesGenerateOptions, ACLGenerateOptions, BuilderConfigsGenerateOptions {}
|
|
90
91
|
//#endregion
|
|
91
|
-
export { GenerateFileData as n, GenerateOptions as t };
|
|
92
|
+
export { GenerateFileData as n, GenerateFileFormatter as r, GenerateOptions as t };
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-C7btBlMx.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-C7QVcw6n.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.25";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-PQDrYdAn.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-HbwoMgWr.mjs";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.d.ts
|
|
6
|
-
|
|
6
|
+
type OpenApiCodegenViteConfig = OpenAPICodegenConfig & {
|
|
7
|
+
formatGeneratedFile?: GenerateFileFormatter;
|
|
8
|
+
};
|
|
9
|
+
declare function openApiCodegen(config: OpenApiCodegenViteConfig): Plugin;
|
|
7
10
|
//#endregion
|
|
8
|
-
export { type OpenAPICodegenConfig, openApiCodegen };
|
|
11
|
+
export { type OpenAPICodegenConfig, type OpenApiCodegenViteConfig, openApiCodegen };
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-C7btBlMx.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-C7QVcw6n.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|
|
@@ -7,13 +7,14 @@ function openApiCodegen(config) {
|
|
|
7
7
|
let resolvedViteConfig;
|
|
8
8
|
let queue = Promise.resolve();
|
|
9
9
|
const isLocalInput = typeof config.input === "string" && !/^https?:\/\//i.test(config.input);
|
|
10
|
-
const normalizedConfig =
|
|
10
|
+
const { formatGeneratedFile, ...normalizedConfig } = config;
|
|
11
11
|
const enqueueGenerate = () => {
|
|
12
12
|
queue = queue.then(async () => {
|
|
13
13
|
const currentConfig = resolvedViteConfig;
|
|
14
14
|
if (!currentConfig) return;
|
|
15
15
|
await runGenerate({
|
|
16
16
|
fileConfig: normalizePaths(normalizedConfig, currentConfig.root),
|
|
17
|
+
formatGeneratedFile,
|
|
17
18
|
profiler: new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1")
|
|
18
19
|
});
|
|
19
20
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@povio/openapi-codegen-cli",
|
|
3
|
-
"version": "2.0.8-rc.
|
|
3
|
+
"version": "2.0.8-rc.25",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"codegen",
|
|
6
6
|
"openapi",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
75
75
|
"i18next": "^25.8.13",
|
|
76
76
|
"import-fresh": "^3.3.1",
|
|
77
|
+
"openapi-types": "^12.1.3",
|
|
77
78
|
"prompt-sync": "^4.2.0",
|
|
78
79
|
"reflect-metadata": "^0.2.2",
|
|
79
80
|
"ts-pattern": "^5.9.0",
|
|
80
81
|
"typescript": "^5.9.3",
|
|
81
|
-
"yargs": "^18.0.0"
|
|
82
|
-
"openapi-types": "^12.1.3"
|
|
82
|
+
"yargs": "^18.0.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@casl/ability": "^6.8.0",
|