@kubb/adapter-oas 5.8.0 → 5.8.2

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
@@ -1245,7 +1245,7 @@ type AdapterOasResolvedOptions = {
1245
1245
  integerType: NonNullable<AdapterOasOptions['integerType']>;
1246
1246
  unknownType: NonNullable<AdapterOasOptions['unknownType']>;
1247
1247
  emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>;
1248
- enumSuffix: AdapterOasOptions['enumSuffix'];
1248
+ enumSuffix: NonNullable<AdapterOasOptions['enumSuffix']>;
1249
1249
  };
1250
1250
  /**
1251
1251
  * `@kubb/core` adapter factory type for the OpenAPI adapter.
@@ -1284,7 +1284,7 @@ export declare const adapterOasName = "oas";
1284
1284
  * })
1285
1285
  * ```
1286
1286
  */
1287
- export declare const adapterOas: (options?: AdapterOasOptions | undefined) => import("@kubb/core").Adapter<AdapterOas>;
1287
+ export declare const adapterOas: import("@kubb/core").AdapterFactory<AdapterOas>;
1288
1288
  //#endregion
1289
1289
  //#region src/operation.d.ts
1290
1290
  /**
package/dist/index.js CHANGED
@@ -1,9 +1,18 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Diagnostics, ast, childName, createAdapter, enumPropName, extractRefName, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mergeAdjacentObjectsLazy } from "@kubb/kit";
2
+ import { Diagnostics, ast, childName, defineExtension, enumPropName, extractRefName, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mergeAdjacentObjectsLazy } from "@kubb/kit";
3
3
  import { access, readFile } from "node:fs/promises";
4
4
  import { parse } from "yaml";
5
5
  import { upgrade } from "@scalar/openapi-upgrader";
6
6
  import { bundle } from "api-ref-bundler";
7
+ //#region kubb-extension.json
8
+ var compatibility = {
9
+ "kubb": ">=5.8.0",
10
+ "node": ">=22"
11
+ };
12
+ //#endregion
13
+ //#region package.json
14
+ var version = "5.8.2";
15
+ //#endregion
7
16
  //#region src/constants.ts
8
17
  /**
9
18
  * Default parser options applied when no explicit options are provided.
@@ -2345,131 +2354,133 @@ const adapterOasName = "oas";
2345
2354
  * })
2346
2355
  * ```
2347
2356
  */
