@povio/openapi-codegen-cli 3.0.0-rc.8 → 3.0.0

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,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-BPAjzilp.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-BZOw7Hx4.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 getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-DGox5gzo.mjs";
1
+ import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.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
- import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-B4aYKmyL.mjs";
2
- import "./options-BPAjzilp.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
1
+ import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-oM5YJYYH.mjs";
2
+ import "./options-BZOw7Hx4.mjs";
3
+ import { t as OpenAPICodegenConfig } from "./config-CrZa_Jbm.mjs";
4
4
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
5
5
  import { z } from "zod";
6
6
  import "i18next";
@@ -26,6 +26,7 @@ interface RequestInfo<ZOutput, ECodes extends string> {
26
26
  }
27
27
  interface RequestConfig<IsRawRes extends boolean = false> {
28
28
  rawResponse?: IsRawRes;
29
+ allowInvalidResponseData?: boolean;
29
30
  }
30
31
  type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
31
32
  interface RestClient {
@@ -90,6 +91,7 @@ declare namespace OpenApiQueryConfig {
90
91
  invalidateCurrentModule?: boolean;
91
92
  invalidationMap?: InvalidationMap<TQueryModule>;
92
93
  crossTabInvalidation?: boolean;
94
+ allowInvalidResponseData?: boolean;
93
95
  onError?: (error: unknown) => void;
94
96
  }
95
97
  type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
@@ -98,6 +100,7 @@ declare namespace OpenApiQueryConfig {
98
100
  invalidateCurrentModule,
99
101
  invalidationMap,
100
102
  crossTabInvalidation,
103
+ allowInvalidResponseData,
101
104
  onError,
102
105
  children
103
106
  }: PropsWithChildren<ProviderProps<TQueryModule>>): react_jsx_runtime0.JSX.Element;
