@povio/openapi-codegen-cli 3.1.0-rc.7 → 3.1.1-rc.1

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/acl.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ErrorHandler } from "./error-handling-BeRxGbwE.mjs";
1
+ import { a as ErrorHandler } from "./error-handling-D-mHJ60d.mjs";
2
2
  import * as react from "react";
3
3
  import { PropsWithChildren } from "react";
4
4
  import * as react_jsx_runtime0 from "react/jsx-runtime";
package/dist/acl.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as SharedErrorHandler } from "./error-handling-DG8SfTWB.mjs";
1
+ import { i as SharedErrorHandler } from "./error-handling-DSI86D3u.mjs";
2
2
  import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.mjs";
3
3
  import { createContext, useCallback, useEffect, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
@@ -74,6 +74,8 @@ declare class ErrorHandler<CodeT extends string | number> {
74
74
  onRethrowError
75
75
  }: ErrorHandlerOptions<CodeT>);
76
76
  private matchesEntry;
77
+ /** Lazy so resolveT() only runs when getMessage actually uses `t`. */
78
+ private static lazyT;
77
79
  rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
78
80
  getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
79
81
  getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
@@ -97,7 +97,7 @@ var DomainErrorRegistry = class {
97
97
  return this.entries.get(code);
98
98
  }
99
99
  };
