@kubb/adapter-oas 5.0.0-beta.76 → 5.0.0-beta.78
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 +31 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -65,7 +65,7 @@ const SCHEMA_REF_PREFIX = "#/components/schemas/";
|
|
|
65
65
|
* HTTP methods that count as operations on an OpenAPI path item. Other keys
|
|
66
66
|
* (`parameters`, `summary`, `$ref`, vendor extensions) are skipped when iterating operations.
|
|
67
67
|
*/
|
|
68
|
-
const SUPPORTED_METHODS = new Set([
|
|
68
|
+
const SUPPORTED_METHODS = /* @__PURE__ */ new Set([
|
|
69
69
|
"get",
|
|
70
70
|
"put",
|
|
71
71
|
"post",
|
|
@@ -89,7 +89,7 @@ const SUPPORTED_METHODS = new Set([
|
|
|
89
89
|
* // true when fragment has e.g. 'properties' or 'oneOf'
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
const structuralKeys = new Set([
|
|
92
|
+
const structuralKeys = /* @__PURE__ */ new Set([
|
|
93
93
|
"properties",
|
|
94
94
|
"items",
|
|
95
95
|
"additionalProperties",
|
|
@@ -104,7 +104,7 @@ const structuralKeys = new Set([
|
|
|
104
104
|
* special-cases in `parser.ts`. `isHandledFormat` reads it so the
|
|
105
105
|
* `KUBB_UNSUPPORTED_FORMAT` diagnostic and the parser agree on what is handled.
|
|
106
106
|
*/
|
|
107
|
-
const specialCasedFormats = new Set([
|
|
107
|
+
const specialCasedFormats = /* @__PURE__ */ new Set([
|
|
108
108
|
"int64",
|
|
109
109
|
"date-time",
|
|
110
110
|
"date",
|
|
@@ -1014,8 +1014,8 @@ function flattenSchema(schema) {
|
|
|
1014
1014
|
const allOfFragments = schema.allOf;
|
|
1015
1015
|
if (allOfFragments.some((item) => isReference(item))) return schema;
|
|
1016
1016
|
if (allOfFragments.some(hasStructuralKeywords)) return schema;
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1017
|
+
const { allOf: _allOf, ...rest } = schema;
|
|
1018
|
+
const merged = rest;
|
|
1019
1019
|
for (const fragment of allOfFragments) for (const [key, value] of Object.entries(fragment)) if (merged[key] === void 0) merged[key] = value;
|
|
1020
1020
|
return merged;
|
|
1021
1021
|
}
|
|
@@ -1141,7 +1141,7 @@ function getSchemas(document, { contentType }) {
|
|
|
1141
1141
|
let hasMultipleSources = false;
|
|
1142
1142
|
if (!isSingle) {
|
|
1143
1143
|
const firstSource = items[0].source;
|
|
1144
|
-
for (
|
|
1144
|
+
for (const item of items) if (item.source !== firstSource) {
|
|
1145
1145
|
hasMultipleSources = true;
|
|
1146
1146
|
break;
|
|
1147
1147
|
}
|
|
@@ -1339,6 +1339,24 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1339
1339
|
*/
|
|
1340
1340
|
const resolvedRefCache = /* @__PURE__ */ new Map();
|
|
1341
1341
|
/**
|
|
1342
|
+
* Memoized record of whether a `$ref` path resolves to a node the document actually defines.
|
|
1343
|
+
* A circular ref still resolves to an existing target, so this stays `true` for cycles and only
|
|
1344
|
+
* goes `false` for a `$ref` that points at a component the spec never declares.
|
|
1345
|
+
*/
|
|
1346
|
+
const refExistence = /* @__PURE__ */ new Map();
|
|
1347
|
+
function refExists(refPath) {
|
|
1348
|
+
if (!refExistence.has(refPath)) {
|
|
1349
|
+
let exists = false;
|
|
1350
|
+
try {
|
|
1351
|
+
exists = !!dialect.schema.resolveRef(document, refPath);
|
|
1352
|
+
} catch {
|
|
1353
|
+
exists = false;
|
|
1354
|
+
}
|
|
1355
|
+
refExistence.set(refPath, exists);
|
|
1356
|
+
}
|
|
1357
|
+
return refExistence.get(refPath) ?? false;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1342
1360
|
* Converts a `$ref` schema into a `RefSchemaNode`.
|
|
1343
1361
|
*
|
|
1344
1362
|
* The resolved schema is stored in `node.schema`. Usage-site sibling fields
|
|
@@ -1363,6 +1381,10 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1363
1381
|
}
|
|
1364
1382
|
resolvedSchema = resolvedRefCache.get(refPath) ?? null;
|
|
1365
1383
|
}
|
|
1384
|
+
if (refPath && document.components && !refExists(refPath)) return _kubb_core.ast.factory.createSchema({
|
|
1385
|
+
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1386
|
+
type: "unknown"
|
|
1387
|
+
});
|
|
1366
1388
|
return _kubb_core.ast.factory.createSchema({
|
|
1367
1389
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1368
1390
|
type: "ref",
|
|
@@ -1482,7 +1504,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1482
1504
|
const variant = resolveRefSilent(member.$ref);
|
|
1483
1505
|
if (!variant) return null;
|
|
1484
1506
|
const propertyName = discriminator.propertyName;
|
|
1485
|
-
const seen = new Set([member.$ref]);
|
|
1507
|
+
const seen = /* @__PURE__ */ new Set([member.$ref]);
|
|
1486
1508
|
function constrains(v) {
|
|
1487
1509
|
const prop = v.properties?.[propertyName];
|
|
1488
1510
|
const resolved = prop && dialect.schema.isReference(prop) ? resolveRefSilent(prop.$ref) : prop;
|
|
@@ -2133,7 +2155,6 @@ function collectInlineEnums(roots, topLevelNames) {
|
|
|
2133
2155
|
const isSchemaRoot = root.kind === "Schema";
|
|
2134
2156
|
for (const node of _kubb_core.ast.collect(root, { schema: (schemaNode) => schemaNode })) {
|
|
2135
2157
|
if (node.type !== "enum" || !node.name) continue;
|
|
2136
|
-
if ((node.namedEnumValues ?? node.enumValues ?? []).length === 1) continue;
|
|
2137
2158
|
if (isSchemaRoot && node === root) continue;
|
|
2138
2159
|
if (topLevelNames.has(node.name)) continue;
|
|
2139
2160
|
if (!promoted.has(node.name)) promoted.set(node.name, {
|
|
@@ -2283,9 +2304,7 @@ function preScan({ schemas, parseSchema, parseOperation, document, parserOptions
|
|
|
2283
2304
|
name
|
|
2284
2305
|
});
|
|
2285
2306
|
if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
|
|
2286
|
-
|
|
2287
|
-
const isConstEnum = (enumNode?.namedEnumValues ?? enumNode?.enumValues ?? []).length === 1;
|
|
2288
|
-
if (enumNode && node.name && !isConstEnum) enumNames.push(node.name);
|
|
2307
|
+
if (_kubb_core.ast.narrowSchema(node, _kubb_core.ast.schemaTypes.enum) && node.name) enumNames.push(node.name);
|
|
2289
2308
|
if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
|
|
2290
2309
|
}
|
|
2291
2310
|
const circularNames = [...(0, _kubb_ast_utils.findCircularSchemas)(allNodes)];
|
|
@@ -2519,8 +2538,7 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2519
2538
|
return (0, _kubb_ast.collect)(node, { schema(schemaNode) {
|
|
2520
2539
|
const schemaRef = (0, _kubb_ast.narrowSchema)(schemaNode, "ref");
|
|
2521
2540
|
if (!schemaRef?.ref) return null;
|
|
2522
|
-
const
|
|
2523
|
-
const result = resolve(nameMapping.get(rawName) ?? rawName);
|
|
2541
|
+
const result = resolve(nameMapping.get(schemaRef.ref) ?? (0, _kubb_ast_utils.extractRefName)(schemaRef.ref));
|
|
2524
2542
|
if (!result) return null;
|
|
2525
2543
|
return _kubb_core.ast.factory.createImport({
|
|
2526
2544
|
name: [result.name],
|