@kubb/adapter-oas 5.14.2 → 5.14.4

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.2";
23
+ var version = "5.14.4";
24
24
  //#endregion
25
25
  //#region src/constants.ts
26
26
  /**
@@ -1903,7 +1903,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1903
1903
  nullable,
1904
1904
  defaultValue
1905
1905
  };
1906
- 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 });
1907
1907
  if (refPath && !refPath.startsWith("#/components/schemas/") && resolvedSchema) return ast.factory.createSchema({
1908
1908
  ...resolvedSchema,
1909
1909
  title: schema.title ?? resolvedSchema.title,
@@ -1917,7 +1917,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1917
1917
  });
1918
1918
  const targetName = renames?.get(schema.$ref);
1919
1919
  return createNode(ctx, {
1920
- type: "ref",
1920
+ type: ast.schemaTypes.ref,
1921
1921
  name: extractRefName(schema.$ref),
1922
1922
  ref: schema.$ref,
1923
1923
  ...targetName ? { targetName } : {},
@@ -1929,7 +1929,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1929
1929
  const { not, ...rest } = schema;
1930
1930
  const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
1931
1931
  const notNode = ast.factory.createSchema({
1932
- type: "not",
1932
+ type: ast.schemaTypes.not,
1933
1933
  members: [parse({ schema: subschema })]
1934
1934
  });
1935
1935
  return createNode({
@@ -1938,7 +1938,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1938
1938
  nullable,
1939
1939
  defaultValue
1940
1940
  }, {
1941
- type: "intersection",
1941
+ type: ast.schemaTypes.intersection,
1942
1942
  members: [parse({
1943
1943
  schema: rest,
1944
1944
  name
@@ -2058,7 +2058,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
2058
2058
  nullable,
2059
2059
  defaultValue
2060
2060
  }, {
2061
- type: "intersection",
2061
+ type: ast.schemaTypes.intersection,
2062
2062
  members: [...mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))]
2063
2063
  });
2064
2064
  }
@@ -2084,7 +2084,8 @@ function convertUnion(context) {
2084
2084
  schema: memberBaseSchema,
2085
2085
  name
2086
2086
  }) : void 0;
2087
- 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) {
2088
2089
  const members = narrowUnionMembers({
2089
2090
  unionMembers,
2090
2091
  discriminator,
@@ -2099,15 +2100,25 @@ function convertUnion(context) {
2099
2100
  refs
2100
2101
  });
2101
2102
  const unionNode = createNode(ctx, {
2102
- type: "union",
2103
+ type: ast.schemaTypes.union,
2103
2104
  strategy,
2104
2105
  members,
2105
2106
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
2106
2107
  });
2107
- 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;
2108
2119
  return createNode(ctx, {
2109
- type: "intersection",
2110
- members: [unionNode, sharedPropertiesNode]
2120
+ type: ast.schemaTypes.intersection,
2121
+ members: [unionNode, ...siblings]
2111
2122
  });
2112
2123
  }
2113
2124
  const members = unionMembers.map((s) => parse({
@@ -2115,7 +2126,7 @@ function convertUnion(context) {
2115
2126
  name
2116
2127
  }));
2117
2128
  const unionNode = createNode(ctx, {
2118
- type: "union",
2129
+ type: ast.schemaTypes.union,
2119
2130
  strategy,
2120
2131
  members,
2121
2132
  discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.inferDiscriminatorPropertyName(members)
@@ -2137,7 +2148,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
2137
2148
  nullable: types.includes("null") || nullable || void 0,
2138
2149
  defaultValue
2139
2150
  }, {
2140
- type: "union",
2151
+ type: ast.schemaTypes.union,
2141
2152
  members: nonNullTypes.map((t) => {
2142
2153
  return parse({
2143
2154
  schema: {