@orval/core 7.9.0 → 7.10.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.
package/dist/index.js CHANGED
@@ -6594,6 +6594,7 @@ function createScanner(text, ignoreTrivia) {
6594
6594
  return token = 14;
6595
6595
  }
6596
6596
  switch (code) {
6597
+ // tokens: []{}:,
6597
6598
  case 123:
6598
6599
  pos++;
6599
6600
  return token = 1;
@@ -6612,10 +6613,12 @@ function createScanner(text, ignoreTrivia) {
6612
6613
  case 44:
6613
6614
  pos++;
6614
6615
  return token = 5;
6616
+ // strings
6615
6617
  case 34:
6616
6618
  pos++;
6617
6619
  value = scanString();
6618
6620
  return token = 10;
6621
+ // comments
6619
6622
  case 47:
6620
6623
  var start = pos - 1;
6621
6624
  if (text.charCodeAt(pos + 1) === 47) {
@@ -6659,12 +6662,16 @@ function createScanner(text, ignoreTrivia) {
6659
6662
  value += String.fromCharCode(code);
6660
6663
  pos++;
6661
6664
  return token = 16;
6665
+ // numbers
6662
6666
  case 45:
6663
6667
  value += String.fromCharCode(code);
6664
6668
  pos++;
6665
6669
  if (pos === len || !isDigit(text.charCodeAt(pos))) {
6666
6670
  return token = 16;
6667
6671
  }
6672
+ // found a minus, followed by a number so
6673
+ // we fall through to proceed with scanning
6674
+ // numbers
6668
6675
  case 48:
6669
6676
  case 49:
6670
6677
  case 50:
@@ -6677,6 +6684,7 @@ function createScanner(text, ignoreTrivia) {
6677
6684
  case 57:
6678
6685
  value += scanNumber();
6679
6686
  return token = 11;
6687
+ // literals and unknown symbols
6680
6688
  default:
6681
6689
  while (pos < len && isUnknownContentCharacter(code)) {
6682
6690
  pos++;
@@ -24963,6 +24971,7 @@ var require_immer_cjs_development = __commonJS({
24963
24971
  switch (type) {
24964
24972
  case 2:
24965
24973
  return base2.set(key, value);
24974
+ /* istanbul ignore next */
24966
24975
  case 3:
24967
24976
  die(16);
24968
24977
  default:
@@ -27628,6 +27637,7 @@ var require_URI = __commonJS({
27628
27637
  switch (getType(value)) {
27629
27638
  case "Undefined":
27630
27639
  return name in data;
27640
+ // data[name] !== undefined;
27631
27641
  case "Boolean":
27632
27642
  var _booly = Boolean(isArray(data[name]) ? data[name].length : data[name]);
27633
27643
  return value === _booly;
@@ -27649,6 +27659,7 @@ var require_URI = __commonJS({
27649
27659
  return arrayContains(data[name], value);
27650
27660
  case "Number":
27651
27661
  value = String(value);
27662
+ /* falls through */
27652
27663
  case "String":
27653
27664
  if (!isArray(data[name])) {
27654
27665
  return data[name] === value;
@@ -27942,6 +27953,7 @@ var require_URI = __commonJS({
27942
27953
  return relative;
27943
27954
  case "absolute":
27944
27955
  return !relative;
27956
+ // hostname identification
27945
27957
  case "domain":
27946
27958
  case "name":
27947
27959
  return name;
@@ -32546,6 +32558,7 @@ var require_index_node_cjs = __commonJS({
32546
32558
  addType = true;
32547
32559
  }
32548
32560
  break;
32561
+ /* c8 ignore next 2 */
32549
32562
  default:
32550
32563
  throw new TypeError("Unknown value type " + valueType);
32551
32564
  }
@@ -41722,6 +41735,7 @@ var require_minimatch = __commonJS({
41722
41735
  continue;
41723
41736
  }
41724
41737
  switch (c2) {
41738
+ /* istanbul ignore next */
41725
41739
  case "/": {
41726
41740
  return false;
41727
41741
  }
@@ -41729,6 +41743,8 @@ var require_minimatch = __commonJS({
41729
41743
  clearStateChar();
41730
41744
  escaping = true;
41731
41745
  continue;
41746
+ // the various stateChar values
41747
+ // for the "extglob" stuff.
41732
41748
  case "?":
41733
41749
  case "*":
41734
41750
  case "+":
@@ -41789,6 +41805,7 @@ var require_minimatch = __commonJS({
41789
41805
  clearStateChar();
41790
41806
  re2 += "|";
41791
41807
  continue;
41808
+ // these are mostly the same in regexp and glob
41792
41809
  case "[":
41793
41810
  clearStateChar();
41794
41811
  if (inClass) {
@@ -44302,7 +44319,7 @@ var require_get_intrinsic = __commonJS({
44302
44319
  if (!allowMissing) {
44303
44320
  throw new $TypeError("base intrinsic for " + name + " exists, but the property is not available.");
44304
44321
  }
44305
- return void 0;
44322
+ return void undefined2;
44306
44323
  }
44307
44324
  if ($gOPD && i3 + 1 >= parts.length) {
44308
44325
  var desc = $gOPD(value, part);
@@ -48109,8 +48126,8 @@ var require_dist10 = __commonJS({
48109
48126
  });
48110
48127
 
48111
48128
  // src/index.ts
48112
- var src_exports = {};
48113
- __export(src_exports, {
48129
+ var index_exports = {};
48130
+ __export(index_exports, {
48114
48131
  BODY_TYPE_NAME: () => BODY_TYPE_NAME,
48115
48132
  EnumGeneration: () => EnumGeneration,
48116
48133
  FormDataArrayHandling: () => FormDataArrayHandling,
@@ -48167,6 +48184,7 @@ __export(src_exports, {
48167
48184
  getArray: () => getArray,
48168
48185
  getBody: () => getBody,
48169
48186
  getEnum: () => getEnum,
48187
+ getEnumDescriptions: () => getEnumDescriptions,
48170
48188
  getEnumImplementation: () => getEnumImplementation,
48171
48189
  getEnumNames: () => getEnumNames,
48172
48190
  getExtension: () => getExtension,
@@ -48212,6 +48230,7 @@ __export(src_exports, {
48212
48230
  jsDoc: () => jsDoc,
48213
48231
  jsStringEscape: () => jsStringEscape,
48214
48232
  kebab: () => kebab,
48233
+ keyValuePairsToJsDoc: () => keyValuePairsToJsDoc,
48215
48234
  loadFile: () => loadFile,
48216
48235
  log: () => log,
48217
48236
  logError: () => logError,
@@ -48242,7 +48261,7 @@ __export(src_exports, {
48242
48261
  writeSplitTagsMode: () => writeSplitTagsMode,
48243
48262
  writeTagsMode: () => writeTagsMode
48244
48263
  });
48245
- module.exports = __toCommonJS(src_exports);
48264
+ module.exports = __toCommonJS(index_exports);
48246
48265
 
48247
48266
  // src/types.ts
48248
48267
  var PropertySortOrder = {
@@ -49071,21 +49090,28 @@ var compareVersions = (firstVersion, secondVersions, operator = ">=") => {
49071
49090
  var search = "\\*/";
49072
49091
  var replacement = "*\\/";
49073
49092
  var regex = new RegExp(search, "g");
49074
- function jsDoc({
49075
- description,
49076
- deprecated,
49077
- summary,
49078
- minLength,
49079
- maxLength,
49080
- minimum,
49081
- maximum,
49082
- exclusiveMinimum,
49083
- exclusiveMaximum,
49084
- minItems,
49085
- maxItems,
49086
- nullable,
49087
- pattern
49088
- }, tryOneLine = false) {
49093
+ function jsDoc(schema, tryOneLine = false, context) {
49094
+ if (context?.output?.override?.jsDoc) {
49095
+ const { filter: filter2 } = context.output.override.jsDoc;
49096
+ if (filter2) {
49097
+ return keyValuePairsToJsDoc(filter2(schema));
49098
+ }
49099
+ }
49100
+ const {
49101
+ description,
49102
+ deprecated,
49103
+ summary,
49104
+ minLength,
49105
+ maxLength,
49106
+ minimum,
49107
+ maximum,
49108
+ exclusiveMinimum,
49109
+ exclusiveMaximum,
49110
+ minItems,
49111
+ maxItems,
49112
+ nullable,
49113
+ pattern
49114
+ } = schema;
49089
49115
  const lines = (Array.isArray(description) ? description.filter((d2) => !d2.includes("eslint-disable")) : [description || ""]).map((line) => line.replace(regex, replacement));
49090
49116
  const count2 = [
49091
49117
  description,
@@ -49157,6 +49183,16 @@ ${tryOneLine ? " " : ""} *`;
49157
49183
  doc += "*/\n";
49158
49184
  return doc;
49159
49185
  }
49186
+ function keyValuePairsToJsDoc(keyValues) {
49187
+ if (!keyValues.length) return "";
49188
+ let doc = "/**\n";
49189
+ keyValues.forEach(({ key, value }) => {
49190
+ doc += ` * @${key} ${value}
49191
+ `;
49192
+ });
49193
+ doc += " */\n";
49194
+ return doc;
49195
+ }
49160
49196
 
49161
49197
  // src/utils/dynamic-import.ts
49162
49198
  var import_url = require("url");
@@ -49373,6 +49409,7 @@ var jsStringEscape = (input) => input.replace(/["'\\\n\r\u2028\u2029]/g, (charac
49373
49409
  case "'":
49374
49410
  case "\\":
49375
49411
  return "\\" + character;
49412
+ // Four possible LineTerminator characters need to be escaped:
49376
49413
  case "\n":
49377
49414
  return "\\n";
49378
49415
  case "\r":
@@ -49431,38 +49468,42 @@ var getIsBodyVerb = (verb) => VERBS_WITH_BODY.includes(verb);
49431
49468
  var getEnumNames = (schemaObject) => {
49432
49469
  return schemaObject?.["x-enumNames"] || schemaObject?.["x-enumnames"] || schemaObject?.["x-enum-varnames"];
49433
49470
  };
49434
- var getEnum = (value, enumName, names, enumGenerationType) => {
49471
+ var getEnumDescriptions = (schemaObject) => {
49472
+ return schemaObject?.["x-enumDescriptions"] || schemaObject?.["x-enumdescriptions"] || schemaObject?.["x-enum-descriptions"];
49473
+ };
49474
+ var getEnum = (value, enumName, names, enumGenerationType, descriptions) => {
49435
49475
  if (enumGenerationType === EnumGeneration.CONST)
49436
- return getTypeConstEnum(value, enumName, names);
49476
+ return getTypeConstEnum(value, enumName, names, descriptions);
49437
49477
  if (enumGenerationType === EnumGeneration.ENUM)
49438
49478
  return getNativeEnum(value, enumName, names);
49439
49479
  if (enumGenerationType === EnumGeneration.UNION)
49440
49480
  return getUnion(value, enumName);
49441
49481
  throw new Error(`Invalid enumGenerationType: ${enumGenerationType}`);
49442
49482
  };
49443
- var getTypeConstEnum = (value, enumName, names) => {
49483
+ var getTypeConstEnum = (value, enumName, names, descriptions) => {
49444
49484
  let enumValue = `export type ${enumName} = typeof ${enumName}[keyof typeof ${enumName}]`;
49445
49485
  if (value.endsWith(" | null")) {
49446
49486
  value = value.replace(" | null", "");
49447
49487
  enumValue += " | null";
49448
49488
  }
49449
49489
  enumValue += ";\n";
49450
- const implementation = getEnumImplementation(value, names);
49451
- enumValue += `
49452
-
49453
- `;
49490
+ const implementation = getEnumImplementation(value, names, descriptions);
49491
+ enumValue += "\n\n";
49454
49492
  enumValue += "// eslint-disable-next-line @typescript-eslint/no-redeclare\n";
49455
49493
  enumValue += `export const ${enumName} = {
49456
49494
  ${implementation}} as const;
49457
49495
  `;
49458
49496
  return enumValue;
49459
49497
  };
49460
- var getEnumImplementation = (value, names) => {
49498
+ var getEnumImplementation = (value, names, descriptions) => {
49461
49499
  if (value === "") return "";
49462
49500
  return [...new Set(value.split(" | "))].reduce((acc, val, index3) => {
49463
49501
  const name = names?.[index3];
49502
+ const description = descriptions?.[index3];
49503
+ const comment = description ? ` /** ${description} */
49504
+ ` : "";
49464
49505
  if (name) {
49465
- return acc + ` ${import_esutils2.keyword.isIdentifierNameES5(name) ? name : `'${name}'`}: ${val},
49506
+ return acc + comment + ` ${import_esutils2.keyword.isIdentifierNameES5(name) ? name : `'${name}'`}: ${val},
49466
49507
  `;
49467
49508
  }
49468
49509
  let key = val.startsWith("'") ? val.slice(1, -1) : val;
@@ -49478,7 +49519,7 @@ var getEnumImplementation = (value, names) => {
49478
49519
  special: true
49479
49520
  });
49480
49521
  }
49481
- return acc + ` ${import_esutils2.keyword.isIdentifierNameES5(key) ? key : `'${key}'`}: ${val},
49522
+ return acc + comment + ` ${import_esutils2.keyword.isIdentifierNameES5(key) ? key : `'${key}'`}: ${val},
49482
49523
  `;
49483
49524
  }, "");
49484
49525
  };
@@ -49767,7 +49808,8 @@ var resolveObjectOriginal = ({
49767
49808
  resolvedValue.value,
49768
49809
  propName,
49769
49810
  getEnumNames(resolvedValue.originalSchema),
49770
- context.output.override.enumGenerationType
49811
+ context.output.override.enumGenerationType,
49812
+ getEnumDescriptions(resolvedValue.originalSchema)
49771
49813
  );
49772
49814
  return {
49773
49815
  value: propName,
@@ -50163,6 +50205,9 @@ var resolveSchemaPropertiesToFormData = ({
50163
50205
  const formDataValues = Object.entries(schema.properties ?? {}).reduce(
50164
50206
  (acc, [key, value]) => {
50165
50207
  const { schema: property } = resolveRef(value, context);
50208
+ if (property.readOnly) {
50209
+ return acc;
50210
+ }
50166
50211
  let formDataValue = "";
50167
50212
  const formattedKeyPrefix = !isRequestBodyOptional ? "" : !import_esutils3.keyword.isIdentifierNameES5(key) ? "?." : "?";
50168
50213
  const formattedKey = !import_esutils3.keyword.isIdentifierNameES5(key) ? `['${key}']` : `.${key}`;
@@ -50423,7 +50468,7 @@ var getObject = ({
50423
50468
  if (!index3) {
50424
50469
  acc.value += "{";
50425
50470
  }
50426
- const doc = jsDoc(schema, true);
50471
+ const doc = jsDoc(schema, true, context);
50427
50472
  acc.hasReadonlyProps ||= isReadOnly || false;
50428
50473
  acc.imports.push(...resolvedValue.imports);
50429
50474
  acc.value += `
@@ -50857,7 +50902,8 @@ var getCombineEnumValue = ({
50857
50902
  return `...${e3},`;
50858
50903
  }
50859
50904
  const names = getEnumNames(originalSchema[i3]);
50860
- return getEnumImplementation(e3, names);
50905
+ const descriptions = getEnumDescriptions(originalSchema[i3]);
50906
+ return getEnumImplementation(e3, names, descriptions);
50861
50907
  }).join("");
50862
50908
  return `{${enums}} as const`;
50863
50909
  };
@@ -51044,10 +51090,10 @@ var getProps = ({
51044
51090
  };
51045
51091
  const queryParamsProp = {
51046
51092
  name: "params",
51047
- definition: `params${queryParams?.isOptional ? "?" : ""}: ${queryParams?.schema.name}`,
51048
- implementation: `params${queryParams?.isOptional ? "?" : ""}: ${queryParams?.schema.name}`,
51093
+ definition: `params${queryParams?.isOptional || context.output.allParamsOptional ? "?" : ""}: ${queryParams?.schema.name}`,
51094
+ implementation: `params${queryParams?.isOptional || context.output.allParamsOptional ? "?" : ""}: ${queryParams?.schema.name}`,
51049
51095
  default: false,
51050
- required: !isUndefined(queryParams?.isOptional) ? !queryParams?.isOptional : false,
51096
+ required: !isUndefined(queryParams?.isOptional) ? !queryParams?.isOptional && !context.output.allParamsOptional : !context.output.allParamsOptional,
51051
51097
  type: GetterPropType.QUERY_PARAM
51052
51098
  };
51053
51099
  const headersProp = {
@@ -51125,7 +51171,14 @@ var getQueryParamsTypes = (queryParams, operationName, context) => {
51125
51171
  name: queryName
51126
51172
  });
51127
51173
  const key = getKey(name);
51128
- const doc = jsDoc(parameter);
51174
+ const doc = jsDoc(
51175
+ {
51176
+ description: parameter.description,
51177
+ ...schema
51178
+ },
51179
+ void 0,
51180
+ context
51181
+ );
51129
51182
  if (parameterImports.length) {
51130
51183
  return {
51131
51184
  definition: `${doc}${key}${!required || schema.default ? "?" : ""}: ${parameterImports[0].name};`,
@@ -51140,7 +51193,8 @@ var getQueryParamsTypes = (queryParams, operationName, context) => {
51140
51193
  resolvedValue.value,
51141
51194
  enumName,
51142
51195
  getEnumNames(resolvedValue.originalSchema),
51143
- context.output.override.enumGenerationType
51196
+ context.output.override.enumGenerationType,
51197
+ getEnumDescriptions(resolvedValue.originalSchema)
51144
51198
  );
51145
51199
  return {
51146
51200
  definition: `${doc}${key}${!required || schema.default ? "?" : ""}: ${enumName};`,
@@ -52106,7 +52160,7 @@ var generateInterface = ({
52106
52160
  }
52107
52161
  if (scalar.type === "object" && !context?.output.override?.useTypeOverInterfaces) {
52108
52162
  if (scalar.type === "object" && schema.properties && Object.values(schema.properties).length > 0 && Object.values(schema.properties).every((item) => "const" in item)) {
52109
- const mappedScalarValue = scalar.value.replaceAll(";", ",");
52163
+ const mappedScalarValue = scalar.value.replaceAll(";", ",").replaceAll("?:", ":");
52110
52164
  model += `export const ${name}Value = ${mappedScalarValue} as const;
52111
52165
  export type ${name} = typeof ${name}Value;
52112
52166
  `;
@@ -52181,7 +52235,8 @@ var generateSchemasDefinition = (schemas = {}, context, suffix, filters) => {
52181
52235
  resolvedValue.value,
52182
52236
  schemaName,
52183
52237
  getEnumNames(resolvedValue.originalSchema),
52184
- context.output.override.enumGenerationType
52238
+ context.output.override.enumGenerationType,
52239
+ getEnumDescriptions(resolvedValue.originalSchema)
52185
52240
  );
52186
52241
  } else if (schemaName === resolvedValue.value && resolvedValue.isRef) {
52187
52242
  const { schema: referredSchema } = resolveRef(schema, context);
@@ -53355,6 +53410,7 @@ var writeTagsMode = async ({
53355
53410
  getArray,
53356
53411
  getBody,
53357
53412
  getEnum,
53413
+ getEnumDescriptions,
53358
53414
  getEnumImplementation,
53359
53415
  getEnumNames,
53360
53416
  getExtension,
@@ -53400,6 +53456,7 @@ var writeTagsMode = async ({
53400
53456
  jsDoc,
53401
53457
  jsStringEscape,
53402
53458
  kebab,
53459
+ keyValuePairsToJsDoc,
53403
53460
  loadFile,
53404
53461
  log,
53405
53462
  logError,