@kubb/adapter-oas 5.0.6 → 5.1.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.cjs CHANGED
@@ -1000,21 +1000,31 @@ function getPrimitiveType(type) {
1000
1000
  return "string";
1001
1001
  }
1002
1002
  /**
1003
+ * Resolves the `dateType` option down to the value for one format. The scalar form of
1004
+ * `dateType` applies to every format; the object form picks `dateTime`/`date`/`time`
1005
+ * individually and defaults an omitted key to `'string'`.
1006
+ */
1007
+ function resolveDateTypeValue(dateType, format) {
1008
+ if (typeof dateType !== "object" || dateType === null) return dateType;
1009
+ return dateType[format === "date-time" ? "dateTime" : format] ?? "string";
1010
+ }
1011
+ /**
1003
1012
  * Resolves the AST type descriptor for a date/time format, honoring the `dateType` option.
1004
- * Returns `null` when `dateType: false`, so the format falls through to `string`.
1013
+ * Returns `null` when the resolved value is `false`, so the format falls through to `string`.
1005
1014
  */
1006
1015
  function getDateType(options, format) {
1007
- if (!options.dateType) return null;
1016
+ const value = resolveDateTypeValue(options.dateType, format);
1017
+ if (!value) return null;
1008
1018
  if (format === "date-time") {
1009
- if (options.dateType === "date") return {
1019
+ if (value === "date") return {
1010
1020
  type: "date",
1011
1021
  representation: "date"
1012
1022
  };
1013
- if (options.dateType === "stringOffset") return {
1023
+ if (value === "stringOffset") return {
1014
1024
  type: "datetime",
1015
1025
  offset: true
1016
1026
  };
1017
- if (options.dateType === "stringLocal") return {
1027
+ if (value === "stringLocal") return {
1018
1028
  type: "datetime",
1019
1029
  local: true
1020
1030
  };
@@ -1025,11 +1035,11 @@ function getDateType(options, format) {
1025
1035
  }
1026
1036
  if (format === "date") return {
1027
1037
  type: "date",
1028
- representation: options.dateType === "date" ? "date" : "string"
1038
+ representation: value === "date" ? "date" : "string"
1029
1039
  };
1030
1040
  return {
1031
1041
  type: "time",
1032
- representation: options.dateType === "date" ? "date" : "string"
1042
+ representation: value === "date" ? "date" : "string"
1033
1043
  };
1034
1044
  }
1035
1045
  /**
@@ -1823,7 +1833,7 @@ const schemaRules = [
1823
1833
  {
1824
1834
  match: ({ schema, options }) => {
1825
1835
  if (!schema.format) return false;
1826
- if (schema.format === "date-time" || schema.format === "date" || schema.format === "time") return options.dateType !== false;
1836
+ if (schema.format === "date-time" || schema.format === "date" || schema.format === "time") return resolveDateTypeValue(options.dateType, schema.format) !== false;
1827
1837
  return isHandledFormat(schema.format);
1828
1838
  },
1829
1839
  convert: convertFormat