@povio/openapi-codegen-cli 2.0.8-rc.23 → 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 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 { t as GenerateOptions } from "./options-BNqkO_OS.mjs";
1
+ import { t as GenerateOptions } from "./options-PQDrYdAn.mjs";
2
2
 
3
3
  //#region src/generators/types/config.d.ts
4
4
  type OpenAPICodegenConfig = Partial<GenerateOptions>;
@@ -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-vrPucfhY.mjs";
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.runSync("files.write", () => writeGenerateFileData(filesData));
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,
@@ -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
- if (fs.readFileSync(file, "utf-8") === data) return;
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 writeFileSync$1({ fileName, content }) {
3056
- writeFileWithDirSync(fileName, content);
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.forEach(writeFileSync$1);
3070
+ async function writeGenerateFileData(filesData, options) {
3071
+ for (const file of filesData) await writeFile(file, options);
3060
3072
  }
3061
3073
 
3062
3074
  //#endregion
@@ -3206,42 +3218,55 @@ function getBuilderConfigs({ data, tag, resolver }) {
3206
3218
  if (createEndpoint) {
3207
3219
  importedEndpoints.push(createEndpoint);
3208
3220
  const body = getEndpointBody$1(createEndpoint);
3209
- if (body) importedZodSchemas.push(body.zodSchema);
3210
- config.create = {
3211
- acl: getAclConfig(createEndpoint, resolver.options),
3212
- mutation: getImportedQueryName(createEndpoint, resolver.options),
3213
- inputDefs: getInputsConfig(resolver, body)
3214
- };
3221
+ if (body) {
3222
+ importedZodSchemas.push(body.zodSchema);
3223
+ config.create = {
3224
+ acl: getAclConfig(createEndpoint, resolver.options),
3225
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3226
+ mutation: createEndpoint,
3227
+ inputDefs: getInputsConfig(resolver, body)
3228
+ };
3229
+ }
3215
3230
  }
3216
3231
  const updateEndpoint = extendedEndpoints.find((endpoint) => isUpdateEndpoint(endpoint, readAllEndpoint));
3217
3232
  if (updateEndpoint) {
3218
3233
  importedEndpoints.push(updateEndpoint);
3219
3234
  const body = getEndpointBody$1(updateEndpoint);
3220
- if (body) importedZodSchemas.push(body.zodSchema);
3221
- config.update = {
3222
- acl: getAclConfig(updateEndpoint, resolver.options),
3223
- mutation: getImportedQueryName(updateEndpoint, resolver.options),
3224
- inputDefs: getInputsConfig(resolver, body)
3225
- };
3235
+ if (body) {
3236
+ importedZodSchemas.push(body.zodSchema);
3237
+ config.update = {
3238
+ acl: getAclConfig(updateEndpoint, resolver.options),
3239
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3240
+ mutation: updateEndpoint,
3241
+ inputDefs: getInputsConfig(resolver, body)
3242
+ };
3243
+ }
3226
3244
  }
3227
3245
  const deleteEndpoint = extendedEndpoints.find((endpoint) => isDeleteEndpoint(endpoint, readAllEndpoint));
3228
3246
  if (deleteEndpoint) {
3229
3247
  importedEndpoints.push(deleteEndpoint);
3230
- config.delete = {
3231
- acl: getAclConfig(deleteEndpoint, resolver.options),
3232
- mutation: getImportedQueryName(deleteEndpoint, resolver.options)
3233
- };
3248
+ const body = getEndpointBody$1(deleteEndpoint);
3249
+ if (body) {
3250
+ importedZodSchemas.push(body.zodSchema);
3251
+ config.delete = {
3252
+ acl: getAclConfig(deleteEndpoint, resolver.options),
3253
+ mutation: deleteEndpoint
3254
+ };
3255
+ }
3234
3256
  }
3235
3257
  const bulkDeleteEndpoint = extendedEndpoints.find((endpoint) => isBulkDeleteEndpoint(endpoint, readAllEndpoint));
3236
3258
  if (bulkDeleteEndpoint) {
3237
3259
  importedEndpoints.push(bulkDeleteEndpoint);
3238
3260
  const body = getEndpointBody$1(bulkDeleteEndpoint);
3239
- if (body) importedZodSchemas.push(body.zodSchema);
3240
- config.bulkDelete = {
3241
- acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
3242
- mutation: getImportedQueryName(bulkDeleteEndpoint, resolver.options),
3243
- inputDefs: getInputsConfig(resolver, body)
3244
- };
3261
+ if (body) {
3262
+ importedZodSchemas.push(body.zodSchema);
3263
+ config.bulkDelete = {
3264
+ acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
3265
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3266
+ mutation: bulkDeleteEndpoint,
3267
+ inputDefs: getInputsConfig(resolver, body)
3268
+ };
3269
+ }
3245
3270
  }
3246
3271
  return config;
3247
3272
  });