2348
- const adapterOas = createAdapter((options) => {
2349
- const { validate = true, contentType, server, discriminator = "preserve", enums = "inline", dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType } = options;
2350
- const parserOptions = {
2351
- dateType,
2352
- integerType,
2353
- unknownType,
2354
- emptySchemaType,
2355
- enumSuffix
2356
- };
2357
- const resolvedOptions = {
2357
+ const adapterOas = defineExtension({
2358
+ kind: "adapter",
2359
+ meta: {
2360
+ name: "oas",
2361
+ version,
2362
+ compatibility
2363
+ },
2364
+ setup: ({ validate = true, contentType, server, discriminator = "preserve", enums = "inline", dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType }) => ({
2358
2365
  validate,
2359
2366
  contentType,
2360
2367
  server,
2361
2368
  discriminator,
2362
2369
  enums,
2363
- ...parserOptions
2364
- };
2365
- let parsedDocument = null;
2366
- const inputCache = /* @__PURE__ */ new WeakMap();
2367
- function parseInput({ document, refs, schemas, parser }) {
2368
- const { parseSchema } = parser;
2369
- const parsedByName = /* @__PURE__ */ new Map();
2370
- const refAliasMap = /* @__PURE__ */ new Map();
2371
- const enumNames = [];
2372
- const discriminatorParentNodes = [];
2373
- const refGraph = /* @__PURE__ */ new Map();
2374
- for (const [name, schema] of Object.entries(schemas)) {
2375
- const node = parseSchema({
2376
- schema,
2377
- name
2378
- });
2379
- parsedByName.set(name, node);
2380
- const refs = scanSchema({
2381
- node,
2382
- name
2370
+ dateType,
2371
+ integerType,
2372
+ unknownType,
2373
+ emptySchemaType,
2374
+ enumSuffix
2375
+ }),
2376
+ build({ validate, contentType, server, discriminator, enums, ...parserOptions }) {
2377
+ let parsedDocument = null;
2378
+ const inputCache = /* @__PURE__ */ new WeakMap();
2379
+ function parseInput({ document, refs, schemas, parser }) {
2380
+ const { parseSchema } = parser;
2381
+ const parsedByName = /* @__PURE__ */ new Map();
2382
+ const refAliasMap = /* @__PURE__ */ new Map();
2383
+ const enumNames = [];
2384
+ const discriminatorParentNodes = [];
2385
+ const refGraph = /* @__PURE__ */ new Map();
2386
+ for (const [name, schema] of Object.entries(schemas)) {
2387
+ const node = parseSchema({
2388
+ schema,
2389
+ name
2390
+ });
2391
+ parsedByName.set(name, node);
2392
+ const refs = scanSchema({
2393
+ node,
2394
+ name
2395
+ });
2396
+ if (node.name) refGraph.set(node.name, refs);
2397
+ if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
2398
+ if (ast.narrowSchema(node, "enum") && node.name) enumNames.push(node.name);
2399
+ if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
2400
+ }
2401
+ const circularNames = [...ast.findCircularSchemasFromGraph(refGraph)];
2402
+ const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
2403
+ const operationNodes = getOperations(document, refs).map((operation) => parseOperation({
2404
+ operation,
2405
+ refs,
2406
+ contentType,
2407
+ options: parserOptions,
2408
+ parseSchema
2409
+ }));
2410
+ const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
2411
+ if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
2412
+ const schemaNodes = promotedEnums ? [...promotedEnums.values()] : [];
2413
+ for (const name of Object.keys(schemas)) {
2414
+ const aliasTarget = refAliasMap.get(name)?.name;
2415
+ const aliased = aliasTarget ? parsedByName.get(aliasTarget) : void 0;
2416
+ const parsed = parsedByName.get(name);
2417
+ const child = discriminatorChildMap?.get(name);
2418
+ const base = child ? patchDiscriminatorNode(parsed, child) : parsed;
2419
+ const node = aliased ? {
2420
+ ...aliased,
2421
+ name
2422
+ } : base;
2423
+ schemaNodes.push(promotedEnums ? refPromotedEnums(node, promotedEnums) : node);
2424
+ }
2425
+ const operations = promotedEnums ? operationNodes.map((node) => refPromotedEnums(node, promotedEnums)) : operationNodes;
2426
+ return ast.factory.createInput({
2427
+ schemas: schemaNodes,
2428
+ operations,
2429
+ meta: {
2430
+ title: document.info?.title,
2431
+ description: document.info?.description,
2432
+ version: document.info?.version,
2433
+ baseURL: resolveBaseUrl({
2434
+ document,
2435
+ server
2436
+ }),
2437
+ circularNames,
2438
+ enumNames
2439
+ }
2383
2440
  });
2384
- if (node.name) refGraph.set(node.name, refs);
2385
- if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
2386
- if (ast.narrowSchema(node, "enum") && node.name) enumNames.push(node.name);
2387
- if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
2388
- }
2389
- const circularNames = [...ast.findCircularSchemasFromGraph(refGraph)];
2390
- const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
2391
- const operationNodes = getOperations(document, refs).map((operation) => parseOperation({
2392
- operation,
2393
- refs,
2394
- contentType,
2395
- options: parserOptions,
2396
- parseSchema
2397
- }));
2398
- const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
2399
- if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
2400
- const schemaNodes = promotedEnums ? [...promotedEnums.values()] : [];
2401
- for (const name of Object.keys(schemas)) {
2402
- const aliasTarget = refAliasMap.get(name)?.name;
2403
- const aliased = aliasTarget ? parsedByName.get(aliasTarget) : void 0;
2404
- const parsed = parsedByName.get(name);
2405
- const child = discriminatorChildMap?.get(name);
2406
- const base = child ? patchDiscriminatorNode(parsed, child) : parsed;
2407
- const node = aliased ? {
2408
- ...aliased,
2409
- name
2410
- } : base;
2411
- schemaNodes.push(promotedEnums ? refPromotedEnums(node, promotedEnums) : node);
2412
2441
  }
2413
- const operations = promotedEnums ? operationNodes.map((node) => refPromotedEnums(node, promotedEnums)) : operationNodes;
2414
- return ast.factory.createInput({
2415
- schemas: schemaNodes,
2416
- operations,
2417
- meta: {
2418
- title: document.info?.title,
2419
- description: document.info?.description,
2420
- version: document.info?.version,
2421
- baseURL: resolveBaseUrl({
2422
- document,
2423
- server
2424
- }),
2425
- circularNames,
2426
- enumNames
2427
- }
2428
- });
2429
- }
2430
- return {
2431
- name: "oas",
2432
- options: resolvedOptions,
2433
- get document() {
2434
- return parsedDocument;
2435
- },
2436
- async validate(input, options) {
2437
- await assertInputExists(input);
2438
- const document = await parseDocument(input);
2439
- assertDocument(document);
2440
- await validateDocument(document, options);
2441
- },
2442
- async parse(source, { signal } = {}) {
2443
- signal?.throwIfAborted();
2444
- const cached = inputCache.get(source);
2445
- if (cached) return cached;
2446
- const promise = (async () => {
2447
- const document = await parseFromConfig(source);
2448
- signal?.throwIfAborted();
2442
+ return {
2443
+ get document() {
2444
+ return parsedDocument;
2445
+ },
2446
+ async validate(input, options) {
2447
+ await assertInputExists(input);
2448
+ const document = await parseDocument(input);
2449
2449
  assertDocument(document);
2450
- if (validate) await validateDocument(document);
2451
- parsedDocument = document;
2452
- const refs = createRefs(document);
2453
- const { schemas, renames } = getSchemas(document, { contentType }, refs);
2454
- return parseInput({
2455
- document,
2456
- refs,
2457
- schemas,
2458
- parser: createSchemaParser({
2450
+ await validateDocument(document, options);
2451
+ },
2452
+ async parse(source, { signal } = {}) {
2453
+ signal?.throwIfAborted();
2454
+ const cached = inputCache.get(source);
2455
+ if (cached) return cached;
2456
+ const promise = (async () => {
2457
+ const document = await parseFromConfig(source);
2458
+ signal?.throwIfAborted();
2459
+ assertDocument(document);
2460
+ if (validate) await validateDocument(document);
2461
+ parsedDocument = document;
2462
+ const refs = createRefs(document);
2463
+ const { schemas, renames } = getSchemas(document, { contentType }, refs);
2464
+ return parseInput({
2459
2465
  document,
2460
2466
  refs,
2461
- renames,
2462
- options: parserOptions
2463
- })
2467
+ schemas,
2468
+ parser: createSchemaParser({
2469
+ document,
2470
+ refs,
2471
+ renames,
2472
+ options: parserOptions
2473
+ })
2474
+ });
2475
+ })();
2476
+ inputCache.set(source, promise);
2477
+ return promise.catch((error) => {
2478
+ if (signal?.aborted) inputCache.delete(source);
2479
+ throw error;
2464
2480
  });
2465
- })();
2466
- inputCache.set(source, promise);
2467
- return promise.catch((error) => {
2468
- if (signal?.aborted) inputCache.delete(source);
2469
- throw error;
2470
- });
2471
- }
2472
- };
2481
+ }
2482
+ };
2483
+ }
2473
2484
  });
2474
2485
  //#endregion
2475
2486
  export { adapterOas, adapterOasName };