@kubb/adapter-oas 5.18.0 → 5.18.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.cjs +61 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var compatibility = {
|
|
|
20
20
|
"node": ">=22.22"
|
|
21
21
|
};
|
|
22
22
|
// package.json
|
|
23
|
-
var version = "5.18.
|
|
23
|
+
var version = "5.18.1";
|
|
24
24
|
// src/constants.ts
|
|
25
25
|
/**
|
|
26
26
|
* Default parser options applied when no explicit options are provided.
|
|
@@ -248,7 +248,7 @@ function patchDiscriminatorNode(node, entry) {
|
|
|
248
248
|
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
249
249
|
*/
|
|
250
250
|
function convert(text, pascal) {
|
|
251
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
251
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)(?!xx(?![a-z]))([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
252
252
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
253
253
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
254
254
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
@@ -1209,8 +1209,29 @@ const semanticSuffixes = {
|
|
|
1209
1209
|
*/
|
|
1210
1210
|
function getSchemas(document, { contentType }, refs) {
|
|
1211
1211
|
const components = document.components;
|
|
1212
|
+
/**
|
|
1213
|
+
* Follows a `$ref` to the schema it ends at. Keywords next to a `$ref` apply together with its target,
|
|
1214
|
+
* so they stay on a one-member `allOf` around it.
|
|
1215
|
+
*/
|
|
1216
|
+
function inlineRef(schema, seen = /* @__PURE__ */ new Set()) {
|
|
1217
|
+
if (!isReference(schema) || seen.has(schema.$ref)) return schema;
|
|
1218
|
+
const { $ref, ...siblings } = schema;
|
|
1219
|
+
const resolved = refs.resolve($ref);
|
|
1220
|
+
if (!resolved) return schema;
|
|
1221
|
+
const target = inlineRef(resolved, seen.add($ref));
|
|
1222
|
+
if (!Object.keys(siblings).length) return target;
|
|
1223
|
+
const own = "allOf" in siblings && Array.isArray(siblings.allOf) ? siblings.allOf : [];
|
|
1224
|
+
return {
|
|
1225
|
+
...siblings,
|
|
1226
|
+
allOf: [...own, target]
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Replaces a `$ref` schema with its target. A plain `$ref` to another `$ref` stays as it is, so the parser reads it as an alias.
|
|
1231
|
+
*/
|
|
1212
1232
|
function resolveSchemaRef(schema) {
|
|
1213
1233
|
if (!isReference(schema)) return schema;
|
|
1234
|
+
if (Object.keys(schema).length > 1) return inlineRef(schema);
|
|
1214
1235
|
const resolved = refs.resolve(schema.$ref);
|
|
1215
1236
|
return resolved && !isReference(resolved) ? resolved : schema;
|
|
1216
1237
|
}
|
|
@@ -2044,12 +2065,13 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2044
2065
|
required: bodyRequired || void 0,
|
|
2045
2066
|
content: content.length > 0 ? content : void 0
|
|
2046
2067
|
} : void 0;
|
|
2047
|
-
const responses = getResponseStatusCodes(operation).map((
|
|
2068
|
+
const responses = getResponseStatusCodes(operation).map((key) => {
|
|
2048
2069
|
const response = getResponseByStatusCode({
|
|
2049
2070
|
operation,
|
|
2050
2071
|
refs,
|
|
2051
|
-
statusCode
|
|
2072
|
+
statusCode: key
|
|
2052
2073
|
});
|
|
2074
|
+
const statusCode = key.toLowerCase();
|
|
2053
2075
|
const responseName = operationName ? `${operationName}Status${statusCode}` : void 0;
|
|
2054
2076
|
const parseEntrySchema = (ct) => {
|
|
2055
2077
|
const raw = getBodySchema({
|
|
@@ -2067,7 +2089,7 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2067
2089
|
schema: raw,
|
|
2068
2090
|
name: responseName
|
|
2069
2091
|
}) : ast.factory.createSchema({ type: options.emptySchemaType });
|
|
2070
|
-
if (raw && ct) scanSchema(node, `${mediaTypePointer(response?.content, ct, `${pointer}/responses/${
|
|
2092
|
+
if (raw && ct) scanSchema(node, `${mediaTypePointer(response?.content, ct, `${pointer}/responses/${key}/content/${escapePointerToken(ct)}`)}/${schemaKeyword(mediaType)}`);
|
|
2071
2093
|
return {
|
|
2072
2094
|
schema: node,
|
|
2073
2095
|
keysToOmit: collectPropertyKeysByFlag(raw, "writeOnly"),
|
|
@@ -2091,7 +2113,7 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2091
2113
|
contentType: "",
|
|
2092
2114
|
...parseEntrySchema(contentType)
|
|
2093
2115
|
}));
|
|
2094
|
-
const responsePointer = `${pointer}/responses/${
|
|
2116
|
+
const responsePointer = `${pointer}/responses/${key}`;
|
|
2095
2117
|
const headers = Object.entries(response?.headers ?? {}).flatMap(([name, value]) => {
|
|
2096
2118
|
const header = name.toLowerCase() === "content-type" ? null : refs.deref(value);
|
|
2097
2119
|
if (!header) return [];
|
|
@@ -2125,7 +2147,7 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2125
2147
|
const fallback = operation.pathItem[key];
|
|
2126
2148
|
return typeof fallback === "string" ? fallback : void 0;
|
|
2127
2149
|
};
|
|
2128
|
-
const servers = operation.schema.servers
|
|
2150
|
+
const servers = operation.schema.servers?.length ? operation.schema.servers : operation.pathItem.servers;
|
|
2129
2151
|
const auth = toAuthRequirements(operation.schema.security ?? document.security, document);
|
|
2130
2152
|
return ast.factory.createOperation({
|
|
2131
2153
|
pointer,
|
|
@@ -3391,10 +3413,13 @@ function createSchemaParser(ctx) {
|
|
|
3391
3413
|
};
|
|
3392
3414
|
function parseSchema({ schema, name }) {
|
|
3393
3415
|
const flattenedSchema = flattenSchema(schema);
|
|
3394
|
-
if (flattenedSchema !== schema)
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3416
|
+
if (flattenedSchema !== schema) {
|
|
3417
|
+
const { if: _if, then: _then, else: _else, dependentRequired: _required, dependentSchemas: _schemas, ...shape } = flattenedSchema;
|
|
3418
|
+
return withConditionals(parseSchema({
|
|
3419
|
+
schema: shape,
|
|
3420
|
+
name
|
|
3421
|
+
}), [schema, ...schema.allOf]);
|
|
3422
|
+
}
|
|
3398
3423
|
if (hasUnevaluatedSiblings(schema)) {
|
|
3399
3424
|
const { unevaluatedProperties: _properties, unevaluatedItems: _items, ...open } = schema;
|
|
3400
3425
|
return parseSchema({
|
|
@@ -3416,11 +3441,12 @@ function createSchemaParser(ctx) {
|
|
|
3416
3441
|
renames
|
|
3417
3442
|
};
|
|
3418
3443
|
const rule = schemaRules.find((entry) => entry.match(context));
|
|
3419
|
-
return withConditionals(rule ? rule.convert(context) : createNode(context, { type: options.emptySchemaType }), schema);
|
|
3444
|
+
return withConditionals(rule ? rule.convert(context) : createNode(context, { type: options.emptySchemaType }), [schema, ...Array.isArray(schema.allOf) ? schema.allOf.filter(isAnnotationMember) : []]);
|
|
3420
3445
|
}
|
|
3446
|
+
const presenceKeys = /* @__PURE__ */ new WeakMap();
|
|
3421
3447
|
function requireKeys(keys) {
|
|
3422
3448
|
const unknown = ast.factory.createSchema({ type: ast.schemaTypes.unknown });
|
|
3423
|
-
|
|
3449
|
+
const node = ast.factory.createSchema({
|
|
3424
3450
|
type: ast.schemaTypes.object,
|
|
3425
3451
|
primitive: "object",
|
|
3426
3452
|
properties: keys.map((name) => ast.factory.createProperty({
|
|
@@ -3429,17 +3455,35 @@ function createSchemaParser(ctx) {
|
|
|
3429
3455
|
schema: unknown
|
|
3430
3456
|
}))
|
|
3431
3457
|
});
|
|
3458
|
+
presenceKeys.set(node, keys.join("\0"));
|
|
3459
|
+
return node;
|
|
3432
3460
|
}
|
|
3433
3461
|
/**
|
|
3434
3462
|
* Adds `if`/`then`/`else`, `dependentRequired` and `dependentSchemas` to the node as `conditionals`.
|
|
3435
3463
|
*/
|
|
3436
|
-
function withConditionals(node,
|
|
3437
|
-
const conditionals =
|
|
3438
|
-
|
|
3464
|
+
function withConditionals(node, sources) {
|
|
3465
|
+
const conditionals = sources.flatMap(toConditionals);
|
|
3466
|
+
const existing = new Set((node.conditionals ?? []).map(presenceKey));
|
|
3467
|
+
const added = conditionals.filter((entry) => {
|
|
3468
|
+
const key = presenceKey(entry);
|
|
3469
|
+
return key === void 0 || !existing.has(key);
|
|
3470
|
+
});
|
|
3471
|
+
return added.length ? {
|
|
3439
3472
|
...node,
|
|
3440
|
-
conditionals
|
|
3473
|
+
conditionals: [...node.conditionals ?? [], ...added]
|
|
3441
3474
|
} : node;
|
|
3442
3475
|
}
|
|
3476
|
+
/**
|
|
3477
|
+
* The keys an entry checks for presence, or `undefined` when a branch checks more than presence and the entry is always kept.
|
|
3478
|
+
*/
|
|
3479
|
+
function presenceKey({ if: condition, then: thenNode, else: elseNode }) {
|
|
3480
|
+
const keys = [
|
|
3481
|
+
condition,
|
|
3482
|
+
thenNode,
|
|
3483
|
+
elseNode
|
|
3484
|
+
].map((branch) => branch ? presenceKeys.get(branch) : "");
|
|
3485
|
+
return keys.includes(void 0) ? void 0 : keys.join("\n");
|
|
3486
|
+
}
|
|
3443
3487
|
function toConditionals(schema) {
|
|
3444
3488
|
const branch = (value) => {
|
|
3445
3489
|
if (!value || typeof value !== "object") return void 0;
|