@kubb/adapter-oas 5.0.0 → 5.0.2

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
@@ -1745,8 +1745,13 @@ function convertArray({ schema, name, nullable, defaultValue, rawOptions, option
1745
1745
  //#region src/emit/parseSchema.ts
1746
1746
  /**
1747
1747
  * Ordered schema rule table. Order is significant: composition keywords (`$ref`, `allOf`,
1748
- * `oneOf`/`anyOf`) take precedence over `const`/`format`, which take precedence over the plain
1749
- * `type`. The first matching rule that produces a node wins. See {@link SchemaRule} for the
1748
+ * `oneOf`/`anyOf`) take precedence over `const`, which takes precedence over a genuine OAS 3.1
1749
+ * multi-type array (more than one non-`null` type), which takes precedence over `format`/`type`.
1750
+ * A multi-type array must split into its per-type members before `format` runs, otherwise
1751
+ * `format` collapses the whole schema to one type (e.g. `type: ['null', 'integer', 'string'],
1752
+ * format: 'int32'` would drop `string` and emit just `integer`); each split-off member still
1753
+ * carries the original `format` and re-enters this table, so `format` still applies per member.
1754
+ * The first matching rule that produces a node wins. See {@link SchemaRule} for the
1750
1755
  * match/convert/fall-through contract.
1751
1756
  */
1752
1757
  const schemaRules = [
@@ -1766,6 +1771,10 @@ const schemaRules = [
1766
1771
  match: ({ schema }) => "const" in schema && schema.const !== void 0,
1767
1772
  convert: convertConst
1768
1773
  },
1774
+ {
1775
+ match: ({ schema }) => Array.isArray(schema.type) && schema.type.filter((t) => t !== "null").length > 1,
1776
+ convert: convertMultiType
1777
+ },
1769
1778
  {
1770
1779
  match: ({ schema, options }) => {
1771
1780
  if (!schema.format) return false;
@@ -1778,10 +1787,6 @@ const schemaRules = [
1778
1787
  match: ({ schema }) => isBinary(schema),
1779
1788
  convert: convertBinary
1780
1789
  },
1781
- {
1782
- match: ({ schema }) => Array.isArray(schema.type) && schema.type.filter((t) => t !== "null").length > 1,
1783
- convert: convertMultiType
1784
- },
1785
1790
  {
1786
1791
  match: ({ schema, type }) => !type && (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern !== void 0),
1787
1792
  convert: convertString
@@ -2151,7 +2156,7 @@ function createSchemaParser(ctx) {
2151
2156
  name,
2152
2157
  nullable,
2153
2158
  defaultValue: schema.default === null && nullable ? void 0 : schema.default,
2154
- type: Array.isArray(schema.type) ? schema.type[0] : schema.type,
2159
+ type: Array.isArray(schema.type) ? schema.type.find((t) => t !== "null") ?? schema.type[0] : schema.type,
2155
2160
  rawOptions,
2156
2161
  options,
2157
2162
  parse: parseSchema,