100
- var ErrorHandler = class {
100
+ var ErrorHandler = class ErrorHandler {
101
101
  entries = [];
102
102
  userEntries;
103
103
  generalEntries;
@@ -164,25 +164,28 @@ var ErrorHandler = class {
164
164
  if (entry.condition) return entry.condition(error);
165
165
  return code === entry.code;
166
166
  }
167
+ /** Lazy so resolveT() only runs when getMessage actually uses `t`. */
168
+ static lazyT = (key, options) => resolveT()(key, options);
167
169
  rethrowError(error) {
168
170
  const code = RestUtils.extractServerResponseCode(error);
169
171
  const serverMessage = RestUtils.extractServerErrorMessage(error);
172
+ const t = ErrorHandler.lazyT;
170
173
  const userEntry = this.userEntries.find((entry) => this.matchesEntry(error, entry, code));
171
174
  if (userEntry) {
172
- const exception = new ApplicationException(userEntry.getMessage(resolveT(), error), userEntry.code, serverMessage);
175
+ const exception = new ApplicationException(userEntry.getMessage(t, error), userEntry.code, serverMessage);
173
176
  this.onRethrowError?.(error, exception);
174
177
  throw exception;
175
178
  }
176
179
  if (code !== null) {
177
180
  const registryEntry = DomainErrorRegistry.getEntry(code);
178
181
  if (registryEntry && (!registryEntry.condition || registryEntry.condition(error))) {
179
- const exception = new ApplicationException(registryEntry.getMessage(resolveT(), error), registryEntry.code, serverMessage);
182
+ const exception = new ApplicationException(registryEntry.getMessage(t, error), registryEntry.code, serverMessage);
180
183
  this.onRethrowError?.(error, exception);
181
184
  throw exception;
182
185
  }
183
186
  }
184
187
  const generalEntry = this.generalEntries.find((entry) => this.matchesEntry(error, entry, code));
185
- const exception = new ApplicationException(generalEntry.getMessage(resolveT(), error), generalEntry.code, serverMessage);
188
+ const exception = new ApplicationException(generalEntry.getMessage(t, error), generalEntry.code, serverMessage);
186
189
  this.onRethrowError?.(error, exception);
187
190
  throw exception;
188
191
  }
@@ -1,4 +1,4 @@
1
- import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-CbQ9gQss.mjs";
1
+ import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
@@ -4028,7 +4028,7 @@ function generateModels({ resolver, data, tag }) {
4028
4028
  const schemaRef = resolver.getRefByZodSchemaName(key);
4029
4029
  zodSchemasData[key] = {
4030
4030
  code,
4031
- isCiruclar: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
4031
+ isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
4032
4032
  isEnum: isEnumZodSchema(code),
4033
4033
  schemaObj: resolver.getZodSchemaObj(key)
4034
4034
  };
@@ -4049,14 +4049,50 @@ function generateModels({ resolver, data, tag }) {
4049
4049
  tag,
4050
4050
  resolver
4051
4051
  }));
4052
- lines.push(`export const ${name} = ${zodSchema.code};`);
4053
- lines.push(`export type ${getZodSchemaInferedTypeName(name, resolver.options)} = z.infer<typeof ${name}>;`);
4052
+ const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
4053
+ if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
4054
+ const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
4055
+ lines.push(`export const ${name}${typeAnnotation} = ${zodSchema.code};`);
4056
+ if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
4054
4057
  if (zodSchema.isEnum) lines.push(`export const ${getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
4055
4058
  lines.push("");
4056
4059
  }
4057
4060
  if (resolver.options.tsNamespaces) lines.push("}");
4058
4061
  return lines.join("\n").trimEnd() + "\n";
4059
4062
  }
4063
+ function renderSchemaType(schema, resolver) {
4064
+ if (isReferenceObject(schema)) {
4065
+ const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
4066
+ return schemaName ? getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
4067
+ }
4068
+ const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
4069
+ if (composite?.length) {
4070
+ const separator = schema.allOf ? " & " : " | ";
4071
+ return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
4072
+ }
4073
+ if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
4074
+ if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
4075
+ if (schema.type === "object" || schema.properties || schema.additionalProperties) {
4076
+ const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
4077
+ const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
4078
+ const hasDefault = !isReferenceObject(property) && property.default !== void 0;
4079
+ const optional = isRequired || hasDefault ? "" : "?";
4080
+ const propertyType = renderSchemaType(property, resolver);
4081
+ const outputType = resolver.options.replaceOptionalWithNullish && optional && (isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
4082
+ return `${wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
4083
+ });
4084
+ if (schema.additionalProperties) {
4085
+ const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
4086
+ properties.push(`[key: string]: ${valueType}`);
4087
+ }
4088
+ return addNullable(schema, `{ ${properties.join("; ")} }`);
4089
+ }
4090
+ const primitiveType = schema.type;
4091
+ return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
4092
+ }
4093
+ function addNullable(schema, type) {
4094
+ return schema.nullable && type !== "null" ? `${type} | null` : type;
4095
+ }
4060
4096
  function renderModelsProxy({ resolver, data, tag }) {
4061
4097
  const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
4062
4098
  const schemaNames = getUsedSchemaNames({
@@ -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-CbQ9gQss.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-DseBECa-.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,4 +1,4 @@
1
- import { a as ErrorHandler, c as SharedErrorHandler, d as ns, f as resources, i as ErrorEntry, l as TranslateFunction, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException, u as configureTranslations } from "./error-handling-BeRxGbwE.mjs";
1
+ import { a as ErrorHandler, c as SharedErrorHandler, d as ns, f as resources, i as ErrorEntry, l as TranslateFunction, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException, u as configureTranslations } from "./error-handling-D-mHJ60d.mjs";
2
2
  import "./options-CE4Koxof.mjs";
3
3
  import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
4
4
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as RestUtils, c as resources, i as SharedErrorHandler, n as DomainErrorRegistry, o as configureTranslations, r as ErrorHandler, s as ns, t as ApplicationException } from "./error-handling-DG8SfTWB.mjs";
1
+ import { a as RestUtils, c as resources, i as SharedErrorHandler, n as DomainErrorRegistry, o as configureTranslations, r as ErrorHandler, s as ns, t as ApplicationException } from "./error-handling-DSI86D3u.mjs";
2
2
  import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.mjs";
3
3
  import axios from "axios";
4
4
  import { z } from "zod";
package/dist/metro.cjs CHANGED
@@ -3838,7 +3838,7 @@ function generateModels({ resolver, data, tag }) {
3838
3838
  const schemaRef = resolver.getRefByZodSchemaName(key);
3839
3839
  zodSchemasData[key] = {
3840
3840
  code,
3841
- isCiruclar: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
3841
+ isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
3842
3842
  isEnum: isEnumZodSchema(code),
3843
3843
  schemaObj: resolver.getZodSchemaObj(key)
3844
3844
  };
@@ -3859,14 +3859,50 @@ function generateModels({ resolver, data, tag }) {
3859
3859
  tag,
3860
3860
  resolver
3861
3861
  }));
3862
- lines.push(`export const ${name} = ${zodSchema.code};`);
3863
- lines.push(`export type ${getZodSchemaInferedTypeName(name, resolver.options)} = z.infer<typeof ${name}>;`);
3862
+ const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
3863
+ if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
3864
+ const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
3865
+ lines.push(`export const ${name}${typeAnnotation} = ${zodSchema.code};`);
3866
+ if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
3864
3867
  if (zodSchema.isEnum) lines.push(`export const ${getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
3865
3868
  lines.push("");
3866
3869
  }
3867
3870
  if (resolver.options.tsNamespaces) lines.push("}");
3868
3871
  return lines.join("\n").trimEnd() + "\n";
3869
3872
  }
3873
+ function renderSchemaType(schema, resolver) {
3874
+ if (isReferenceObject(schema)) {
3875
+ const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
3876
+ return schemaName ? getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
3877
+ }
3878
+ const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
3879
+ if (composite?.length) {
3880
+ const separator = schema.allOf ? " & " : " | ";
3881
+ return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
3882
+ }
3883
+ if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
3884
+ if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
3885
+ if (schema.type === "object" || schema.properties || schema.additionalProperties) {
3886
+ const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
3887
+ const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
3888
+ const hasDefault = !isReferenceObject(property) && property.default !== void 0;
3889
+ const optional = isRequired || hasDefault ? "" : "?";
3890
+ const propertyType = renderSchemaType(property, resolver);
3891
+ const outputType = resolver.options.replaceOptionalWithNullish && optional && (isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
3892
+ return `${wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
3893
+ });
3894
+ if (schema.additionalProperties) {
3895
+ const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
3896
+ properties.push(`[key: string]: ${valueType}`);
3897
+ }
3898
+ return addNullable(schema, `{ ${properties.join("; ")} }`);
3899
+ }
3900
+ const primitiveType = schema.type;
3901
+ return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
3902
+ }
3903
+ function addNullable(schema, type) {
3904
+ return schema.nullable && type !== "null" ? `${type} | null` : type;
3905
+ }
3870
3906
  function renderModelsProxy({ resolver, data, tag }) {
3871
3907
  const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
3872
3908
  const schemaNames = getUsedSchemaNames({
package/dist/metro.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import "./generateCodeFromOpenAPIDoc-CbQ9gQss.mjs";
2
- import "./generate.runner-DnUDkoAZ.mjs";
3
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-BqOhUduF.mjs";
1
+ import "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
2
+ import "./generate.runner-C1HrS_9G.mjs";
3
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-Co_bG00_.mjs";
4
4
  import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-wLs5vqw6.mjs";
5
5
  import fs from "fs";
6
6
  import path from "path";
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-CbQ9gQss.mjs";
2
- import { t as runGenerate } from "./generate.runner-DnUDkoAZ.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
2
+ import { t as runGenerate } from "./generate.runner-C1HrS_9G.mjs";
3
3
  import path from "path";
4
4
 
5
5
  //#region src/plugins/openapi-codegen.runner.ts
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-CbQ9gQss.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-DnUDkoAZ.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-DseBECa-.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-C1HrS_9G.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.1.0-rc.7";
42
+ return "3.1.1-rc.1";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import "./generateCodeFromOpenAPIDoc-CbQ9gQss.mjs";
2
- import "./generate.runner-DnUDkoAZ.mjs";
3
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-BqOhUduF.mjs";
1
+ import "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
2
+ import "./generate.runner-C1HrS_9G.mjs";
3
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-Co_bG00_.mjs";
4
4
  import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-wLs5vqw6.mjs";
5
5
  import path from "path";
6
6
 
package/dist/zod.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ErrorHandler } from "./error-handling-BeRxGbwE.mjs";
1
+ import { a as ErrorHandler } from "./error-handling-D-mHJ60d.mjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/zod.d.ts
package/dist/zod.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as SharedErrorHandler } from "./error-handling-DG8SfTWB.mjs";
1
+ import { i as SharedErrorHandler } from "./error-handling-DSI86D3u.mjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/zod.ts
package/package.json CHANGED
@@ -139,5 +139,5 @@
139
139
  "pnpm": ">= 9"
140
140
  },
141
141
  "packageManager": "pnpm@10.4.0",
142
- "version": "3.1.0-rc.7"
142
+ "version": "3.1.1-rc.1"
143
143
  }