package/dist/index.mjs CHANGED
@@ -66,9 +66,18 @@ var RestClient = class {
66
66
  async makeRequest(requestInfo, requestConfig) {
67
67
  const errorStack = (/* @__PURE__ */ new Error()).stack;
68
68
  try {
69
- const { rawResponse, ...config } = requestConfig;
69
+ const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
70
70
  const res = await this.client(config);
71
- const resData = requestInfo.resSchema.parse(res.data);
71
+ const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
72
+ const parseResult = requestInfo.resSchema.safeParse(responseData);
73
+ let resData;
74
+ if (parseResult.success) resData = parseResult.data;
75
+ else if (allowInvalidResponseData && config.method === "get") {
76
+ parseResult.error.name = "BE Response schema mismatch - ZodError";
77
+ parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
78
+ console.error(parseResult.error);
79
+ resData = res.data;
80
+ } else throw parseResult.error;
72
81
  return rawResponse ? {
73
82
  ...res,
74
83
  data: resData
@@ -113,18 +122,20 @@ var RestInterceptor = class {
113
122
  let OpenApiQueryConfig;
114
123
  (function(_OpenApiQueryConfig) {
115
124
  const Context = createContext({});
116
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, onError, children }) {
125
+ function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
117
126
  const value = useMemo(() => ({
118
127
  preferUpdate,
119
128
  invalidateCurrentModule,
120
129
  invalidationMap,
121
130
  crossTabInvalidation,
131
+ allowInvalidResponseData,
122
132
  onError
123
133
  }), [
124
134
  preferUpdate,
125
135
  invalidateCurrentModule,
126
136
  invalidationMap,
127
137
  crossTabInvalidation,
138
+ allowInvalidResponseData,
128
139
  onError
129
140
  ]);
130
141
  return /* @__PURE__ */ jsx(Context.Provider, {
@@ -0,0 +1,32 @@
1
+ import { r as GenerateFileFormatter } from "./options-BZOw7Hx4.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-CrZa_Jbm.mjs";
3
+ import { IncomingMessage, ServerResponse } from "http";
4
+
5
+ //#region src/metro/openapi-codegen.plugin.d.ts
6
+ type OpenApiCodegenMetroConfig = OpenAPICodegenConfig & {
7
+ formatGeneratedFile?: GenerateFileFormatter;
8
+ };
9
+ type OpenApiCodegenMetroOptions = {
10
+ root?: string;
11
+ watchOpenApiInput?: boolean;
12
+ };
13
+ type MetroNextFunction = (error?: unknown) => void;
14
+ type MetroMiddleware = (request: IncomingMessage, response: ServerResponse, next: MetroNextFunction) => unknown;
15
+ type MetroServer = unknown;
16
+ type MetroConfig = {
17
+ projectRoot?: string;
18
+ server?: {
19
+ enhanceMiddleware?: (middleware: MetroMiddleware, server: MetroServer) => MetroMiddleware;
20
+ [key: string]: unknown;
21
+ };
22
+ transformer?: {
23
+ getTransformOptions?: (...args: unknown[]) => unknown;
24
+ [key: string]: unknown;
25
+ };
26
+ watchFolders?: readonly string[];
27
+ [key: string]: unknown;
28
+ };
29
+ declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: Promise<TMetroConfig>, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): Promise<TMetroConfig>;
30
+ declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: TMetroConfig, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): TMetroConfig;
31
+ //#endregion
32
+ export { type MetroConfig, type MetroMiddleware, type OpenAPICodegenConfig, type OpenApiCodegenMetroConfig, type OpenApiCodegenMetroOptions, withOpenApiCodegen };
package/dist/metro.mjs ADDED
@@ -0,0 +1,86 @@
1
+ import "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
+ import "./generate.runner-BXTc97I0.mjs";
3
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-QGd35-a3.mjs";
4
+ import fs from "fs";
5
+ import path from "path";
6
+
7
+ //#region src/metro/openapi-codegen.plugin.ts
8
+ function withOpenApiCodegen(metroConfig, codegenConfig, options = {}) {
9
+ if (isPromiseLike(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedOpenApiCodegen(resolvedConfig, codegenConfig, options));
10
+ return withResolvedOpenApiCodegen(metroConfig, codegenConfig, options);
11
+ }
12
+ function withResolvedOpenApiCodegen(metroConfig, codegenConfig, options) {
13
+ const root = path.resolve(options.root ?? metroConfig.projectRoot ?? process.cwd());
14
+ const codegen = createOpenApiCodegenRunner(codegenConfig);
15
+ const originalEnhanceMiddleware = metroConfig.server?.enhanceMiddleware;
16
+ const originalGetTransformOptions = metroConfig.transformer?.getTransformOptions;
17
+ let startupSucceeded = false;
18
+ let inflightGenerate;
19
+ let inputWatcher;
20
+ const requestStartupGenerate = () => {
21
+ if (startupSucceeded) return Promise.resolve();
22
+ if (inflightGenerate) return inflightGenerate;
23
+ const attempt = codegen.enqueueGenerate(root).then(() => {
24
+ startupSucceeded = true;
25
+ inflightGenerate = void 0;
26
+ }, (error) => {
27
+ inflightGenerate = void 0;
28
+ throw error;
29
+ });
30
+ inflightGenerate = attempt;
31
+ return attempt;
32
+ };
33
+ const ensureInputWatcher = () => {
34
+ if (options.watchOpenApiInput === false || inputWatcher) return;
35
+ const inputPath = codegen.getLocalInputPath(root);
36
+ if (!inputPath) return;
37
+ try {
38
+ inputWatcher = fs.watch(inputPath, { persistent: false }, () => {
39
+ startupSucceeded = false;
40
+ requestStartupGenerate().catch(reportGenerateError);
41
+ });
42
+ inputWatcher.on("error", reportWatcherError);
43
+ } catch (error) {
44
+ reportWatcherError(error);
45
+ }
46
+ };
47
+ const wrappedConfig = {
48
+ ...metroConfig,
49
+ server: {
50
+ ...metroConfig.server,
51
+ enhanceMiddleware(middleware, server) {
52
+ ensureInputWatcher();
53
+ const enhancedMiddleware = originalEnhanceMiddleware ? originalEnhanceMiddleware(middleware, server) : middleware;
54
+ return async (request, response, next) => {
55
+ try {
56
+ await requestStartupGenerate();
57
+ return await enhancedMiddleware(request, response, next);
58
+ } catch (error) {
59
+ next(error);
60
+ }
61
+ };
62
+ }
63
+ },
64
+ transformer: {
65
+ ...metroConfig.transformer,
66
+ async getTransformOptions(...args) {
67
+ await requestStartupGenerate();
68
+ return originalGetTransformOptions ? originalGetTransformOptions(...args) : void 0;
69
+ }
70
+ }
71
+ };
72
+ if (options.root || metroConfig.projectRoot) wrappedConfig.projectRoot = root;
73
+ return wrappedConfig;
74
+ }
75
+ function isPromiseLike(value) {
76
+ return typeof value.then === "function";
77
+ }
78
+ function reportGenerateError(error) {
79
+ console.error("[openapi-codegen] Failed to generate OpenAPI client from Metro config.", error);
80
+ }
81
+ function reportWatcherError(error) {
82
+ console.error("[openapi-codegen] Failed to watch OpenAPI input from Metro config.", error);
83
+ }
84
+
85
+ //#endregion
86
+ export { withOpenApiCodegen };
@@ -0,0 +1,42 @@
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
+ import { t as runGenerate } from "./generate.runner-BXTc97I0.mjs";
3
+ import path from "path";
4
+
5
+ //#region src/plugins/openapi-codegen.runner.ts
6
+ function createOpenApiCodegenRunner(config) {
7
+ let queue = Promise.resolve();
8
+ const { formatGeneratedFile, ...fileConfig } = config;
9
+ const enqueueGenerate = (root) => {
10
+ const run = queue.catch(() => void 0).then(async () => {
11
+ const profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1");
12
+ await runGenerate({
13
+ fileConfig: normalizeOpenApiCodegenPaths(fileConfig, root),
14
+ formatGeneratedFile,
15
+ profiler
16
+ });
17
+ });
18
+ queue = run.then(() => void 0, () => void 0);
19
+ return run;
20
+ };
21
+ return {
22
+ enqueueGenerate,
23
+ getLocalInputPath: (root) => getLocalInputPath(config.input, root),
24
+ isLocalInput: isLocalOpenApiInput(config.input)
25
+ };
26
+ }
27
+ function normalizeOpenApiCodegenPaths(config, root) {
28
+ const normalized = { ...config };
29
+ if (typeof normalized.output === "string" && !path.isAbsolute(normalized.output)) normalized.output = path.resolve(root, normalized.output);
30
+ if (typeof normalized.input === "string" && !path.isAbsolute(normalized.input) && isLocalOpenApiInput(normalized.input)) normalized.input = path.resolve(root, normalized.input);
31
+ return normalized;
32
+ }
33
+ function getLocalInputPath(input, root) {
34
+ if (!isLocalOpenApiInput(input)) return;
35
+ return path.resolve(root, input);
36
+ }
37
+ function isLocalOpenApiInput(input) {
38
+ return typeof input === "string" && !/^https?:\/\//i.test(input);
39
+ }
40
+
41
+ //#endregion
42
+ export { createOpenApiCodegenRunner as t };
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-DGox5gzo.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-C94-P4xF.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-BXTc97I0.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 "3.0.0-rc.8";
42
+ return "3.0.0";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.d.mts CHANGED
@@ -1,11 +1,14 @@
1
- import { r as GenerateFileFormatter } from "./options-BPAjzilp.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
1
+ import { r as GenerateFileFormatter } from "./options-BZOw7Hx4.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-CrZa_Jbm.mjs";
3
3
  import { Plugin } from "vite";
4
4
 
5
- //#region src/vite/openapi-codegen.plugin.d.ts
6
- type OpenApiCodegenViteConfig = OpenAPICodegenConfig & {
5
+ //#region src/plugins/openapi-codegen.runner.d.ts
6
+ type OpenApiCodegenPluginConfig = OpenAPICodegenConfig & {
7
7
  formatGeneratedFile?: GenerateFileFormatter;
8
8
  };
9
+ //#endregion
10
+ //#region src/vite/openapi-codegen.plugin.d.ts
11
+ type OpenApiCodegenViteConfig = OpenApiCodegenPluginConfig;
9
12
  declare function openApiCodegen(config: OpenApiCodegenViteConfig): Plugin;
10
13
  //#endregion
11
14
  export { type OpenAPICodegenConfig, type OpenApiCodegenViteConfig, openApiCodegen };
package/dist/vite.mjs CHANGED
@@ -1,28 +1,20 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-DGox5gzo.mjs";
2
- import { t as runGenerate } from "./generate.runner-C94-P4xF.mjs";
1
+ import "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
+ import "./generate.runner-BXTc97I0.mjs";
3
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-QGd35-a3.mjs";
3
4
  import path from "path";
4
5
 
5
6
  //#region src/vite/openapi-codegen.plugin.ts
6
7
  function openApiCodegen(config) {
7
8
  let resolvedViteConfig;
8
- let queue = Promise.resolve();
9
- const isLocalInput = typeof config.input === "string" && !/^https?:\/\//i.test(config.input);
10
- const { formatGeneratedFile, ...normalizedConfig } = config;
9
+ const codegen = createOpenApiCodegenRunner(config);
11
10
  const enqueueGenerate = () => {
12
- queue = queue.then(async () => {
13
- const currentConfig = resolvedViteConfig;
14
- if (!currentConfig) return;
15
- await runGenerate({
16
- fileConfig: normalizePaths(normalizedConfig, currentConfig.root),
17
- formatGeneratedFile,
18
- profiler: new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1")
19
- });
20
- });
21
- return queue;
11
+ const currentConfig = resolvedViteConfig;
12
+ if (!currentConfig) return Promise.resolve();
13
+ return codegen.enqueueGenerate(currentConfig.root);
22
14
  };
23
15
  const setupWatcher = (server) => {
24
- if (!isLocalInput || !config.input) return;
25
- const openApiPath = path.resolve(server.config.root, config.input);
16
+ const openApiPath = codegen.getLocalInputPath(server.config.root);
17
+ if (!openApiPath) return;
26
18
  server.watcher.add(openApiPath);
27
19
  server.watcher.on("change", (changedPath) => {
28
20
  if (path.resolve(changedPath) === openApiPath) enqueueGenerate();
@@ -42,12 +34,6 @@ function openApiCodegen(config) {
42
34
  }
43
35
  };
44
36
  }
45
- function normalizePaths(config, root) {
46
- const normalized = { ...config };
47
- if (typeof normalized.output === "string" && !path.isAbsolute(normalized.output)) normalized.output = path.resolve(root, normalized.output);
48
- if (typeof normalized.input === "string" && !path.isAbsolute(normalized.input) && !/^https?:\/\//i.test(normalized.input)) normalized.input = path.resolve(root, normalized.input);
49
- return normalized;
50
- }
51
37
 
52
38
  //#endregion
53
39
  export { openApiCodegen };
package/dist/zod.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ErrorHandler } from "./error-handling-B4aYKmyL.mjs";
1
+ import { a as ErrorHandler } from "./error-handling-oM5YJYYH.mjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/zod.d.ts
package/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "3.0.0-rc.8",
4
3
  "keywords": [
5
4
  "codegen",
6
5
  "openapi",
@@ -35,6 +34,10 @@
35
34
  "types": "./dist/vite.d.mts",
36
35
  "import": "./dist/vite.mjs"
37
36
  },
37
+ "./metro": {
38
+ "types": "./dist/metro.d.mts",
39
+ "import": "./dist/metro.mjs"
40
+ },
38
41
  "./generator": {
39
42
  "types": "./dist/generator.d.mts",
40
43
  "import": "./dist/generator.mjs"
@@ -127,5 +130,6 @@
127
130
  "node": ">= 14",
128
131
  "pnpm": ">= 9"
129
132
  },
130
- "packageManager": "pnpm@10.4.0"
133
+ "packageManager": "pnpm@10.4.0",
134
+ "version": "3.0.0"
131
135
  }