@kubb/adapter-oas 5.0.0-beta.63 → 5.0.0-beta.64

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
2
  import { AdapterFactoryOptions, ast } from "@kubb/core";
3
3
 
4
4
  //#region ../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
- import "./chunk-C0LytTxp.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  import { Diagnostics, ast, createAdapter } from "@kubb/core";
3
3
  import path from "node:path";
4
4
  import { access, readFile } from "node:fs/promises";
5
5
  import { compileErrors, validate } from "@readme/openapi-parser";
6
+ import { upgrade } from "@scalar/openapi-upgrader";
6
7
  import { parse } from "yaml";
7
8
  import { bundle } from "api-ref-bundler";
8
9
  import { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion } from "@kubb/ast/macros";
@@ -294,19 +295,6 @@ async function read(path) {
294
295
  //#endregion
295
296
  //#region ../../internals/utils/src/object.ts
296
297
  /**
297
- * Returns `true` when `value` is a plain (non-null, non-array) object.
298
- *
299
- * @example
300
- * ```ts
301
- * isPlainObject({}) // true
302
- * isPlainObject([]) // false
303
- * isPlainObject(null) // false
304
- * ```
305
- */
306
- function isPlainObject(value) {
307
- return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
308
- }
309
- /**
310
298
  * Recursively merges `source` into `target`, combining nested plain objects.
311
299
  * Arrays and non-object values from `source` override the corresponding values in `target`.
312
300
  *
@@ -573,66 +561,6 @@ async function bundleDocument(pathOrUrl) {
573
561
  return await bundle(pathOrUrl, resolver);
574
562
  }
575
563
  //#endregion
576
- //#region src/guards.ts
577
- /**
578
- * Returns `true` when `doc` is a Swagger 2.0 document (no `openapi` key).
579
- *
580
- * @example
581
- * ```ts
582
- * if (isOpenApiV2Document(doc)) {
583
- * // doc is OpenAPIV2.Document
584
- * }
585
- * ```
586
- */
587
- function isOpenApiV2Document(doc) {
588
- return !!doc && isPlainObject(doc) && !("openapi" in doc);
589
- }
590
- /**
591
- * Returns `true` when a schema should be treated as nullable.
592
- *
593
- * Recognizes all nullable signals across OAS versions: `nullable: true` (OAS 3.0),
594
- * `x-nullable: true` (vendor extension), `type: 'null'`, and `type: ['null', ...]` (OAS 3.1).
595
- *
596
- * @example
597
- * ```ts
598
- * isNullable({ type: 'string', nullable: true }) // true
599
- * isNullable({ type: ['string', 'null'] }) // true
600
- * isNullable({ type: 'string' }) // false
601
- * ```
602
- */
603
- function isNullable(schema) {
604
- if ((schema?.nullable ?? schema?.["x-nullable"]) === true) return true;
605
- const schemaType = schema?.type;
606
- if (schemaType === "null") return true;
607
- if (Array.isArray(schemaType)) return schemaType.includes("null");
608
- return false;
609
- }
610
- /**
611
- * Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
612
- *
613
- * @example
614
- * ```ts
615
- * isReference({ $ref: '#/components/schemas/Pet' }) // true
616
- * isReference({ type: 'string' }) // false
617
- * ```
618
- */
619
- function isReference(obj) {
620
- return !!obj && typeof obj === "object" && "$ref" in obj;
621
- }
622
- /**
623
- * Returns `true` when `obj` is a schema with a structured OAS 3.x `discriminator` object.
624
- *
625
- * @example
626
- * ```ts
627
- * isDiscriminator({ discriminator: { propertyName: 'type', mapping: {} } }) // true
628
- * isDiscriminator({ discriminator: 'type' }) // false (Swagger 2 string form)
629
- * ```
630
- */
631
- function isDiscriminator(obj) {
632
- const record = obj;
633
- return !!obj && !!record["discriminator"] && typeof record["discriminator"] !== "string";
634
- }
635
- //#endregion
636
564
  //#region src/factory.ts
637
565
  /**
638
566
  * Loads and bundles an OpenAPI document, returning the raw `Document`.
@@ -640,7 +568,7 @@ function isDiscriminator(obj) {
640
568
  * Accepts a file path string or an already-parsed document object. File paths and URLs are
641
569
  * bundled via `api-ref-bundler`, hoisting external file schemas into named `components.schemas`
642
570
  * entries so generators can emit named types and imports. Swagger 2.0 documents are
643
- * automatically up-converted to OpenAPI 3.0 via `swagger2openapi`.
571
+ * automatically up-converted to OpenAPI 3.0 via `@scalar/openapi-upgrader`.
644
572
  *
645
573
  * @example
646
574
  * ```ts
@@ -650,13 +578,7 @@ function isDiscriminator(obj) {
650
578
  */
651
579
  async function parseDocument(pathOrApi, { canBundle = true } = {}) {
652
580
  if (typeof pathOrApi === "string" && canBundle) return parseDocument(await bundleDocument(pathOrApi), { canBundle: false });
653
- const document = typeof pathOrApi === "string" ? parse(pathOrApi) : pathOrApi;
654
- if (isOpenApiV2Document(document)) {
655
- const { default: swagger2openapi } = await import("swagger2openapi");
656
- const { openapi } = await swagger2openapi.convertObj(document, { anchors: true });
657
- return openapi;
658
- }
659
- return document;
581
+ return upgrade(typeof pathOrApi === "string" ? parse(pathOrApi) : pathOrApi, "3.0");
660
582
  }
661
583
  /**
662
584
  * Deep-merges multiple OpenAPI documents into a single `Document`.
@@ -908,6 +830,53 @@ function plan(roots, context) {
908
830
  };
909
831
  }
910
832
  //#endregion
833
+ //#region src/guards.ts
834
+ /**
835
+ * Returns `true` when a schema should be treated as nullable.
836
+ *
837
+ * Recognizes all nullable signals across OAS versions: `nullable: true` (OAS 3.0),
838
+ * `x-nullable: true` (vendor extension), `type: 'null'`, and `type: ['null', ...]` (OAS 3.1).
839
+ *
840
+ * @example
841
+ * ```ts
842
+ * isNullable({ type: 'string', nullable: true }) // true
843
+ * isNullable({ type: ['string', 'null'] }) // true
844
+ * isNullable({ type: 'string' }) // false
845
+ * ```
846
+ */
847
+ function isNullable(schema) {
848
+ if ((schema?.nullable ?? schema?.["x-nullable"]) === true) return true;
849
+ const schemaType = schema?.type;
850
+ if (schemaType === "null") return true;
851
+ if (Array.isArray(schemaType)) return schemaType.includes("null");
852
+ return false;
853
+ }
854
+ /**
855
+ * Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
856
+ *
857
+ * @example
858
+ * ```ts
859
+ * isReference({ $ref: '#/components/schemas/Pet' }) // true
860
+ * isReference({ type: 'string' }) // false
861
+ * ```
862
+ */
863
+ function isReference(obj) {
864
+ return !!obj && typeof obj === "object" && "$ref" in obj;
865
+ }
866
+ /**
867
+ * Returns `true` when `obj` is a schema with a structured OAS 3.x `discriminator` object.
868
+ *
869
+ * @example
870
+ * ```ts
871
+ * isDiscriminator({ discriminator: { propertyName: 'type', mapping: {} } }) // true
872
+ * isDiscriminator({ discriminator: 'type' }) // false (Swagger 2 string form)
873
+ * ```
874
+ */
875
+ function isDiscriminator(obj) {
876
+ const record = obj;
877
+ return !!obj && !!record["discriminator"] && typeof record["discriminator"] !== "string";
878
+ }
879
+ //#endregion
911
880
  //#region src/refs.ts
912
881
  const _refCache = /* @__PURE__ */ new WeakMap();
913
882
  /**