@kubb/adapter-oas 5.14.1 → 5.14.3

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
@@ -20,7 +20,7 @@ var compatibility = {
20
20
  };
21
21
  //#endregion
22
22
  //#region package.json
23
- var version = "5.14.1";
23
+ var version = "5.14.3";
24
24
  //#endregion
25
25
  //#region src/constants.ts
26
26
  /**
@@ -1291,12 +1291,21 @@ function getParameters({ operation, refs }) {
1291
1291
  for (const entry of [...pathLevelParams, ...operationParams]) if (entry.param.name && entry.param.in) paramMap.set(`${entry.param.in}:${entry.param.name}`, entry);
1292
1292
  return Array.from(paramMap.values());
1293
1293
  }
1294
- /** The `encoding` of a media type, reduced to the entries that set a field Kubb carries. */
1294
+ const PARAMETER_STYLES = /* @__PURE__ */ new Set([
1295
+ "matrix",
1296
+ "label",
1297
+ "form",
1298
+ "simple",
1299
+ "spaceDelimited",
1300
+ "pipeDelimited",
1301
+ "deepObject"
1302
+ ]);
1303
+ /** The `encoding` of a media type, reduced to the entries that set a field Kubb carries. A `style` outside the OpenAPI set is dropped. */
1295
1304
  function getEncoding(encoding) {
1296
1305
  const entries = Object.entries(encoding ?? {}).flatMap(([property, { contentType, style, explode, allowReserved }]) => {
1297
1306
  const node = {
1298
1307
  ...contentType !== void 0 ? { contentType } : {},
1299
- ...style !== void 0 ? { style } : {},
1308
+ ...style !== void 0 && PARAMETER_STYLES.has(style) ? { style } : {},
1300
1309
  ...explode !== void 0 ? { explode } : {},
1301
1310
  ...allowReserved !== void 0 ? { allowReserved } : {}
1302
1311
  };
@@ -1358,7 +1367,7 @@ function parseParameter({ param, pointer, parentName, options, parseSchema }) {
1358
1367
  name: schemaName
1359
1368
  }) : ast.factory.createSchema({ type: options.unknownType });
1360
1369
  if (rawSchema) scanSchema(schema, contentType ? `${pointer}/content/${escapePointerToken(contentType)}/schema` : `${pointer}/schema`);
1361
- const style = param.style;
1370
+ const style = param.style !== void 0 && PARAMETER_STYLES.has(param.style) ? param.style : void 0;
1362
1371
  const explode = param.explode;
1363
1372
  const allowReserved = param.allowReserved;
1364
1373
  return ast.factory.createParameter({
@@ -1894,7 +1903,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1894
1903
  nullable,
1895
1904
  defaultValue
1896
1905
  };
1897
- if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: "unknown" });
1906
+ if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: ast.schemaTypes.unknown });
1898
1907
  if (refPath && !refPath.startsWith("#/components/schemas/") && resolvedSchema) return ast.factory.createSchema({
1899
1908
  ...resolvedSchema,
1900
1909
  title: schema.title ?? resolvedSchema.title,
@@ -1908,7 +1917,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1908
1917
  });
1909
1918
  const targetName = renames?.get(schema.$ref);
