@kubb/adapter-oas 4.33.4 → 4.35.1

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
@@ -3,27 +3,9 @@ import * as _kubb_core0 from "@kubb/core";
3
3
  import { AdapterFactoryOptions } from "@kubb/core";
4
4
  import { DiscriminatorObject, OASDocument, SchemaObject } from "oas/types";
5
5
  import BaseOas from "oas";
6
- import { RootNode } from "@kubb/ast/types";
7
6
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
8
7
  import { Operation } from "oas/operation";
9
8
 
10
- //#region src/devtools.d.ts
11
- type DevtoolsOptions = {
12
- /**
13
- * Override the Kubb Studio base URL.
14
- * @default 'https://studio.kubb.dev'
15
- */
16
- studioUrl?: string;
17
- };
18
- /**
19
- * Prints the Kubb Studio URL for the given `RootNode` — inspired by
20
- * [testing-playground](https://testing-playground.com/).
21
- *
22
- * Drop this call next to an assertion during development or in a failing test
23
- * to get an instantly-clickable link for visual debugging.
24
- */
25
- declare function logAst(root: RootNode, options?: DevtoolsOptions): void;
26
- //#endregion
27
9
  //#region src/oas/types.d.ts
28
10
  type contentType = 'application/json' | (string & {});
29
11
  type SchemaObject$1 = SchemaObject & {
@@ -154,15 +136,6 @@ type OasAdapterOptions = {
154
136
  * @default `unknownType`
155
137
  */
156
138
  emptySchemaType?: 'any' | 'unknown' | 'void';
157
- /**
158
- * Enable visual AST inspection via Kubb Studio.
159
- *
160
- * - `true` — opens `https://studio.kubb.dev/ast?root=<encoded>` after every `parse()`.
161
- * - `{ studioUrl }` — same, with a custom Studio URL (e.g. your self-hosted instance).
162
- *
163
- * Logs the URL to the console so you can click/open it during development or CI.
164
- */
165
- devtools?: boolean | DevtoolsOptions;
166
139
  };
167
140
  type OasAdapterResolvedOptions = {
168
141
  validate: boolean;
@@ -176,7 +149,6 @@ type OasAdapterResolvedOptions = {
176
149
  integerType: NonNullable<OasAdapterOptions['integerType']>;
177
150
  unknownType: NonNullable<OasAdapterOptions['unknownType']>;
178
151
  emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
179
- devtools: OasAdapterOptions['devtools'];
180
152
  };
181
153
  type OasAdapter = AdapterFactoryOptions<'oas', OasAdapterOptions, OasAdapterResolvedOptions>;
182
154
  //#endregion
@@ -202,5 +174,5 @@ declare const adapterOasName = "oas";
202
174
  */
203
175
  declare const adapterOas: (options?: OasAdapterOptions | undefined) => _kubb_core0.Adapter<OasAdapter>;
204
176
  //#endregion
205
- export { adapterOas, adapterOasName, logAst };
177
+ export { adapterOas, adapterOasName };
206
178
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@ import "./chunk--u3MIqq1.js";
2
2
  import path from "node:path";
3
3
  import { collect, createOperation, createParameter, createProperty, createResponse, createRoot, createSchema, narrowSchema, schemaTypes, transform } from "@kubb/ast";
4
4
  import { defineAdapter } from "@kubb/core";
5
- import { deflateSync } from "fflate";
6
5
  import { bundle, loadConfig } from "@redocly/openapi-core";
7
6
  import yaml from "@stoplight/yaml";
8
7
  import { isRef } from "oas/types";
@@ -12,38 +11,6 @@ import swagger2openapi from "swagger2openapi";
12
11
  import jsonpointer from "jsonpointer";
13
12
  import BaseOas from "oas";
14
13
  import { matchesMimeType } from "oas/utils";
15
- /**
16
- * Encodes a `RootNode` as a compressed, URL-safe string.
17
- *
18
- * The JSON representation is deflate-compressed with {@link deflateSync} before
19
- * base64url encoding, which typically reduces payload size by 70–80 % and
20
- * keeps URLs well within browser and server path-length limits.
21
- *
22
- * Use {@link decodeAst} to reverse.
23
- */
24
- function encodeAst(root) {
25
- const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(root)));
26
- return Buffer.from(compressed).toString("base64url");
27
- }
28
- /**
29
- * Constructs the Kubb Studio URL for visual AST inspection.
30
- * The `root` is encoded and attached as the `?root=` query parameter so Studio
31
- * can decode and render it without a round-trip to any server.
32
- */
33
- function getAstUrl(root, options = {}) {
34
- return `${(options.studioUrl ?? "https://studio.kubb.dev").replace(/\/$/, "")}/ast?root=${encodeAst(root)}`;
35
- }
36
- /**
37
- * Prints the Kubb Studio URL for the given `RootNode` — inspired by
38
- * [testing-playground](https://testing-playground.com/).
39
- *
40
- * Drop this call next to an assertion during development or in a failing test
41
- * to get an instantly-clickable link for visual debugging.
42
- */
43
- function logAst(root, options = {}) {
44
- console.log(`\n ${getAstUrl(root, options)}\n`);
45
- }
46
- //#endregion
47
14
  //#region src/oas/resolveServerUrl.ts
