@kubb/adapter-oas 5.0.0-beta.94 → 5.0.0-beta.96
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 +21 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -21
- package/dist/index.js +22 -29
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1037,7 +1037,7 @@ function resolveSchemaRef(document, schema) {
|
|
|
1037
1037
|
*
|
|
1038
1038
|
* @example
|
|
1039
1039
|
* ```ts
|
|
1040
|
-
* const { schemas,
|
|
1040
|
+
* const { schemas, renames } = getSchemas(document, { contentType: 'application/json' })
|
|
1041
1041
|
* ```
|
|
1042
1042
|
*/
|
|
1043
1043
|
function getSchemas(document, { contentType }) {
|
|
@@ -1062,7 +1062,7 @@ function getSchemas(document, { contentType }) {
|
|
|
1062
1062
|
normalizedNames.set(key, bucket);
|
|
1063
1063
|
}
|
|
1064
1064
|
const schemas = {};
|
|
1065
|
-
const
|
|
1065
|
+
const renames = /* @__PURE__ */ new Map();
|
|
1066
1066
|
for (const [, items] of normalizedNames) {
|
|
1067
1067
|
const isSingle = items.length === 1;
|
|
1068
1068
|
let hasMultipleSources = false;
|
|
@@ -1077,12 +1077,12 @@ function getSchemas(document, { contentType }) {
|
|
|
1077
1077
|
const suffix = isSingle ? "" : hasMultipleSources ? semanticSuffixes[item.source] : index === 0 ? "" : String(index + 1);
|
|
1078
1078
|
const uniqueName = item.originalName + suffix;
|
|
1079
1079
|
schemas[uniqueName] = item.schema;
|
|
1080
|
-
|
|
1080
|
+
if (suffix) renames.set(`#/components/${item.source}/${item.originalName}`, uniqueName);
|
|
1081
1081
|
});
|
|
1082
1082
|
}
|
|
1083
1083
|
return {
|
|
1084
1084
|
schemas: sortSchemas(schemas),
|
|
1085
|
-
|
|
1085
|
+
renames
|
|
1086
1086
|
};
|
|
1087
1087
|
}
|
|
1088
1088
|
/**
|
|
@@ -1248,18 +1248,20 @@ function nameEnums(node, options) {
|
|
|
1248
1248
|
* Use `syncSchemaRef(node)` in printers to get a merged view of both.
|
|
1249
1249
|
* Circular refs are detected in `resolveRefNode` and leave `schema` as `null`.
|
|
1250
1250
|
*/
|
|
1251
|
-
function convertRef({ schema, name, nullable, defaultValue, rawOptions, document, resolveRefNode, refExists }) {
|
|
1251
|
+
function convertRef({ schema, name, nullable, defaultValue, rawOptions, document, resolveRefNode, refExists, renames }) {
|
|
1252
1252
|
const refPath = schema.$ref;
|
|
1253
1253
|
const resolvedSchema = refPath ? resolveRefNode(refPath, rawOptions) : null;
|
|
1254
1254
|
if (refPath && document.components && !refExists(refPath)) return _kubb_ast.ast.factory.createSchema({
|
|
1255
1255
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1256
1256
|
type: "unknown"
|
|
1257
1257
|
});
|
|
1258
|
+
const targetName = renames?.get(schema.$ref);
|
|
1258
1259
|
return _kubb_ast.ast.factory.createSchema({
|
|
1259
1260
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1260
1261
|
type: "ref",
|
|
1261
1262
|
name: (0, _kubb_ast.extractRefName)(schema.$ref),
|
|
1262
1263
|
ref: schema.$ref,
|
|
1264
|
+
...targetName ? { targetName } : {},
|
|
1263
1265
|
schema: resolvedSchema
|
|
1264
1266
|
});
|
|
1265
1267
|
}
|
|
@@ -1900,7 +1902,8 @@ function createSchemaParser(ctx) {
|
|
|
1900
1902
|
parse: parseSchema,
|
|
1901
1903
|
document,
|
|
1902
1904
|
resolveRefNode,
|
|
1903
|
-
refExists
|
|
1905
|
+
refExists,
|
|
1906
|
+
renames: ctx.renames
|
|
1904
1907
|
};
|
|
1905
1908
|
for (const rule of schemaRules) {
|
|
1906
1909
|
if (!rule.match(context)) continue;
|
|
@@ -2201,7 +2204,6 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2201
2204
|
emptySchemaType,
|
|
2202
2205
|
enumSuffix
|
|
2203
2206
|
};
|
|
2204
|
-
let nameMapping = /* @__PURE__ */ new Map();
|
|
2205
2207
|
let parsedDocument = null;
|
|
2206
2208
|
const documentCache = /* @__PURE__ */ new WeakMap();
|
|
2207
2209
|
const schemasCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -2222,16 +2224,16 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2222
2224
|
const cached = schemasCache.get(document);
|
|
2223
2225
|
if (cached) return cached;
|
|
2224
2226
|
const result = getSchemas(document, { contentType });
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
return result.schemas;
|
|
2227
|
+
schemasCache.set(document, result);
|
|
2228
|
+
return result;
|
|
2228
2229
|
}
|
|
2229
|
-
function ensureSchemaParser(document) {
|
|
2230
|
+
function ensureSchemaParser({ document, renames }) {
|
|
2230
2231
|
const cached = schemaParserCache.get(document);
|
|
2231
2232
|
if (cached) return cached;
|
|
2232
2233
|
const parser = createSchemaParser({
|
|
2233
2234
|
document,
|
|
2234
|
-
contentType
|
|
2235
|
+
contentType,
|
|
2236
|
+
renames
|
|
2235
2237
|
});
|
|
2236
2238
|
schemaParserCache.set(document, parser);
|
|
2237
2239
|
return parser;
|
|
@@ -2313,8 +2315,7 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2313
2315
|
integerType,
|
|
2314
2316
|
unknownType,
|
|
2315
2317
|
emptySchemaType,
|
|
2316
|
-
enumSuffix
|
|
2317
|
-
nameMapping
|
|
2318
|
+
enumSuffix
|
|
2318
2319
|
};
|
|
2319
2320
|
},
|
|
2320
2321
|
get document() {
|
|
@@ -2324,24 +2325,16 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2324
2325
|
await assertInputExists(input);
|
|
2325
2326
|
await validateDocument(await parseDocument(input), options);
|
|
2326
2327
|
},
|
|
2327
|
-
getImports(node, resolve) {
|
|
2328
|
-
return (0, _kubb_ast.collect)(node, { schema(schemaNode) {
|
|
2329
|
-
const schemaRef = (0, _kubb_ast.narrowSchema)(schemaNode, "ref");
|
|
2330
|
-
if (!schemaRef?.ref) return null;
|
|
2331
|
-
const result = resolve(nameMapping.get(schemaRef.ref) ?? (0, _kubb_ast.extractRefName)(schemaRef.ref));
|
|
2332
|
-
if (!result) return null;
|
|
2333
|
-
return _kubb_ast.ast.factory.createImport({
|
|
2334
|
-
name: [result.name],
|
|
2335
|
-
path: result.path
|
|
2336
|
-
});
|
|
2337
|
-
} });
|
|
2338
|
-
},
|
|
2339
2328
|
async parse(source) {
|
|
2340
2329
|
const document = await ensureDocument(source);
|
|
2330
|
+
const { schemas, renames } = ensureSchemas(document);
|
|
2341
2331
|
return parseInput({
|
|
2342
2332
|
document,
|
|
2343
|
-
schemas
|
|
2344
|
-
parser: ensureSchemaParser(
|
|
2333
|
+
schemas,
|
|
2334
|
+
parser: ensureSchemaParser({
|
|
2335
|
+
document,
|
|
2336
|
+
renames
|
|
2337
|
+
})
|
|
2345
2338
|
});
|
|
2346
2339
|
}
|
|
2347
2340
|
};
|