@@ -3359,12 +3384,70 @@ function getSchemaProperties(resolver, schema) {
3359
3384
  return {};
3360
3385
  }
3361
3386
 
3387
+ //#endregion
3388
+ //#region src/generators/const/queries.const.ts
3389
+ const QUERY_HOOKS = {
3390
+ query: "useQuery",
3391
+ infiniteQuery: "useInfiniteQuery",
3392
+ mutation: "useMutation"
3393
+ };
3394
+ const QUERY_IMPORT = {
3395
+ bindings: [
3396
+ QUERY_HOOKS.query,
3397
+ QUERY_HOOKS.infiniteQuery,
3398
+ QUERY_HOOKS.mutation
3399
+ ],
3400
+ from: "@tanstack/react-query"
3401
+ };
3402
+ const QUERIES_MODULE_NAME = "moduleName";
3403
+
3362
3404
  //#endregion
3363
3405
  //#region src/generators/generate/generateConfigs.ts
3364
3406
  function generateConfigs(generateTypeParams) {
3365
- const { configs, hasZodImport, modelsImports, queriesImports, aclImports } = getBuilderConfigs(generateTypeParams);
3407
+ const { configs, hasZodImport, modelsImports, aclImports } = getBuilderConfigs(generateTypeParams);
3366
3408
  if (configs.length === 0) return;
3367
3409
  const { resolver, tag } = generateTypeParams;
3410
+ const endpoints = configs.flatMap((config) => [
3411
+ config.create?.mutation,
3412
+ config.update?.mutation,
3413
+ config.delete?.mutation,
3414
+ config.bulkDelete?.mutation
3415
+ ]).filter((m) => typeof m !== "string" && m !== void 0);
3416
+ const hasMutation = endpoints.length > 0;
3417
+ resolver.options.checkAcl && endpoints.some((e) => e.acl);
3418
+ const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
3419
+ const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((e) => resolver.options.workspaceContext);
3420
+ const endpointsImports = getEndpointsImports({
3421
+ tag,
3422
+ endpoints,
3423
+ options: resolver.options
3424
+ });
3425
+ const queryImport = {
3426
+ bindings: [QUERY_HOOKS.mutation],
3427
+ from: "@tanstack/react-query"
3428
+ };
3429
+ const queryTypesImport = {
3430
+ bindings: ["OpenApiQueryConfig"],
3431
+ typeBindings: [QUERY_OPTIONS_TYPES.mutation],
3432
+ from: getQueryTypesImportPath(resolver.options)
3433
+ };
3434
+ const mutationEffectsImport = {
3435
+ bindings: [MUTATION_EFFECTS.hookName],
3436
+ typeBindings: [MUTATION_EFFECTS.optionsType],
3437
+ from: PACKAGE_IMPORT_PATH
3438
+ };
3439
+ const queryModulesImport = {
3440
+ bindings: [QUERY_MODULE_ENUM],
3441
+ from: getQueryModulesImportPath(resolver.options)
3442
+ };
3443
+ const aclCheckImport = {
3444
+ bindings: [ACL_CHECK_HOOK],
3445
+ from: ACL_PACKAGE_IMPORT_PATH
3446
+ };
3447
+ const workspaceContextImport = {
3448
+ bindings: ["OpenApiWorkspaceContext"],
3449
+ from: PACKAGE_IMPORT_PATH
3450
+ };
3368
3451
  const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
3369
3452
  const dynamicInputsImport = {
3370
3453
  bindings: [BUILDERS_UTILS.dynamicInputs],
@@ -3380,7 +3463,17 @@ function generateConfigs(generateTypeParams) {
3380
3463
  if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
3381
3464
  if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
3382
3465
  for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
3383
- for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
3466
+ for (const endpointsImport of endpointsImports) lines.push(renderImport$3(endpointsImport));
3467
+ if (hasMutation) {
3468
+ lines.push(renderImport$3(queryImport));
3469
+ lines.push(renderImport$3(queryTypesImport));
3470
+ if (hasMutationEffects) {
3471
+ lines.push(renderImport$3(queryModulesImport));
3472
+ lines.push(renderImport$3(mutationEffectsImport));
3473
+ }
3474
+ lines.push(renderImport$3(aclCheckImport));
3475
+ if (hasWorkspaceContext) lines.push(renderImport$3(workspaceContextImport));
3476
+ }
3384
3477
  for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
3385
3478
  lines.push("");
3386
3479
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
@@ -3389,7 +3482,7 @@ function generateConfigs(generateTypeParams) {
3389
3482
  options: resolver.options
3390
3483
  })} {`);
3391
3484
  for (const config of configs) {
3392
- lines.push(renderBuilderConfig(config));
3485
+ lines.push(renderBuilderConfig(config, generateTypeParams));
3393
3486
  lines.push("");
3394
3487
  }
3395
3488
  if (resolver.options.tsNamespaces) lines.push("}");
@@ -3425,7 +3518,48 @@ function renderColumnsConfig(columnsConfig) {
3425
3518
  lines.push("}");
3426
3519
  return lines.join("\n");
3427
3520
  }
3428
- function renderBuilderConfig(config) {
3521
+ function renderMutationContent(resolver, endpoint, tag) {
3522
+ const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
3523
+ const hasMutationEffects = resolver.options.mutationEffects;
3524
+ const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
3525
+ const endpointTag = getEndpointTag(endpoint, resolver.options);
3526
+ const endpointParams = mapEndpointParamsToFunctionParams(resolver, endpoint, {
3527
+ includeFileParam: true,
3528
+ modelNamespaceTag: endpointTag
3529
+ });
3530
+ const endpointParamsStr = endpointParams.map((p) => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ");
3531
+ const destructuredMutationArgs = endpointParams.map((p) => p.name).join(", ");
3532
+ const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
3533
+ const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
3534
+ const lines = [];
3535
+ lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasAxiosRequestConfig ? `, config?: AxiosRequestConfig` : ""}) => {`);
3536
+ lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
3537
+ if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
3538
+ lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
3539
+ lines.push("");
3540
+ lines.push(` return ${QUERY_HOOKS.mutation}({`);
3541
+ const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
3542
+ lines.push(` mutationFn: (${mutationFnArg}) => {`);
3543
+ if (hasAclCheck) lines.push(` checkAcl(${getNamespaceName({
3544
+ type: GenerateType.Acl,
3545
+ tag: endpointTag,
3546
+ options: resolver.options
3547
+ })}.canUse${capitalize(snakeToCamel(endpoint.operationName))}({ ${destructuredMutationArgs} }));`);
3548
+ lines.push(` return ${endpointFunction}(${destructuredMutationArgs}${hasAxiosRequestConfig ? `${destructuredMutationArgs ? ", " : ""}config` : ""});`);
3549
+ lines.push(" },");
3550
+ if (hasMutationEffects) {
3551
+ lines.push(" onSuccess: async (...args) => {");
3552
+ lines.push(" await runMutationEffects();");
3553
+ lines.push(" await options?.onSuccess?.(...args);");
3554
+ lines.push(" },");
3555
+ }
3556
+ lines.push(" ...options,");
3557
+ lines.push(" });");
3558
+ lines.push("}");
3559
+ return lines.map((line) => " " + line).join("\n").trimStart();
3560
+ }
3561
+ function renderBuilderConfig(config, params) {
3562
+ const { resolver, tag } = params;
3429
3563
  const lines = [];
3430
3564
  lines.push(`export const ${config.name} = {`);
3431
3565
  lines.push(" meta: {");
@@ -3454,23 +3588,31 @@ function renderBuilderConfig(config) {
3454
3588
  if (config.create) {
3455
3589
  lines.push(" create: {");
3456
3590
  if (config.create.acl) lines.push(` acl: ${config.create.acl},`);
3457
- if (config.create.inputDefs) lines.push(` schema: ${config.create.inputDefs.schema},`);
3458
- lines.push(` mutation: ${config.create.mutation},`);
3591
+ if (config.create.schema) lines.push(` schema: ${config.create.schema},`);
3592
+ lines.push(` mutation: ${typeof config.create.mutation === "string" ? config.create.mutation : renderMutationContent(resolver, config.create.mutation, tag)},`);
3459
3593
  if (config.create.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.create.inputDefs)})`);
3460
3594
  lines.push(" },");
3461
3595
  }
3462
3596
  if (config.update) {
3463
3597
  lines.push(" update: {");
3464
3598
  if (config.update.acl) lines.push(` acl: ${config.update.acl},`);
3465
- if (config.update.inputDefs) lines.push(` schema: ${config.update.inputDefs.schema},`);
3466
- lines.push(` mutation: ${config.update.mutation},`);
3599
+ if (config.update.schema) lines.push(` schema: ${config.update.schema},`);
3600
+ lines.push(` mutation: ${typeof config.update.mutation === "string" ? config.update.mutation : renderMutationContent(resolver, config.update.mutation, tag)},`);
3467
3601
  if (config.update.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.update.inputDefs)})`);