48
15
  /**
49
16
  * Resolves an OpenAPI server URL by substituting `{variable}` placeholders.
@@ -1001,7 +968,7 @@ function applyDiscriminatorEnum(schema) {
1001
968
  * Creates an OAS parser that converts an OpenAPI/Swagger spec into
1002
969
  * the `@kubb/ast` tree.
1003
970
  *
1004
- * Options are passed per-call to `buildAst` or `convertSchema` rather than
971
+ * Options are passed per-call to `parse` or `convertSchema` rather than
1005
972
  * at construction time, keeping the factory lightweight.
1006
973
  *
1007
974
  * This is the **kubb-parser** stage of the compilation lifecycle:
@@ -1013,7 +980,7 @@ function applyDiscriminatorEnum(schema) {
1013
980
  * @example
1014
981
  * ```ts
1015
982
  * const parser = createOasParser(oas)
1016
- * const root = parser.buildAst({ emptySchemaType: 'unknown' })
983
+ * const root = parser.parse({ emptySchemaType: 'unknown' })
1017
984
  * ```
1018
985
  */
1019
986
  function createOasParser(oas, { contentType, collisionDetection } = {}) {
@@ -1641,7 +1608,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1641
1608
  * Converts an OpenAPI/Swagger spec (wrapped in a Kubb `Oas` instance) into
1642
1609
  * a `RootNode` — the top-level node of the `@kubb/ast` tree.
1643
1610
  */
1644
- function buildAst(options) {
1611
+ function parse(options) {
1645
1612
  const mergedOptions = {
1646
1613
  ...DEFAULT_OPTIONS,
1647
1614
  ...options
@@ -1705,7 +1672,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
1705
1672
  } });
1706
1673
  }
1707
1674
  return {
1708
- buildAst,
1675
+ parse,
1709
1676
  convertSchema,
1710
1677
  resolveRefs,
1711
1678
  getImports
@@ -1733,7 +1700,7 @@ const adapterOasName = "oas";
1733
1700
  * ```
1734
1701
  */
1735
1702
  const adapterOas = defineAdapter((options) => {
1736
- const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = false, dateType = "string", integerType = "number", unknownType = "any", emptySchemaType = unknownType, devtools } = options;
1703
+ const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = false, dateType = "string", integerType = "number", unknownType = "any", emptySchemaType = unknownType } = options;
1737
1704
  return {
1738
1705
  name: "oas",
1739
1706
  options: {
@@ -1747,8 +1714,7 @@ const adapterOas = defineAdapter((options) => {
1747
1714
  dateType,
1748
1715
  integerType,
1749
1716
  unknownType,
1750
- emptySchemaType,
1751
- devtools
1717
+ emptySchemaType
1752
1718
  },
1753
1719
  async parse(source) {
1754
1720
  const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
@@ -1762,11 +1728,11 @@ const adapterOas = defineAdapter((options) => {
1762
1728
  } catch (_err) {}
1763
1729
  const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
1764
1730
  const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
1765
- const rootNode = createRoot({
1731
+ return createRoot({
1766
1732
  ...createOasParser(oas, {
1767
1733
  contentType,
1768
1734
  collisionDetection
1769
- }).buildAst({
1735
+ }).parse({
1770
1736
  dateType,
1771
1737
  integerType,
1772
1738
  unknownType,
@@ -1778,8 +1744,6 @@ const adapterOas = defineAdapter((options) => {
1778
1744
  baseURL
1779
1745
  }
1780
1746
  });
1781
- if (devtools) logAst(rootNode, devtools === true ? {} : devtools);
1782
- return rootNode;
1783
1747
  }
1784
1748
  };
1785
1749
  });
@@ -1800,6 +1764,6 @@ function sourceToFakeConfig(source) {
1800
1764
  }
1801
1765
  }
1802
1766
  //#endregion
1803
- export { adapterOas, adapterOasName, logAst };
1767
+ export { adapterOas, adapterOasName };
1804
1768
 
1805
1769
  //# sourceMappingURL=index.js.map