1910
1919
  return createNode(ctx, {
1911
- type: "ref",
1920
+ type: ast.schemaTypes.ref,
1912
1921
  name: extractRefName(schema.$ref),
1913
1922
  ref: schema.$ref,
1914
1923
  ...targetName ? { targetName } : {},
@@ -1920,7 +1929,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1920
1929
  const { not, ...rest } = schema;
1921
1930
  const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
1922
1931
  const notNode = ast.factory.createSchema({
1923
- type: "not",
1932
+ type: ast.schemaTypes.not,
1924
1933
  members: [parse({ schema: subschema })]
1925
1934
  });
1926
1935
  return createNode({
@@ -1929,7 +1938,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1929
1938
  nullable,
1930
1939
  defaultValue
1931
1940
  }, {
1932
- type: "intersection",
1941
+ type: ast.schemaTypes.intersection,
1933
1942
  members: [parse({
1934
1943
  schema: rest,
1935
1944
  name
@@ -2049,7 +2058,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
2049
2058
  nullable,
2050
2059
  defaultValue
2051
2060
  }, {
2052
- type: "intersection",
2061
+ type: ast.schemaTypes.intersection,
2053
2062
  members: [...mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))]
2054
2063
  });
2055
2064
  }
@@ -2075,7 +2084,8 @@ function convertUnion(context) {
2075
2084
  schema: memberBaseSchema,
2076
2085
  name
2077
2086
  }) : void 0;
2078
- if (sharedPropertiesNode || discriminator) {
2087
+ const missingRequired = (Array.isArray(schema.required) ? schema.required : []).filter((key) => !Object.hasOwn(schema.properties ?? {}, key));
2088
+ if (sharedPropertiesNode || discriminator || missingRequired.length) {
2079
2089
  const members = narrowUnionMembers({
2080
2090
  unionMembers,
2081
2091
  discriminator,
@@ -2090,15 +2100,25 @@ function convertUnion(context) {
2090
2100
  refs
2091
2101
  });
2092
2102
  const unionNode = createNode(ctx, {
2093
- type: "union",
2103
+ type: ast.schemaTypes.union,
2094
2104
  strategy,
2095
2105
  members,
2096
2106
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
2097
2107
  });
2098
- if (!sharedPropertiesNode) return unionNode;
2108
+ const requiredProperties = missingRequired.map((name) => ast.factory.createProperty({
2109
+ name,
2110
+ required: true,
2111
+ schema: ast.factory.createSchema({ type: ast.schemaTypes.unknown })
2112
+ }));
2113
+ const siblings = sharedPropertiesNode ? [sharedPropertiesNode] : [];
2114
+ if (requiredProperties.length) siblings.push(ast.factory.createSchema({
2115
+ type: ast.schemaTypes.object,
2116
+ properties: requiredProperties
2117
+ }));
2118
+ if (!siblings.length) return unionNode;
2099
2119
  return createNode(ctx, {
2100
- type: "intersection",
2101
- members: [unionNode, sharedPropertiesNode]
2120
+ type: ast.schemaTypes.intersection,
2121
+ members: [unionNode, ...siblings]
2102
2122
  });
2103
2123
  }
2104
2124
  const members = unionMembers.map((s) => parse({
@@ -2106,7 +2126,7 @@ function convertUnion(context) {
2106
2126
  name
2107
2127
  }));
2108
2128
  const unionNode = createNode(ctx, {
2109
- type: "union",
2129
+ type: ast.schemaTypes.union,
2110
2130
  strategy,
2111
2131
  members,
2112
2132
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
@@ -2128,7 +2148,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
2128
2148
  nullable: types.includes("null") || nullable || void 0,
2129
2149
  defaultValue
2130
2150
  }, {
2131
- type: "union",
2151
+ type: ast.schemaTypes.union,
2132
2152
  members: nonNullTypes.map((t) => {
2133
2153
  return parse({
2134
2154
  schema: {
@@ -2905,9 +2925,13 @@ const adapterOas = defineExtension({
2905
2925
  }));
2906
2926
  const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
2907
2927
  if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
2928
+ const aliasTargetOf = (name) => {
2929
+ const node = refAliasMap.get(name);
2930
+ return node?.ref ? ast.refName(node.ref) : node?.name;
2931
+ };
2908
2932
  function isAliasCycle(name) {
2909
2933
  const seen = /* @__PURE__ */ new Set([name]);
2910
- for (let next = refAliasMap.get(name)?.name; next; next = refAliasMap.get(next)?.name) {
2934
+ for (let next = aliasTargetOf(name); next; next = aliasTargetOf(next)) {
2911
2935
  if (next === name) return true;
2912
2936
  if (seen.has(next)) return false;
2913
2937
  seen.add(next);