@kubb/adapter-oas 5.29.4 → 5.30.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 +68 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -28
- package/dist/index.js.map +1 -1
- package/docs/options.md +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var compatibility = {
|
|
|
14
14
|
"node": ">=22.22"
|
|
15
15
|
};
|
|
16
16
|
// package.json
|
|
17
|
-
var version = "5.
|
|
17
|
+
var version = "5.30.0";
|
|
18
18
|
// src/constants.ts
|
|
19
19
|
/**
|
|
20
20
|
* Default parser options applied when no explicit options are provided.
|
|
@@ -170,9 +170,6 @@ const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
|
170
170
|
*/
|
|
171
171
|
const enumDescriptionKeys = ["x-enumDescriptions", "x-enum-descriptions"];
|
|
172
172
|
// src/emit/discriminator/propagate.ts
|
|
173
|
-
function findUnion(schema) {
|
|
174
|
-
return ast.schema.narrow(schema, "union") ?? ast.schema.narrow(schema, "intersection")?.members?.map((member) => ast.schema.narrow(member, "union")).find((union) => union);
|
|
175
|
-
}
|
|
176
173
|
function pinnedValues({ objNode, propertyName }) {
|
|
177
174
|
const prop = objNode.properties.find((p) => p.name === propertyName);
|
|
178
175
|
return (prop ? ast.schema.narrow(prop.schema, "enum") : null)?.enumValues?.filter((v) => v !== null) ?? [];
|
|
@@ -192,17 +189,19 @@ function memberDiscriminant({ member, propertyName }) {
|
|
|
192
189
|
} : null;
|
|
193
190
|
}
|
|
194
191
|
/**
|
|
195
|
-
* Maps each child schema's emitted name to its discriminator patch data by scanning the given
|
|
196
|
-
*
|
|
192
|
+
* Maps each child schema's emitted name to its discriminator patch data, one entry per discriminator property, by scanning the given
|
|
193
|
+
* AST schema nodes, and the schemas nested in them, for union schemas that carry a `discriminatorPropertyName`.
|
|
194
|
+
* A union can sit at the root, inside an intersection (a union with shared properties), on a property, or on array `items`.
|
|
195
|
+
* Ref targets are not followed.
|
|
197
196
|
*
|
|
198
197
|
* Called on a small pre-parsed subset of schemas (only the discriminator parents)
|
|
199
198
|
* rather than on all schemas at once.
|
|
200
199
|
*/
|
|
201
200
|
function buildDiscriminatorChildMap(schemas) {
|
|
202
201
|
const childMap = /* @__PURE__ */ new Map();
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!unionNode
|
|
202
|
+
const unions = schemas.flatMap((schema) => ast.node.collect(schema, { schema: (node) => ast.schema.narrow(node, "union") }));
|
|
203
|
+
for (const unionNode of unions) {
|
|
204
|
+
if (!unionNode.discriminatorPropertyName || !unionNode.members) continue;
|
|
206
205
|
const propertyName = unionNode.discriminatorPropertyName;
|
|
207
206
|
for (const member of unionNode.members) {
|
|
208
207
|
const child = memberDiscriminant({
|
|
@@ -210,12 +209,14 @@ function buildDiscriminatorChildMap(schemas) {
|
|
|
210
209
|
propertyName
|
|
211
210
|
});
|
|
212
211
|
if (!child) continue;
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
const targets = childMap.get(child.name) ?? [];
|
|
213
|
+
const existing = targets.find((target) => target.propertyName === propertyName);
|
|
214
|
+
if (existing) existing.enumValues = [.../* @__PURE__ */ new Set([...existing.enumValues, ...child.enumValues])];
|
|
215
|
+
else targets.push({
|
|
216
|
+
propertyName,
|
|
217
|
+
enumValues: child.enumValues
|
|
218
218
|
});
|
|
219
|
+
childMap.set(child.name, targets);
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
return childMap;
|
|
@@ -2472,14 +2473,38 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
|
|
|
2472
2473
|
schema: resolvedSchema
|
|
2473
2474
|
});
|
|
2474
2475
|
}
|
|
2476
|
+
/**
|
|
2477
|
+
* `not`, `contains` and the `if`/`then`/`else` branches check a value and are not its type, so a subschema without a
|
|
2478
|
+
* type accepts every value there. A `void` from `emptySchemaType` or `unknownType` would reject them all, so it becomes
|
|
2479
|
+
* `unknown`, also behind a `$ref`.
|
|
2480
|
+
*/
|
|
2481
|
+
function acceptAnyValue(node) {
|
|
2482
|
+
return ast.node.transform(node, { schema: (child) => {
|
|
2483
|
+
if (child.type === ast.schema.types.void) return {
|
|
2484
|
+
...child,
|
|
2485
|
+
type: ast.schema.types.unknown,
|
|
2486
|
+
primitive: "unknown"
|
|
2487
|
+
};
|
|
2488
|
+
if (ast.ref.getSchema(child).type === ast.schema.types.void) return ast.factory.createSchema({ type: ast.schema.types.unknown });
|
|
2489
|
+
} });
|
|
2490
|
+
}
|
|
2475
2491
|
/** Converts `{ ...rest, not: X }` into `intersection[rest, not[X]]`; a bare `required` inside `not` borrows the outer `properties`. */
|
|
2476
2492
|
function convertNot({ schema, name, nullable, defaultValue, parse }) {
|
|
2477
|
-
const { not, ...rest } = schema;
|
|
2493
|
+
const { not, if: _if, then: _then, else: _else, dependentRequired: _required, dependentSchemas: _schemas, ...rest } = schema;
|
|
2478
2494
|
const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
|
|
2479
2495
|
const notNode = ast.factory.createSchema({
|
|
2480
2496
|
type: ast.schema.types.not,
|
|
2481
|
-
members: [parse({ schema: subschema })]
|
|
2497
|
+
members: [acceptAnyValue(parse({ schema: subschema }))]
|
|
2482
2498
|
});
|
|
2499
|
+
const parsedRest = parse({
|
|
2500
|
+
schema: rest,
|
|
2501
|
+
name
|
|
2502
|
+
});
|
|
2503
|
+
const restNode = parsedRest.type === ast.schema.types.void ? {
|
|
2504
|
+
...parsedRest,
|
|
2505
|
+
type: ast.schema.types.unknown,
|
|
2506
|
+
primitive: "unknown"
|
|
2507
|
+
} : parsedRest;
|
|
2483
2508
|
return createNode({
|
|
2484
2509
|
schema,
|
|
2485
2510
|
name,
|
|
@@ -2487,10 +2512,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
|
|
|
2487
2512
|
defaultValue
|
|
2488
2513
|
}, {
|
|
2489
2514
|
type: ast.schema.types.intersection,
|
|
2490
|
-
members: [
|
|
2491
|
-
schema: rest,
|
|
2492
|
-
name
|
|
2493
|
-
}), notNode]
|
|
2515
|
+
members: [restNode, notNode]
|
|
2494
2516
|
});
|
|
2495
2517
|
}
|
|
2496
2518
|
/**
|
|
@@ -2620,7 +2642,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
|
|
|
2620
2642
|
}
|
|
2621
2643
|
}
|
|
2622
2644
|
if (keepsOwnKeywords(schema)) {
|
|
2623
|
-
const { allOf: _allOf, ...schemaWithoutAllOf } = schema;
|
|
2645
|
+
const { allOf: _allOf, if: _if, then: _then, else: _else, dependentRequired: _required, dependentSchemas: _schemas, ...schemaWithoutAllOf } = schema;
|
|
2624
2646
|
allOfMembers.push(parse({ schema: schemaWithoutAllOf }));
|
|
2625
2647
|
}
|
|
2626
2648
|
for (const { propertyName, values } of discriminantValues) allOfMembers.push(createDiscriminantNode({
|
|
@@ -3889,7 +3911,7 @@ function getContains(schema, parse) {
|
|
|
3889
3911
|
const { contains, minContains, maxContains } = schema;
|
|
3890
3912
|
if (!contains || typeof contains !== "object") return {};
|
|
3891
3913
|
return { contains: {
|
|
3892
|
-
schema: parse({ schema: contains }),
|
|
3914
|
+
schema: acceptAnyValue(parse({ schema: contains })),
|
|
3893
3915
|
...typeof minContains === "number" && { min: minContains },
|
|
3894
3916
|
...typeof maxContains === "number" && { max: maxContains }
|
|
3895
3917
|
} };
|
|
@@ -4085,7 +4107,7 @@ function formatPrintsPlainType({ schema, options, type }) {
|
|
|
4085
4107
|
*/
|
|
4086
4108
|
const schemaRules = [
|
|
4087
4109
|
{
|
|
4088
|
-
match: ({ schema }) => typeof schema.not === "object" && schema.not !== null,
|
|
4110
|
+
match: ({ schema }) => schema.not === true || typeof schema.not === "object" && schema.not !== null,
|
|
4089
4111
|
convert: convertNot
|
|
4090
4112
|
},
|
|
4091
4113
|
{
|
|
@@ -4187,6 +4209,12 @@ function hasUnevaluatedSiblings(schema) {
|
|
|
4187
4209
|
schema.$ref
|
|
4188
4210
|
].some((value) => value !== void 0);
|
|
4189
4211
|
}
|
|
4212
|
+
const arrayKeywords = [
|
|
4213
|
+
"minItems",
|
|
4214
|
+
"maxItems",
|
|
4215
|
+
"uniqueItems",
|
|
4216
|
+
"contains"
|
|
4217
|
+
];
|
|
4190
4218
|
function isKeyList(value) {
|
|
4191
4219
|
return Array.isArray(value) && value.length > 0 && value.every((name) => typeof name === "string");
|
|
4192
4220
|
}
|
|
@@ -4295,10 +4323,15 @@ var SchemaParser = class {
|
|
|
4295
4323
|
return keys.includes(void 0) ? void 0 : keys.join("\n");
|
|
4296
4324
|
}
|
|
4297
4325
|
#toBranch(value) {
|
|
4326
|
+
if (typeof value === "boolean") return acceptAnyValue(this.parse({ schema: value }));
|
|
4298
4327
|
if (!value || typeof value !== "object") return void 0;
|
|
4299
4328
|
const { required, type, ...rest } = value;
|
|
4300
4329
|
if (Array.isArray(required) && required.length && (type === void 0 || type === "object") && !Object.keys(rest).length) return this.#requireKeys(required);
|
|
4301
|
-
|
|
4330
|
+
const isArrayCheck = type === void 0 && arrayKeywords.some((key) => rest[key] !== void 0);
|
|
4331
|
+
return acceptAnyValue(this.parse({ schema: isArrayCheck ? {
|
|
4332
|
+
...value,
|
|
4333
|
+
type: "array"
|
|
4334
|
+
} : value }));
|
|
4302
4335
|
}
|
|
4303
4336
|
#toConditionals(schema) {
|
|
4304
4337
|
const entries = (value) => value && typeof value === "object" ? Object.entries(value) : [];
|
|
@@ -4560,8 +4593,16 @@ var Adapter = class {
|
|
|
4560
4593
|
};
|
|
4561
4594
|
}
|
|
4562
4595
|
};
|
|
4563
|
-
|
|
4564
|
-
|
|
4596
|
+
/**
|
|
4597
|
+
* Returns `true` when the schema, or any schema nested in it, is a `oneOf`/`anyOf` with a discriminator,
|
|
4598
|
+
* such as a union declared on a property or on array `items`.
|
|
4599
|
+
*/
|
|
4600
|
+
function isDiscriminatorParent(schema, seen = /* @__PURE__ */ new WeakSet()) {
|
|
4601
|
+
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
4602
|
+
seen.add(schema);
|
|
4603
|
+
const { oneOf, anyOf, discriminator } = schema;
|
|
4604
|
+
if ((oneOf ?? anyOf) && discriminator?.propertyName) return true;
|
|
4605
|
+
return Object.values(schema).some((value) => isDiscriminatorParent(value, seen));
|
|
4565
4606
|
}
|
|
4566
4607
|
function resolveSchemaNodes({ names, parsed: { parsedByName, refAliasMap, discriminatorChildMap }, promotedEnums }) {
|
|
4567
4608
|
const aliasTargetOf = (name) => {
|
|
@@ -4582,8 +4623,7 @@ function resolveSchemaNodes({ names, parsed: { parsedByName, refAliasMap, discri
|
|
|
4582
4623
|
const aliasTarget = refAliasMap.get(name)?.name;
|
|
4583
4624
|
const aliased = aliasTarget ? parsedByName.get(aliasTarget) : void 0;
|
|
4584
4625
|
const parsed = parsedByName.get(name);
|
|
4585
|
-
const
|
|
4586
|
-
const base = child ? patchDiscriminatorNode(parsed, child) : parsed;
|
|
4626
|
+
const base = (discriminatorChildMap?.get(name) ?? []).reduce(patchDiscriminatorNode, parsed);
|
|
4587
4627
|
const resolved = aliased ? {
|
|
4588
4628
|
...aliased,
|
|
4589
4629
|
name,
|