@kubb/adapter-oas 5.9.5 → 5.10.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
@@ -12,7 +12,7 @@ var compatibility = {
12
12
  };
13
13
  //#endregion
14
14
  //#region package.json
15
- var version = "5.9.5";
15
+ var version = "5.10.0";
16
16
  //#endregion
17
17
  //#region src/constants.ts
18
18
  /**
@@ -535,6 +535,13 @@ function isNullable(schema) {
535
535
  return false;
536
536
  }
537
537
  /**
538
+ * Returns the `x-*` keys of `source` as-is, or `undefined` when there are none.
539
+ */
540
+ function pickExtensions(source) {
541
+ const entries = Object.entries(source).filter(([key]) => key.startsWith("x-"));
542
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
543
+ }
544
+ /**
538
545
  * Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
539
546
  */
540
547
  function isReference(obj) {
@@ -893,6 +900,7 @@ function parseParameter({ param, parentName, options, parseSchema }) {
893
900
  }) : _kubb_kit.ast.factory.createSchema({ type: options.unknownType });
894
901
  const style = param.style;
895
902
  const explode = param.explode;
903
+ const allowReserved = param.allowReserved;
896
904
  return _kubb_kit.ast.factory.createParameter({
897
905
  name: param.name,
898
906
  in: param.in,
@@ -902,7 +910,8 @@ function parseParameter({ param, parentName, options, parseSchema }) {
902
910
  },
903
911
  required: param.required ?? false,
904
912
  ...style !== void 0 ? { style } : {},
905
- ...explode !== void 0 ? { explode } : {}
913
+ ...explode !== void 0 ? { explode } : {},
914
+ ...allowReserved !== void 0 ? { allowReserved } : {}
906
915
  });
907
916
  }
908
917
  /**
@@ -1003,7 +1012,8 @@ function parseOperation({ operation, ...ctx }) {
1003
1012
  deprecated: operation.schema.deprecated || void 0,
1004
1013
  parameters,
1005
1014
  requestBody,
1006
- responses
1015
+ responses,
1016
+ extensions: pickExtensions(operation.schema)
1007
1017
  });
1008
1018
  }
1009
1019
  //#endregion
@@ -1377,6 +1387,27 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
1377
1387
  schema: resolvedSchema
1378
1388
  });
1379
1389
  }
1390
+ /** Converts `{ ...rest, not: X }` into `intersection[rest, not[X]]`; a bare `required` inside `not` borrows the outer `properties`. */
1391
+ function convertNot({ schema, name, nullable, defaultValue, parse }) {
1392
+ const { not, ...rest } = schema;
1393
+ const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
1394
+ const notNode = _kubb_kit.ast.factory.createSchema({
1395
+ type: "not",
1396
+ members: [parse({ schema: subschema })]
1397
+ });
1398
+ return createNode({
1399
+ schema,
1400
+ name,
1401
+ nullable,
1402
+ defaultValue
1403
+ }, {
1404
+ type: "intersection",
1405
+ members: [parse({
1406
+ schema: rest,
1407
+ name
1408
+ }), notNode]
1409
+ });
1410
+ }
1380
1411
  /**
1381
1412
  * Converts an `allOf` schema into a flattened node or an `IntersectionSchemaNode`.
1382
1413
  */
@@ -1853,7 +1884,7 @@ function convertArray({ schema, name, nullable, defaultValue, options, parse })
1853
1884
  //#endregion
1854
1885
  //#region src/emit/parseSchema.ts
1855
1886
  /**
1856
- * Ordered schema rule table. Order is significant: composition keywords (`$ref`, `allOf`,
1887
+ * Ordered schema rule table. Order is significant: composition keywords (`not`, `$ref`, `allOf`,
1857
1888
  * `oneOf`/`anyOf`) take precedence over `const`, which takes precedence over a genuine OAS 3.1
1858
1889
  * multi-type array (more than one non-`null` type), which takes precedence over `format`/`type`.
1859
1890
  * A multi-type array must split into its per-type members before `format` runs, otherwise
@@ -1864,6 +1895,10 @@ function convertArray({ schema, name, nullable, defaultValue, options, parse })
1864
1895
  * match/convert/fall-through contract.
1865
1896
  */
1866
1897
  const schemaRules = [
1898
+ {
1899
+ match: ({ schema }) => typeof schema.not === "object" && schema.not !== null,
1900
+ convert: convertNot
1901
+ },
1867
1902
  {
1868
1903
  match: ({ schema }) => isReference(schema),
1869
1904
  convert: convertRef
@@ -2194,7 +2229,7 @@ function visit(node, pointer) {
2194
2229
  for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`);
2195
2230
  return;
2196
2231
  }
2197
- if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`);
2232
+ if (node.type === "union" || node.type === "intersection" || node.type === "not") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`);
2198
2233
  }
2199
2234
  //#endregion
2200
2235
  //#region src/adapter.ts
@@ -2311,18 +2346,21 @@ const adapterOas = (0, _kubb_kit.defineExtension)({
2311
2346
  server
2312
2347
  }),
2313
2348
  servers: (document.servers ?? []).filter((entry) => entry.url).map(({ url, description, variables }) => {
2349
+ const declared = variables && Object.keys(variables).length > 0 ? { variables } : {};
2314
2350
  try {
2315
2351
  return {
2316
2352
  url: resolveServerUrl({
2317
2353
  url,
2318
2354
  variables
2319
2355
  }),
2320
- description
2356
+ description,
2357
+ ...declared
2321
2358
  };
2322
2359
  } catch {
2323
2360
  return {
2324
2361
  url,
2325
- description
2362
+ description,
2363
+ ...declared
2326
2364
  };
2327
2365
  }
2328
2366
  }),
@@ -2339,7 +2377,8 @@ const adapterOas = (0, _kubb_kit.defineExtension)({
2339
2377
  }] : [];
2340
2378
  }),
2341
2379
  circularNames,
2342
- enumNames
2380
+ enumNames,
2381
+ extensions: pickExtensions(document)
2343
2382
  }
2344
2383
  });
2345
2384
  }