@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.cjs CHANGED
@@ -36,7 +36,7 @@ var compatibility = {
36
36
  };
37
37
  //#endregion
38
38
  //#region package.json
39
- var version = "5.14.1";
39
+ var version = "5.14.3";
40
40
  //#endregion
41
41
  //#region src/constants.ts
42
42
  /**
@@ -1307,12 +1307,21 @@ function getParameters({ operation, refs }) {
1307
1307
  for (const entry of [...pathLevelParams, ...operationParams]) if (entry.param.name && entry.param.in) paramMap.set(`${entry.param.in}:${entry.param.name}`, entry);
1308
1308
  return Array.from(paramMap.values());
1309
1309
  }
1310
- /** The `encoding` of a media type, reduced to the entries that set a field Kubb carries. */
1310
+ const PARAMETER_STYLES = /* @__PURE__ */ new Set([
1311
+ "matrix",
1312
+ "label",
1313
+ "form",
1314
+ "simple",
1315
+ "spaceDelimited",
1316
+ "pipeDelimited",
1317
+ "deepObject"
1318
+ ]);
1319
+ /** The `encoding` of a media type, reduced to the entries that set a field Kubb carries. A `style` outside the OpenAPI set is dropped. */
1311
1320
  function getEncoding(encoding) {
1312
1321
  const entries = Object.entries(encoding ?? {}).flatMap(([property, { contentType, style, explode, allowReserved }]) => {
1313
1322
  const node = {
1314
1323
  ...contentType !== void 0 ? { contentType } : {},
1315
- ...style !== void 0 ? { style } : {},
1324
+ ...style !== void 0 && PARAMETER_STYLES.has(style) ? { style } : {},
1316
1325
  ...explode !== void 0 ? { explode } : {},
1317
1326
  ...allowReserved !== void 0 ? { allowReserved } : {}
1318
1327
  };
@@ -1374,7 +1383,7 @@ function parseParameter({ param, pointer, parentName, options, parseSchema }) {
1374
1383
  name: schemaName
1375
1384
  }) : _kubb_kit.ast.factory.createSchema({ type: options.unknownType });
1376
1385
  if (rawSchema) scanSchema(schema, contentType ? `${pointer}/content/${escapePointerToken(contentType)}/schema` : `${pointer}/schema`);
1377
- const style = param.style;
1386
+ const style = param.style !== void 0 && PARAMETER_STYLES.has(param.style) ? param.style : void 0;
1378
1387
  const explode = param.explode;
1379
1388
  const allowReserved = param.allowReserved;
1380
1389
  return _kubb_kit.ast.factory.createParameter({
@@ -1910,7 +1919,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1910
1919
  nullable,
1911
1920
  defaultValue
1912
1921
  };
1913
- if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: "unknown" });
1922
+ if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: _kubb_kit.ast.schemaTypes.unknown });
1914
1923
  if (refPath && !refPath.startsWith("#/components/schemas/") && resolvedSchema) return _kubb_kit.ast.factory.createSchema({
1915
1924
  ...resolvedSchema,
1916
1925
  title: schema.title ?? resolvedSchema.title,
@@ -1924,7 +1933,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1924
1933
  });
1925
1934
  const targetName = renames?.get(schema.$ref);
