@kubb/adapter-oas 5.8.0 → 5.8.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/OVERVIEW.md +29 -0
- package/dist/index.cjs +124 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +124 -114
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +181 -0
- package/package.json +5 -2
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:
|
|
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
|
@@ -4,6 +4,15 @@ 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.1";
|
|
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,132 @@ const adapterOasName = "oas";
|
|
|
2345
2354
|
* })
|
|
2346
2355
|
* ```
|
|
2347
2356
|
*/
|
|
2348
|
-
const adapterOas = createAdapter(
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
enumSuffix
|
|
2356
|
-
};
|
|
2357
|
-
const resolvedOptions = {
|
|
2357
|
+
const adapterOas = createAdapter({
|
|
2358
|
+
meta: {
|
|
2359
|
+
name: "oas",
|
|
2360
|
+
version,
|
|
2361
|
+
compatibility
|
|
2362
|
+
},
|
|
2363
|
+
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
2364
|
validate,
|
|
2359
2365
|
contentType,
|
|
2360
2366
|
server,
|
|
2361
2367
|
discriminator,
|
|
2362
2368
|
enums,
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
const
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
const
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2369
|
+
dateType,
|
|
2370
|
+
integerType,
|
|
2371
|
+
unknownType,
|
|
2372
|
+
emptySchemaType,
|
|
2373
|
+
enumSuffix
|
|
2374
|
+
}),
|
|
2375
|
+
build({ validate, contentType, server, discriminator, enums, ...parserOptions }) {
|
|
2376
|
+
let parsedDocument = null;
|
|
2377
|
+
const inputCache = /* @__PURE__ */ new WeakMap();
|
|
2378
|
+
function parseInput({ document, refs, schemas, parser }) {
|
|
2379
|
+
const { parseSchema } = parser;
|
|
2380
|
+
const parsedByName = /* @__PURE__ */ new Map();
|
|
2381
|
+
const refAliasMap = /* @__PURE__ */ new Map();
|
|
2382
|
+
const enumNames = [];
|
|
2383
|
+
const discriminatorParentNodes = [];
|
|
2384
|
+
const refGraph = /* @__PURE__ */ new Map();
|
|
2385
|
+
for (const [name, schema] of Object.entries(schemas)) {
|
|
2386
|
+
const node = parseSchema({
|
|
2387
|
+
schema,
|
|
2388
|
+
name
|
|
2389
|
+
});
|
|
2390
|
+
parsedByName.set(name, node);
|
|
2391
|
+
const refs = scanSchema({
|
|
2392
|
+
node,
|
|
2393
|
+
name
|
|
2394
|
+
});
|
|
2395
|
+
if (node.name) refGraph.set(node.name, refs);
|
|
2396
|
+
if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
|
|
2397
|
+
if (ast.narrowSchema(node, "enum") && node.name) enumNames.push(node.name);
|
|
2398
|
+
if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
|
|
2399
|
+
}
|
|
2400
|
+
const circularNames = [...ast.findCircularSchemasFromGraph(refGraph)];
|
|
2401
|
+
const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
|
|
2402
|
+
const operationNodes = getOperations(document, refs).map((operation) => parseOperation({
|
|
2403
|
+
operation,
|
|
2404
|
+
refs,
|
|
2405
|
+
contentType,
|
|
2406
|
+
options: parserOptions,
|
|
2407
|
+
parseSchema
|
|
2408
|
+
}));
|
|
2409
|
+
const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
|
|
2410
|
+
if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
|
|
2411
|
+
const schemaNodes = promotedEnums ? [...promotedEnums.values()] : [];
|
|
2412
|
+
for (const name of Object.keys(schemas)) {
|
|
2413
|
+
const aliasTarget = refAliasMap.get(name)?.name;
|
|
2414
|
+
const aliased = aliasTarget ? parsedByName.get(aliasTarget) : void 0;
|
|
2415
|
+
const parsed = parsedByName.get(name);
|
|
2416
|
+
const child = discriminatorChildMap?.get(name);
|
|
2417
|
+
const base = child ? patchDiscriminatorNode(parsed, child) : parsed;
|
|
2418
|
+
const node = aliased ? {
|
|
2419
|
+
...aliased,
|
|
2420
|
+
name
|
|
2421
|
+
} : base;
|
|
2422
|
+
schemaNodes.push(promotedEnums ? refPromotedEnums(node, promotedEnums) : node);
|
|
2423
|
+
}
|
|
2424
|
+
const operations = promotedEnums ? operationNodes.map((node) => refPromotedEnums(node, promotedEnums)) : operationNodes;
|
|
2425
|
+
return ast.factory.createInput({
|
|
2426
|
+
schemas: schemaNodes,
|
|
2427
|
+
operations,
|
|
2428
|
+
meta: {
|
|
2429
|
+
title: document.info?.title,
|
|
2430
|
+
description: document.info?.description,
|
|
2431
|
+
version: document.info?.version,
|
|
2432
|
+
baseURL: resolveBaseUrl({
|
|
2433
|
+
document,
|
|
2434
|
+
server
|
|
2435
|
+
}),
|
|
2436
|
+
circularNames,
|
|
2437
|
+
enumNames
|
|
2438
|
+
}
|
|
2383
2439
|
});
|
|
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
2440
|
}
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
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();
|
|
2441
|
+
return {
|
|
2442
|
+
get document() {
|
|
2443
|
+
return parsedDocument;
|
|
2444
|
+
},
|
|
2445
|
+
async validate(input, options) {
|
|
2446
|
+
await assertInputExists(input);
|
|
2447
|
+
const document = await parseDocument(input);
|
|
2449
2448
|
assertDocument(document);
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2449
|
+
await validateDocument(document, options);
|
|
2450
|
+
},
|
|
2451
|
+
async parse(source, { signal } = {}) {
|
|
2452
|
+
signal?.throwIfAborted();
|
|
2453
|
+
const cached = inputCache.get(source);
|
|
2454
|
+
if (cached) return cached;
|
|
2455
|
+
const promise = (async () => {
|
|
2456
|
+
const document = await parseFromConfig(source);
|
|
2457
|
+
signal?.throwIfAborted();
|
|
2458
|
+
assertDocument(document);
|
|
2459
|
+
if (validate) await validateDocument(document);
|
|
2460
|
+
parsedDocument = document;
|
|
2461
|
+
const refs = createRefs(document);
|
|
2462
|
+
const { schemas, renames } = getSchemas(document, { contentType }, refs);
|
|
2463
|
+
return parseInput({
|
|
2459
2464
|
document,
|
|
2460
2465
|
refs,
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2466
|
+
schemas,
|
|
2467
|
+
parser: createSchemaParser({
|
|
2468
|
+
document,
|
|
2469
|
+
refs,
|
|
2470
|
+
renames,
|
|
2471
|
+
options: parserOptions
|
|
2472
|
+
})
|
|
2473
|
+
});
|
|
2474
|
+
})();
|
|
2475
|
+
inputCache.set(source, promise);
|
|
2476
|
+
return promise.catch((error) => {
|
|
2477
|
+
if (signal?.aborted) inputCache.delete(source);
|
|
2478
|
+
throw error;
|
|
2464
2479
|
});
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
if (signal?.aborted) inputCache.delete(source);
|
|
2469
|
-
throw error;
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
};
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2473
2483
|
});
|
|
2474
2484
|
//#endregion
|
|
2475
2485
|
export { adapterOas, adapterOasName };
|