3468
3602
  lines.push(" },");
3469
3603
  }
3470
3604
  if (config.delete) {
3471
3605
  lines.push(" delete: {");
3472
3606
  if (config.delete.acl) lines.push(` acl: ${config.delete.acl},`);
3473
- lines.push(` mutation: ${config.delete.mutation},`);
3607
+ lines.push(` mutation: ${typeof config.delete.mutation === "string" ? config.delete.mutation : renderMutationContent(resolver, config.delete.mutation, tag)},`);
3608
+ lines.push(" },");
3609
+ }
3610
+ if (config.bulkDelete) {
3611
+ lines.push(" bulkDelete: {");
3612
+ if (config.bulkDelete.acl) lines.push(` acl: ${config.bulkDelete.acl},`);
3613
+ if (config.bulkDelete.schema) lines.push(` schema: ${config.bulkDelete.schema},`);
3614
+ lines.push(` mutation: ${typeof config.bulkDelete.mutation === "string" ? config.bulkDelete.mutation : renderMutationContent(resolver, config.bulkDelete.mutation, tag)},`);
3615
+ if (config.bulkDelete.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.bulkDelete.inputDefs)})`);
3474
3616
  lines.push(" },");
3475
3617
  }
3476
3618
  lines.push("};");
@@ -3725,23 +3867,6 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
3725
3867
  return lines.join("\n");
3726
3868
  }
3727
3869
 
3728
- //#endregion
3729
- //#region src/generators/const/queries.const.ts
3730
- const QUERY_HOOKS = {
3731
- query: "useQuery",
3732
- infiniteQuery: "useInfiniteQuery",
3733
- mutation: "useMutation"
3734
- };
3735
- const QUERY_IMPORT = {
3736
- bindings: [
3737
- QUERY_HOOKS.query,
3738
- QUERY_HOOKS.infiniteQuery,
3739
- QUERY_HOOKS.mutation
3740
- ],
3741
- from: "@tanstack/react-query"
3742
- };
3743
- const QUERIES_MODULE_NAME = "moduleName";
3744
-
3745
3870
  //#endregion
3746
3871
  //#region src/generators/generate/generateQueries.ts
3747
3872
  const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-BNqkO_OS.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-PQDrYdAn.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
 
4
4
  //#region src/generators/types/metadata.d.ts
@@ -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-vrPucfhY.mjs";
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-BNqkO_OS.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-BHkVxL6S.mjs";
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-vrPucfhY.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-DKpRoYsX.mjs";
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.23";
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-BNqkO_OS.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-BHkVxL6S.mjs";
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
- declare function openApiCodegen(config: OpenAPICodegenConfig): Plugin;
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-vrPucfhY.mjs";
2
- import { t as runGenerate } from "./generate.runner-DKpRoYsX.mjs";
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 = { ...config };
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.23",
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",