1926
1935
  return createNode(ctx, {
1927
- type: "ref",
1936
+ type: _kubb_kit.ast.schemaTypes.ref,
1928
1937
  name: (0, _kubb_kit.extractRefName)(schema.$ref),
1929
1938
  ref: schema.$ref,
1930
1939
  ...targetName ? { targetName } : {},
@@ -1936,7 +1945,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1936
1945
  const { not, ...rest } = schema;
1937
1946
  const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
1938
1947
  const notNode = _kubb_kit.ast.factory.createSchema({
1939
- type: "not",
1948
+ type: _kubb_kit.ast.schemaTypes.not,
1940
1949
  members: [parse({ schema: subschema })]
1941
1950
  });
1942
1951
  return createNode({
@@ -1945,7 +1954,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1945
1954
  nullable,
1946
1955
  defaultValue
1947
1956
  }, {
1948
- type: "intersection",
1957
+ type: _kubb_kit.ast.schemaTypes.intersection,
1949
1958
  members: [parse({
1950
1959
  schema: rest,
1951
1960
  name
@@ -2065,7 +2074,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
2065
2074
  nullable,
2066
2075
  defaultValue
2067
2076
  }, {
2068
- type: "intersection",
2077
+ type: _kubb_kit.ast.schemaTypes.intersection,
2069
2078
  members: [...(0, _kubb_kit.mergeAdjacentObjectsLazy)(allOfMembers.slice(0, syntheticStart)), ...(0, _kubb_kit.mergeAdjacentObjectsLazy)(allOfMembers.slice(syntheticStart))]
2070
2079
  });
2071
2080
  }
@@ -2091,7 +2100,8 @@ function convertUnion(context) {
2091
2100
  schema: memberBaseSchema,
2092
2101
  name
2093
2102
  }) : void 0;
2094
- if (sharedPropertiesNode || discriminator) {
2103
+ const missingRequired = (Array.isArray(schema.required) ? schema.required : []).filter((key) => !Object.hasOwn(schema.properties ?? {}, key));
2104
+ if (sharedPropertiesNode || discriminator || missingRequired.length) {
2095
2105
  const members = narrowUnionMembers({
2096
2106
  unionMembers,
2097
2107
  discriminator,
@@ -2106,15 +2116,25 @@ function convertUnion(context) {
2106
2116
  refs
2107
2117
  });
2108
2118
  const unionNode = createNode(ctx, {
2109
- type: "union",
2119
+ type: _kubb_kit.ast.schemaTypes.union,
2110
2120
  strategy,
2111
2121
  members,
2112
2122
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? _kubb_kit.ast.inferDiscriminatorPropertyName(members)
2113
2123
  });
2114
- if (!sharedPropertiesNode) return unionNode;
2124
+ const requiredProperties = missingRequired.map((name) => _kubb_kit.ast.factory.createProperty({
2125
+ name,
2126
+ required: true,
2127
+ schema: _kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown })
2128
+ }));
2129
+ const siblings = sharedPropertiesNode ? [sharedPropertiesNode] : [];
2130
+ if (requiredProperties.length) siblings.push(_kubb_kit.ast.factory.createSchema({
2131
+ type: _kubb_kit.ast.schemaTypes.object,
2132
+ properties: requiredProperties
2133
+ }));
2134
+ if (!siblings.length) return unionNode;
2115
2135
  return createNode(ctx, {
2116
- type: "intersection",
2117
- members: [unionNode, sharedPropertiesNode]
2136
+ type: _kubb_kit.ast.schemaTypes.intersection,
2137
+ members: [unionNode, ...siblings]
2118
2138
  });
2119
2139
  }
2120
2140
  const members = unionMembers.map((s) => parse({
@@ -2122,7 +2142,7 @@ function convertUnion(context) {
2122
2142
  name
2123
2143
  }));
2124
2144
  const unionNode = createNode(ctx, {
2125
- type: "union",
2145
+ type: _kubb_kit.ast.schemaTypes.union,
2126
2146
  strategy,
2127
2147
  members,
2128
2148
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? _kubb_kit.ast.inferDiscriminatorPropertyName(members)
@@ -2144,7 +2164,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
2144
2164
  nullable: types.includes("null") || nullable || void 0,
2145
2165
  defaultValue
2146
2166
  }, {
2147
- type: "union",
2167
+ type: _kubb_kit.ast.schemaTypes.union,
2148
2168
  members: nonNullTypes.map((t) => {
2149
2169
  return parse({
2150
2170
  schema: {
@@ -2920,9 +2940,13 @@ const adapterOas = (0, _kubb_core.defineExtension)({
2920
2940
  }));
2921
2941
  const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
2922
2942
  if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
2943
+ const aliasTargetOf = (name) => {
2944
+ const node = refAliasMap.get(name);
2945
+ return node?.ref ? _kubb_kit.ast.refName(node.ref) : node?.name;
2946
+ };
2923
2947
  function isAliasCycle(name) {
2924
2948
  const seen = /* @__PURE__ */ new Set([name]);
2925
- for (let next = refAliasMap.get(name)?.name; next; next = refAliasMap.get(next)?.name) {
2949
+ for (let next = aliasTargetOf(name); next; next = aliasTargetOf(next)) {
2926
2950
  if (next === name) return true;
2927
2951
  if (seen.has(next)) return false;
2928
2952
  seen.add(next);