@povio/openapi-codegen-cli 3.0.0-rc.10 → 3.0.0-rc.12

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 { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-BOWjt2I0.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-oWuHuxoy.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
@@ -2189,13 +2189,16 @@ function resolveEndpointZodSchema({ resolver, schema, meta, tag, fallbackName, c
2189
2189
  fallbackName,
2190
2190
  resolver,
2191
2191
  tag
2192
- }) : `${resolveZodSchemaName({
2193
- schema: schemaObject,
2194
- zodSchema,
2195
- fallbackName,
2196
- resolver,
2197
- tag
2198
- })}${zodChain}`;
2192
+ }) : (() => {
2193
+ const name = resolveZodSchemaName({
2194
+ schema: schemaObject,
2195
+ zodSchema,
2196
+ fallbackName,
2197
+ resolver,
2198
+ tag
2199
+ });
2200
+ return isNamedZodSchema(name) ? name : name + zodChain;
2201
+ })();
2199
2202
  entries.set(metaKey, resolved);
2200
2203
  return resolved;
2201
2204
  }
@@ -2406,7 +2409,7 @@ function getEndpointsFromOpenAPIDoc(resolver) {
2406
2409
  const domainStr = rawSchema["x-domain-error-domain"];
2407
2410
  const domainName = rawSchema["x-domain-error-name"];
2408
2411
  const codeEnumArr = ((rawSchema?.properties)?.code)?.enum;
2409
- const domainCode = Array.isArray(codeEnumArr) && codeEnumArr.length === 1 && typeof codeEnumArr[0] === "number" ? codeEnumArr[0] : void 0;
2412
+ const domainCode = Array.isArray(codeEnumArr) && codeEnumArr.length === 1 && (typeof codeEnumArr[0] === "number" || typeof codeEnumArr[0] === "string") ? codeEnumArr[0] : void 0;
2410
2413
  endpoint.errors.push({
2411
2414
  zodSchema: responseZodSchema,
2412
2415
  status,
@@ -4804,6 +4807,7 @@ export const ${APP_REST_CLIENT_NAME} = new RestClient({
4804
4807
  function domainToPascalCase(domain) {
4805
4808
  return domain.split(/[-_]/).map(capitalize).join("");
4806
4809
  }
4810
+ const VALID_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
4807
4811
  function generateDomainErrors({ data }) {
4808
4812
  const byDomain = /* @__PURE__ */ new Map();
4809
4813
  for (const { endpoints } of data.values()) for (const endpoint of endpoints) for (const error of endpoint.errors) {
@@ -4821,8 +4825,16 @@ function generateDomainErrors({ data }) {
4821
4825
  const blocks = [];
4822
4826
  for (const [domain, codes] of [...byDomain.entries()].sort(([a], [b]) => a.localeCompare(b))) {
4823
4827
  const pascalName = domainToPascalCase(domain);
4824
- const entries = [...codes.values()].sort((a, b) => a.code - b.code).map(({ code, name, description }) => {
4825
- return `${description ? ` /** ${description} */\n ` : " "}${name ?? `ERROR_${code}`}: ${code}`;
4828
+ const entries = [...codes.values()].sort((a, b) => {
4829
+ if (typeof a.code === "number" && typeof b.code === "number") return a.code - b.code;
4830
+ const sa = String(a.code);
4831
+ const sb = String(b.code);
4832
+ return sa < sb ? -1 : sa > sb ? 1 : 0;
4833
+ }).map(({ code, name, description }) => {
4834
+ const comment = description ? ` /** ${description} */\n ` : " ";
4835
+ const key = name ?? (typeof code === "string" ? code : `ERROR_${code}`);
4836
+ if (!VALID_IDENTIFIER.test(key)) throw new Error(`Domain error code "${code}" produces an invalid identifier "${key}". Use the 'name' field on @ApiDomainErrorResponse to provide a valid identifier.`);
4837
+ return `${comment}${key}: ${typeof code === "string" ? `"${code}"` : String(code)}`;
4826
4838
  }).join(",\n");
4827
4839
  blocks.push(`export const ${pascalName}DomainErrors = {\n${entries},\n} as const;`);
4828
4840
  blocks.push(`export type ${pascalName}DomainErrorCode = (typeof ${pascalName}DomainErrors)[keyof typeof ${pascalName}DomainErrors];`);
@@ -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-BOWjt2I0.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-oWuHuxoy.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 { 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-BOWjt2I0.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-C-MWypBE.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-oWuHuxoy.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-CmQsbF8c.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.10";
42
+ return "3.0.0-rc.12";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-BOWjt2I0.mjs";
2
- import { t as runGenerate } from "./generate.runner-C-MWypBE.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-oWuHuxoy.mjs";
2
+ import { t as runGenerate } from "./generate.runner-CmQsbF8c.mjs";
3
3
  import path from "path";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "3.0.0-rc.10",
3
+ "version": "3.0.0-rc.12",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",