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