@kubb/adapter-oas 5.0.0-alpha.15 → 5.0.0-alpha.16
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 +157 -343
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +151 -341
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +1 -1
- package/src/constants.ts +0 -49
- package/src/discriminator.ts +25 -0
- package/src/infer.ts +85 -0
- package/src/naming.ts +25 -0
- package/src/oas/types.ts +10 -4
- package/src/parser.ts +122 -323
- package/src/refResolver.ts +65 -0
- package/src/utils.ts +0 -168
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
6
|
+
value,
|
|
7
|
+
configurable: true
|
|
8
|
+
});
|
|
5
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -104,44 +108,10 @@ const formatMap = {
|
|
|
104
108
|
double: "number"
|
|
105
109
|
};
|
|
106
110
|
/**
|
|
107
|
-
* Exhaustive list of media types that Kubb recognizes.
|
|
108
|
-
*/
|
|
109
|
-
const knownMediaTypes = new Set([
|
|
110
|
-
"application/json",
|
|
111
|
-
"application/xml",
|
|
112
|
-
"application/x-www-form-urlencoded",
|
|
113
|
-
"application/octet-stream",
|
|
114
|
-
"application/pdf",
|
|
115
|
-
"application/zip",
|
|
116
|
-
"application/graphql",
|
|
117
|
-
"multipart/form-data",
|
|
118
|
-
"text/plain",
|
|
119
|
-
"text/html",
|
|
120
|
-
"text/csv",
|
|
121
|
-
"text/xml",
|
|
122
|
-
"image/png",
|
|
123
|
-
"image/jpeg",
|
|
124
|
-
"image/gif",
|
|
125
|
-
"image/webp",
|
|
126
|
-
"image/svg+xml",
|
|
127
|
-
"audio/mpeg",
|
|
128
|
-
"video/mp4"
|
|
129
|
-
]);
|
|
130
|
-
/**
|
|
131
111
|
* Vendor extension keys used to attach human-readable labels to enum values.
|
|
132
112
|
* Checked in priority order: the first key found wins.
|
|
133
113
|
*/
|
|
134
114
|
const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
135
|
-
/**
|
|
136
|
-
* Scalar primitive schema types used for union member simplification.
|
|
137
|
-
*/
|
|
138
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
139
|
-
"string",
|
|
140
|
-
"number",
|
|
141
|
-
"integer",
|
|
142
|
-
"bigint",
|
|
143
|
-
"boolean"
|
|
144
|
-
]);
|
|
145
115
|
//#endregion
|
|
146
116
|
//#region src/oas/resolveServerUrl.ts
|
|
147
117
|
/**
|
|
@@ -944,127 +914,59 @@ function resolveCollisions(schemasWithMeta) {
|
|
|
944
914
|
};
|
|
945
915
|
}
|
|
946
916
|
//#endregion
|
|
947
|
-
//#region src/
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
* Falls back to the full ref string when no slash is present.
|
|
952
|
-
*/
|
|
953
|
-
function extractRefName($ref) {
|
|
954
|
-
return $ref.split("/").at(-1) ?? $ref;
|
|
917
|
+
//#region src/discriminator.ts
|
|
918
|
+
function resolveDiscriminatorValue(mapping, ref) {
|
|
919
|
+
if (!mapping || !ref) return void 0;
|
|
920
|
+
return Object.entries(mapping).find(([, value]) => value === ref)?.[0];
|
|
955
921
|
}
|
|
956
|
-
|
|
957
|
-
* Replaces the discriminator property's schema inside an `ObjectSchemaNode`
|
|
958
|
-
* with an enum of the given `values`.
|
|
959
|
-
*
|
|
960
|
-
* - When `enumName` is provided the enum is named, which lets printers emit a
|
|
961
|
-
* standalone enum declaration + type reference (e.g. `PetTypeEnum`).
|
|
962
|
-
* - When `enumName` is omitted the enum stays anonymous, so printers inline it
|
|
963
|
-
* as a literal union (e.g. `'dog'`).
|
|
964
|
-
*
|
|
965
|
-
* Returns the node unchanged when it is not an object or lacks the target property.
|
|
966
|
-
*/
|
|
967
|
-
function applyDiscriminatorEnum({ node, propertyName, values, enumName }) {
|
|
968
|
-
if (node.type !== "object" || !node.properties?.length) return node;
|
|
969
|
-
if (!node.properties.some((prop) => prop.name === propertyName)) return node;
|
|
922
|
+
function createDiscriminantNode(propertyName, value) {
|
|
970
923
|
return (0, _kubb_ast.createSchema)({
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
924
|
+
type: "object",
|
|
925
|
+
primitive: "object",
|
|
926
|
+
properties: [(0, _kubb_ast.createProperty)({
|
|
927
|
+
name: propertyName,
|
|
928
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
975
929
|
type: "enum",
|
|
976
930
|
primitive: "string",
|
|
977
|
-
enumValues:
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
return (0, _kubb_ast.createProperty)({
|
|
983
|
-
...prop,
|
|
984
|
-
schema: enumSchema
|
|
985
|
-
});
|
|
986
|
-
})
|
|
931
|
+
enumValues: [value]
|
|
932
|
+
}),
|
|
933
|
+
required: true
|
|
934
|
+
})]
|
|
987
935
|
});
|
|
988
936
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
* Only adjacent pairs are merged — non-object or named nodes act as boundaries.
|
|
994
|
-
* This collapses patterns like `Address & { streetNumber } & { streetName }` into
|
|
995
|
-
* `Address & { streetNumber; streetName }`.
|
|
996
|
-
*/
|
|
997
|
-
function mergeAdjacentAnonymousObjects(members) {
|
|
998
|
-
return members.reduce((acc, member) => {
|
|
999
|
-
const obj = (0, _kubb_ast.narrowSchema)(member, "object");
|
|
1000
|
-
if (obj && !obj.name) {
|
|
1001
|
-
const prev = acc[acc.length - 1];
|
|
1002
|
-
const prevObj = prev ? (0, _kubb_ast.narrowSchema)(prev, "object") : null;
|
|
1003
|
-
if (prevObj && !prevObj.name) {
|
|
1004
|
-
acc[acc.length - 1] = (0, _kubb_ast.createSchema)({
|
|
1005
|
-
...prevObj,
|
|
1006
|
-
properties: [...prevObj.properties ?? [], ...obj.properties ?? []]
|
|
1007
|
-
});
|
|
1008
|
-
return acc;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
acc.push(member);
|
|
1012
|
-
return acc;
|
|
1013
|
-
}, []);
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/naming.ts
|
|
939
|
+
function resolveChildName(parentName, propName) {
|
|
940
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
|
|
1014
941
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
*
|
|
1022
|
-
* Only scalar primitives (`string`, `number`, `integer`, `bigint`, `boolean`) are
|
|
1023
|
-
* considered — object, array, and ref members are left untouched.
|
|
1024
|
-
*
|
|
1025
|
-
* Const-derived enums (those without an `enumType`, produced from an OpenAPI `const`
|
|
1026
|
-
* keyword) are **never** removed — `'accepted' | string` must stay as-is because the
|
|
1027
|
-
* literal is intentional.
|
|
1028
|
-
*/
|
|
1029
|
-
function simplifyUnionMembers(members) {
|
|
1030
|
-
const scalarPrimitives = new Set(members.filter((m) => SCALAR_PRIMITIVE_TYPES.has(m.type)).map((m) => m.type));
|
|
1031
|
-
if (!scalarPrimitives.size) return members;
|
|
1032
|
-
return members.filter((m) => {
|
|
1033
|
-
if (m.type !== "enum") return true;
|
|
1034
|
-
const prim = m.primitive;
|
|
1035
|
-
if (!prim) return true;
|
|
1036
|
-
if (!m.enumType) return true;
|
|
1037
|
-
if (scalarPrimitives.has(prim)) return false;
|
|
1038
|
-
if ((prim === "integer" || prim === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
|
|
1039
|
-
return true;
|
|
1040
|
-
});
|
|
942
|
+
function resolveEnumPropName(parentName, propName, enumSuffix) {
|
|
943
|
+
return pascalCase([
|
|
944
|
+
parentName,
|
|
945
|
+
propName,
|
|
946
|
+
enumSuffix
|
|
947
|
+
].filter(Boolean).join(" "));
|
|
1041
948
|
}
|
|
949
|
+
function applyEnumName(propNode, parentName, propName, enumSuffix) {
|
|
950
|
+
const enumNode = (0, _kubb_ast.narrowSchema)(propNode, "enum");
|
|
951
|
+
if (enumNode?.primitive === "boolean") return {
|
|
952
|
+
...propNode,
|
|
953
|
+
name: void 0
|
|
954
|
+
};
|
|
955
|
+
if (enumNode) return {
|
|
956
|
+
...propNode,
|
|
957
|
+
name: resolveEnumPropName(parentName, propName, enumSuffix)
|
|
958
|
+
};
|
|
959
|
+
return propNode;
|
|
960
|
+
}
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/refResolver.ts
|
|
1042
963
|
/**
|
|
1043
|
-
*
|
|
1044
|
-
* each import. When `oas` is supplied, only `$ref`s that are resolvable in the
|
|
1045
|
-
* spec are included; omit it to skip the existence check.
|
|
1046
|
-
*
|
|
1047
|
-
* This function is the pure, state-free alternative to `OasParser.getImports`.
|
|
1048
|
-
* Because it receives `nameMapping` explicitly it can be called without holding
|
|
1049
|
-
* a reference to the parser or the OAS instance.
|
|
1050
|
-
*
|
|
1051
|
-
* @example
|
|
1052
|
-
* ```ts
|
|
1053
|
-
* // Use adapter state directly — no parser reference needed
|
|
1054
|
-
* const imports = getImports({
|
|
1055
|
-
* node: schemaNode,
|
|
1056
|
-
* nameMapping: adapter.options.nameMapping,
|
|
1057
|
-
* resolve: (schemaName) => ({
|
|
1058
|
-
* name: schemaManager.getName(schemaName, { type: 'type' }),
|
|
1059
|
-
* path: schemaManager.getFile(schemaName).path,
|
|
1060
|
-
* }),
|
|
1061
|
-
* })
|
|
1062
|
-
* ```
|
|
964
|
+
* Collects import entries for all `ref` schema nodes in `node`.
|
|
1063
965
|
*/
|
|
1064
966
|
function getImports({ node, nameMapping, resolve }) {
|
|
1065
967
|
return (0, _kubb_ast.collect)(node, { schema(schemaNode) {
|
|
1066
968
|
if (schemaNode.type !== "ref" || !schemaNode.ref) return;
|
|
1067
|
-
const rawName = extractRefName(schemaNode.ref);
|
|
969
|
+
const rawName = (0, _kubb_ast.extractRefName)(schemaNode.ref);
|
|
1068
970
|
const result = resolve(nameMapping.get(rawName) ?? rawName);
|
|
1069
971
|
if (!result) return;
|
|
1070
972
|
return {
|
|
@@ -1073,6 +975,29 @@ function getImports({ node, nameMapping, resolve }) {
|
|
|
1073
975
|
};
|
|
1074
976
|
} });
|
|
1075
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* Walks a schema tree and resolves `ref`/`enum` names through callbacks.
|
|
980
|
+
*/
|
|
981
|
+
function resolveRefs({ node, nameMapping, resolveName, resolveEnumName }) {
|
|
982
|
+
return (0, _kubb_ast.transform)(node, { schema(schemaNode) {
|
|
983
|
+
const schemaRef = (0, _kubb_ast.narrowSchema)(schemaNode, _kubb_ast.schemaTypes.ref);
|
|
984
|
+
if (schemaRef && (schemaRef.ref || schemaRef.name)) {
|
|
985
|
+
const rawRef = schemaRef.ref ?? schemaRef.name;
|
|
986
|
+
const resolved = resolveName(nameMapping.get(rawRef) ?? rawRef);
|
|
987
|
+
if (resolved) return {
|
|
988
|
+
...schemaNode,
|
|
989
|
+
name: resolved
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
if (schemaNode.type === "enum" && schemaNode.name) {
|
|
993
|
+
const resolved = (resolveEnumName ?? resolveName)(schemaNode.name);
|
|
994
|
+
if (resolved) return {
|
|
995
|
+
...schemaNode,
|
|
996
|
+
name: resolved
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
} });
|
|
1000
|
+
}
|
|
1076
1001
|
//#endregion
|
|
1077
1002
|
//#region src/parser.ts
|
|
1078
1003
|
/**
|
|
@@ -1098,7 +1023,7 @@ function getPrimitiveType(type) {
|
|
|
1098
1023
|
* Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
|
|
1099
1024
|
*/
|
|
1100
1025
|
function toMediaType(contentType) {
|
|
1101
|
-
return
|
|
1026
|
+
return Object.values(_kubb_ast.mediaTypes).includes(contentType) ? contentType : void 0;
|
|
1102
1027
|
}
|
|
1103
1028
|
/**
|
|
1104
1029
|
* Creates an OAS parser that converts an OpenAPI/Swagger spec into
|
|
@@ -1121,14 +1046,28 @@ function toMediaType(contentType) {
|
|
|
1121
1046
|
*/
|
|
1122
1047
|
function createOasParser(oas, { contentType } = {}) {
|
|
1123
1048
|
const { schemas: schemaObjects, nameMapping } = oas.getSchemas({ contentType });
|
|
1049
|
+
const TYPE_OPTION_MAP = {
|
|
1050
|
+
any: _kubb_ast.schemaTypes.any,
|
|
1051
|
+
unknown: _kubb_ast.schemaTypes.unknown,
|
|
1052
|
+
void: _kubb_ast.schemaTypes.void
|
|
1053
|
+
};
|
|
1124
1054
|
/**
|
|
1125
1055
|
* Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
|
|
1126
1056
|
* Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
|
|
1127
1057
|
*/
|
|
1128
1058
|
function resolveTypeOption(value) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1059
|
+
return TYPE_OPTION_MAP[value];
|
|
1060
|
+
}
|
|
1061
|
+
function normalizeArrayEnum(schema) {
|
|
1062
|
+
const normalizedItems = {
|
|
1063
|
+
...typeof schema.items === "object" && !Array.isArray(schema.items) ? schema.items : {},
|
|
1064
|
+
enum: schema.enum
|
|
1065
|
+
};
|
|
1066
|
+
const { enum: _enum, ...schemaWithoutEnum } = schema;
|
|
1067
|
+
return {
|
|
1068
|
+
...schemaWithoutEnum,
|
|
1069
|
+
items: normalizedItems
|
|
1070
|
+
};
|
|
1132
1071
|
}
|
|
1133
1072
|
/**
|
|
1134
1073
|
* Resolves the AST type and datetime modifiers for a date/time format, honoring the `dateType` option.
|
|
@@ -1190,7 +1129,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1190
1129
|
function convertRef({ schema, nullable, defaultValue }) {
|
|
1191
1130
|
return (0, _kubb_ast.createSchema)({
|
|
1192
1131
|
type: "ref",
|
|
1193
|
-
name: extractRefName(schema.$ref),
|
|
1132
|
+
name: (0, _kubb_ast.extractRefName)(schema.$ref),
|
|
1194
1133
|
ref: schema.$ref,
|
|
1195
1134
|
nullable,
|
|
1196
1135
|
description: schema.description,
|
|
@@ -1217,10 +1156,10 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1217
1156
|
* Circular references through discriminator parents are detected and skipped to prevent
|
|
1218
1157
|
* infinite recursion during code generation.
|
|
1219
1158
|
*/
|
|
1220
|
-
function convertAllOf({ schema, name, nullable, defaultValue,
|
|
1159
|
+
function convertAllOf({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1221
1160
|
if (schema.allOf.length === 1 && !schema.properties && !(Array.isArray(schema.required) && schema.required.length) && schema.additionalProperties === void 0) {
|
|
1222
1161
|
const [memberSchema] = schema.allOf;
|
|
1223
|
-
const memberNode = convertSchema({ schema: memberSchema },
|
|
1162
|
+
const memberNode = convertSchema({ schema: memberSchema }, rawOptions);
|
|
1224
1163
|
const { kind: _kind, ...memberNodeProps } = memberNode;
|
|
1225
1164
|
const mergedNullable = nullable || memberNode.nullable || void 0;
|
|
1226
1165
|
const mergedDefault = schema.default === null && mergedNullable ? void 0 : schema.default ?? memberNode.default;
|
|
@@ -1249,7 +1188,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1249
1188
|
const inOneOf = parentUnion.some((oneOfItem) => isReference(oneOfItem) && oneOfItem.$ref === childRef);
|
|
1250
1189
|
const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef);
|
|
1251
1190
|
if (inOneOf || inMapping) {
|
|
1252
|
-
const discriminatorValue =
|
|
1191
|
+
const discriminatorValue = resolveDiscriminatorValue(deref.discriminator.mapping, childRef);
|
|
1253
1192
|
if (discriminatorValue) filteredDiscriminantValues.push({
|
|
1254
1193
|
propertyName: deref.discriminator.propertyName,
|
|
1255
1194
|
value: discriminatorValue
|
|
@@ -1257,7 +1196,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1257
1196
|
return false;
|
|
1258
1197
|
}
|
|
1259
1198
|
return true;
|
|
1260
|
-
}).map((s) => convertSchema({ schema: s },
|
|
1199
|
+
}).map((s) => convertSchema({ schema: s }, rawOptions));
|
|
1261
1200
|
const syntheticStart = allOfMembers.length;
|
|
1262
1201
|
if (Array.isArray(schema.required) && schema.required.length) {
|
|
1263
1202
|
const outerKeys = schema.properties ? new Set(Object.keys(schema.properties)) : /* @__PURE__ */ new Set();
|
|
@@ -1272,31 +1211,19 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1272
1211
|
allOfMembers.push(convertSchema({ schema: {
|
|
1273
1212
|
properties: { [key]: resolved.properties[key] },
|
|
1274
1213
|
required: [key]
|
|
1275
|
-
} },
|
|
1214
|
+
} }, rawOptions));
|
|
1276
1215
|
break;
|
|
1277
1216
|
}
|
|
1278
1217
|
}
|
|
1279
1218
|
}
|
|
1280
1219
|
if (schema.properties) {
|
|
1281
1220
|
const { allOf: _allOf, ...schemaWithoutAllOf } = schema;
|
|
1282
|
-
allOfMembers.push(convertSchema({ schema: schemaWithoutAllOf },
|
|
1221
|
+
allOfMembers.push(convertSchema({ schema: schemaWithoutAllOf }, rawOptions));
|
|
1283
1222
|
}
|
|
1284
|
-
for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push((
|
|
1285
|
-
type: "object",
|
|
1286
|
-
primitive: "object",
|
|
1287
|
-
properties: [(0, _kubb_ast.createProperty)({
|
|
1288
|
-
name: propertyName,
|
|
1289
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
1290
|
-
type: "enum",
|
|
1291
|
-
primitive: "string",
|
|
1292
|
-
enumValues: [value]
|
|
1293
|
-
}),
|
|
1294
|
-
required: true
|
|
1295
|
-
})]
|
|
1296
|
-
}));
|
|
1223
|
+
for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push(createDiscriminantNode(propertyName, value));
|
|
1297
1224
|
return (0, _kubb_ast.createSchema)({
|
|
1298
1225
|
type: "intersection",
|
|
1299
|
-
members: [...mergeAdjacentAnonymousObjects(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentAnonymousObjects(allOfMembers.slice(syntheticStart))],
|
|
1226
|
+
members: [...(0, _kubb_ast.mergeAdjacentAnonymousObjects)(allOfMembers.slice(0, syntheticStart)), ...(0, _kubb_ast.mergeAdjacentAnonymousObjects)(allOfMembers.slice(syntheticStart))],
|
|
1300
1227
|
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
1301
1228
|
});
|
|
1302
1229
|
}
|
|
@@ -1308,69 +1235,46 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1308
1235
|
* individually intersected with the shared properties node to match the OAS pattern of
|
|
1309
1236
|
* adding common fields next to a discriminated union.
|
|
1310
1237
|
*/
|
|
1311
|
-
function convertUnion({ schema, name, nullable, defaultValue,
|
|
1238
|
+
function convertUnion({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1312
1239
|
const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
|
|
1313
1240
|
const unionBase = {
|
|
1314
1241
|
...renderSchemaBase(schema, name, nullable, defaultValue),
|
|
1315
1242
|
discriminatorPropertyName: isDiscriminator(schema) ? schema.discriminator.propertyName : void 0
|
|
1316
1243
|
};
|
|
1317
|
-
|
|
1244
|
+
const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
|
|
1245
|
+
const sharedPropertiesNode = schema.properties ? (() => {
|
|
1318
1246
|
const { oneOf: _oneOf, anyOf: _anyOf, ...schemaWithoutUnion } = schema;
|
|
1319
|
-
|
|
1320
|
-
const sharedPropertiesNode = convertSchema({
|
|
1247
|
+
return convertSchema({
|
|
1321
1248
|
schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
|
|
1322
1249
|
name
|
|
1323
|
-
},
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
...unionBase,
|
|
1327
|
-
members: unionMembers.map((s) => {
|
|
1328
|
-
const ref = isReference(s) ? s.$ref : void 0;
|
|
1329
|
-
const discriminatorValue = discriminator?.mapping && ref ? Object.entries(discriminator.mapping).find(([, v]) => v === ref)?.[0] : void 0;
|
|
1330
|
-
let propertiesNode = sharedPropertiesNode;
|
|
1331
|
-
if (discriminatorValue && discriminator) propertiesNode = applyDiscriminatorEnum({
|
|
1332
|
-
node: propertiesNode,
|
|
1333
|
-
propertyName: discriminator.propertyName,
|
|
1334
|
-
values: [discriminatorValue]
|
|
1335
|
-
});
|
|
1336
|
-
return (0, _kubb_ast.createSchema)({
|
|
1337
|
-
type: "intersection",
|
|
1338
|
-
members: [convertSchema({ schema: s }, options), propertiesNode]
|
|
1339
|
-
});
|
|
1340
|
-
})
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
|
|
1344
|
-
if (discriminator?.mapping) return (0, _kubb_ast.createSchema)({
|
|
1250
|
+
}, rawOptions);
|
|
1251
|
+
})() : void 0;
|
|
1252
|
+
if (sharedPropertiesNode || discriminator?.mapping) return (0, _kubb_ast.createSchema)({
|
|
1345
1253
|
type: "union",
|
|
1346
1254
|
...unionBase,
|
|
1347
1255
|
members: unionMembers.map((s) => {
|
|
1348
1256
|
const ref = isReference(s) ? s.$ref : void 0;
|
|
1349
|
-
const discriminatorValue =
|
|
1350
|
-
const memberNode = convertSchema({ schema: s },
|
|
1351
|
-
if (
|
|
1257
|
+
const discriminatorValue = resolveDiscriminatorValue(discriminator?.mapping, ref);
|
|
1258
|
+
const memberNode = convertSchema({ schema: s }, rawOptions);
|
|
1259
|
+
if (sharedPropertiesNode) return (0, _kubb_ast.createSchema)({
|
|
1260
|
+
type: "intersection",
|
|
1261
|
+
members: [memberNode, discriminatorValue && discriminator ? (0, _kubb_ast.applyDiscriminatorEnum)({
|
|
1262
|
+
node: sharedPropertiesNode,
|
|
1263
|
+
propertyName: discriminator.propertyName,
|
|
1264
|
+
values: [discriminatorValue]
|
|
1265
|
+
}) : sharedPropertiesNode]
|
|
1266
|
+
});
|
|
1267
|
+
if (!discriminatorValue || !discriminator) return memberNode;
|
|
1352
1268
|
return (0, _kubb_ast.createSchema)({
|
|
1353
1269
|
type: "intersection",
|
|
1354
|
-
members: [memberNode, (
|
|
1355
|
-
type: "object",
|
|
1356
|
-
primitive: "object",
|
|
1357
|
-
properties: [(0, _kubb_ast.createProperty)({
|
|
1358
|
-
name: discriminator.propertyName,
|
|
1359
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
1360
|
-
type: "enum",
|
|
1361
|
-
primitive: "string",
|
|
1362
|
-
enumValues: [discriminatorValue]
|
|
1363
|
-
}),
|
|
1364
|
-
required: true
|
|
1365
|
-
})]
|
|
1366
|
-
})]
|
|
1270
|
+
members: [memberNode, createDiscriminantNode(discriminator.propertyName, discriminatorValue)]
|
|
1367
1271
|
});
|
|
1368
1272
|
})
|
|
1369
1273
|
});
|
|
1370
1274
|
return (0, _kubb_ast.createSchema)({
|
|
1371
1275
|
type: "union",
|
|
1372
1276
|
...unionBase,
|
|
1373
|
-
members: simplifyUnionMembers(unionMembers.map((s) => convertSchema({ schema: s },
|
|
1277
|
+
members: (0, _kubb_ast.simplifyUnionMembers)(unionMembers.map((s) => convertSchema({ schema: s }, rawOptions)))
|
|
1374
1278
|
});
|
|
1375
1279
|
}
|
|
1376
1280
|
/**
|
|
@@ -1400,10 +1304,10 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1400
1304
|
* Returns `undefined` when the format should fall through to string handling
|
|
1401
1305
|
* (i.e. `format: 'date-time'` with `dateType: false`).
|
|
1402
1306
|
*/
|
|
1403
|
-
function convertFormat({ schema, name, nullable, defaultValue,
|
|
1307
|
+
function convertFormat({ schema, name, nullable, defaultValue, options }) {
|
|
1404
1308
|
const base = renderSchemaBase(schema, name, nullable, defaultValue);
|
|
1405
1309
|
if (schema.format === "int64") return (0, _kubb_ast.createSchema)({
|
|
1406
|
-
type:
|
|
1310
|
+
type: options.integerType === "bigint" ? "bigint" : "integer",
|
|
1407
1311
|
primitive: "integer",
|
|
1408
1312
|
...base,
|
|
1409
1313
|
min: schema.minimum,
|
|
@@ -1412,7 +1316,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1412
1316
|
exclusiveMaximum: typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : void 0
|
|
1413
1317
|
});
|
|
1414
1318
|
if (schema.format === "date-time" || schema.format === "date" || schema.format === "time") {
|
|
1415
|
-
const dateType = getDateType(
|
|
1319
|
+
const dateType = getDateType(options, schema.format);
|
|
1416
1320
|
if (!dateType) return void 0;
|
|
1417
1321
|
if (dateType.type === "datetime") return (0, _kubb_ast.createSchema)({
|
|
1418
1322
|
...base,
|
|
@@ -1457,28 +1361,19 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1457
1361
|
* - Numeric and boolean enums require a const-map representation because most generators cannot
|
|
1458
1362
|
* use string-enum syntax for non-string values.
|
|
1459
1363
|
*/
|
|
1460
|
-
function convertEnum({ schema, name, nullable, type,
|
|
1461
|
-
if (type === "array") {
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
};
|
|
1466
|
-
const { enum: _enum, ...schemaWithoutEnum } = schema;
|
|
1467
|
-
return convertSchema({
|
|
1468
|
-
schema: {
|
|
1469
|
-
...schemaWithoutEnum,
|
|
1470
|
-
items: normalizedItems
|
|
1471
|
-
},
|
|
1472
|
-
name
|
|
1473
|
-
}, options);
|
|
1474
|
-
}
|
|
1364
|
+
function convertEnum({ schema, name, nullable, type, rawOptions }) {
|
|
1365
|
+
if (type === "array") return convertSchema({
|
|
1366
|
+
schema: normalizeArrayEnum(schema),
|
|
1367
|
+
name
|
|
1368
|
+
}, rawOptions);
|
|
1475
1369
|
const nullInEnum = schema.enum.includes(null);
|
|
1476
1370
|
const filteredValues = nullInEnum ? schema.enum.filter((v) => v !== null) : schema.enum;
|
|
1477
1371
|
const enumNullable = nullable || nullInEnum || void 0;
|
|
1478
1372
|
const enumDefault = schema.default === null && enumNullable ? void 0 : schema.default;
|
|
1373
|
+
const enumPrimitive = getPrimitiveType(type);
|
|
1479
1374
|
const enumBase = {
|
|
1480
1375
|
type: "enum",
|
|
1481
|
-
primitive:
|
|
1376
|
+
primitive: enumPrimitive,
|
|
1482
1377
|
name,
|
|
1483
1378
|
title: schema.title,
|
|
1484
1379
|
description: schema.description,
|
|
@@ -1490,38 +1385,19 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1490
1385
|
example: schema.example
|
|
1491
1386
|
};
|
|
1492
1387
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
1493
|
-
if (extensionKey) {
|
|
1494
|
-
const
|
|
1495
|
-
const
|
|
1496
|
-
const enumType = getPrimitiveType(type) === "number" || getPrimitiveType(type) === "integer" ? "number" : getPrimitiveType(type) === "boolean" ? "boolean" : "string";
|
|
1388
|
+
if (extensionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1389
|
+
const enumType = enumPrimitive === "number" || enumPrimitive === "integer" ? "number" : enumPrimitive === "boolean" ? "boolean" : "string";
|
|
1390
|
+
const sourceValues = extensionKey ? [...new Set(schema[extensionKey])] : [...new Set(filteredValues)];
|
|
1497
1391
|
return (0, _kubb_ast.createSchema)({
|
|
1498
1392
|
...enumBase,
|
|
1499
1393
|
enumType,
|
|
1500
|
-
namedEnumValues:
|
|
1394
|
+
namedEnumValues: sourceValues.map((label, index) => ({
|
|
1501
1395
|
name: String(label),
|
|
1502
|
-
value: filteredValues[index] ?? label,
|
|
1396
|
+
value: extensionKey ? filteredValues[index] ?? label : label,
|
|
1503
1397
|
format: enumType
|
|
1504
1398
|
}))
|
|
1505
1399
|
});
|
|
1506
1400
|
}
|
|
1507
|
-
if (type === "number" || type === "integer") return (0, _kubb_ast.createSchema)({
|
|
1508
|
-
...enumBase,
|
|
1509
|
-
enumType: "number",
|
|
1510
|
-
namedEnumValues: [...new Set(filteredValues)].map((value) => ({
|
|
1511
|
-
name: String(value),
|
|
1512
|
-
value,
|
|
1513
|
-
format: "number"
|
|
1514
|
-
}))
|
|
1515
|
-
});
|
|
1516
|
-
if (type === "boolean") return (0, _kubb_ast.createSchema)({
|
|
1517
|
-
...enumBase,
|
|
1518
|
-
enumType: "boolean",
|
|
1519
|
-
namedEnumValues: [...new Set(filteredValues)].map((value) => ({
|
|
1520
|
-
name: String(value),
|
|
1521
|
-
value,
|
|
1522
|
-
format: "boolean"
|
|
1523
|
-
}))
|
|
1524
|
-
});
|
|
1525
1401
|
return (0, _kubb_ast.createSchema)({
|
|
1526
1402
|
...enumBase,
|
|
1527
1403
|
enumValues: [...new Set(filteredValues)]
|
|
@@ -1539,46 +1415,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1539
1415
|
* - not required + not nullable → `optional: true`
|
|
1540
1416
|
* - not required + nullable → `nullish: true`
|
|
1541
1417
|
*/
|
|
1542
|
-
|
|
1543
|
-
* Builds the propagation name for a child property during recursive schema conversion.
|
|
1544
|
-
*
|
|
1545
|
-
* The parent name is prepended so the full path is encoded
|
|
1546
|
-
* (e.g. `OrderParams` when parent is `Order`).
|
|
1547
|
-
*/
|
|
1548
|
-
function resolveChildName(parentName, propName) {
|
|
1549
|
-
return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
|
|
1550
|
-
}
|
|
1551
|
-
/**
|
|
1552
|
-
* Derives the final name for an enum property schema node.
|
|
1553
|
-
*
|
|
1554
|
-
* The resulting name always includes the enum suffix and full parent path context
|
|
1555
|
-
* (e.g. `OrderParamsStatusEnum`).
|
|
1556
|
-
*/
|
|
1557
|
-
function resolveEnumPropName(parentName, propName, enumSuffix) {
|
|
1558
|
-
return pascalCase([
|
|
1559
|
-
parentName,
|
|
1560
|
-
propName,
|
|
1561
|
-
enumSuffix
|
|
1562
|
-
].filter(Boolean).join(" "));
|
|
1563
|
-
}
|
|
1564
|
-
/**
|
|
1565
|
-
* Given a freshly-converted property schema, returns the node with a correct
|
|
1566
|
-
* `name` attached — or stripped — depending on whether the node is a named
|
|
1567
|
-
* enum, a boolean const-enum (always inlined), or a regular schema.
|
|
1568
|
-
*/
|
|
1569
|
-
function applyEnumName(propNode, parentName, propName, enumSuffix) {
|
|
1570
|
-
const enumNode = (0, _kubb_ast.narrowSchema)(propNode, "enum");
|
|
1571
|
-
if (enumNode?.primitive === "boolean") return {
|
|
1572
|
-
...propNode,
|
|
1573
|
-
name: void 0
|
|
1574
|
-
};
|
|
1575
|
-
if (enumNode) return {
|
|
1576
|
-
...propNode,
|
|
1577
|
-
name: resolveEnumPropName(parentName, propName, enumSuffix)
|
|
1578
|
-
};
|
|
1579
|
-
return propNode;
|
|
1580
|
-
}
|
|
1581
|
-
function convertObject({ schema, name, nullable, defaultValue, options, mergedOptions }) {
|
|
1418
|
+
function convertObject({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1582
1419
|
const properties = schema.properties ? Object.entries(schema.properties).map(([propName, propSchema]) => {
|
|
1583
1420
|
const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
|
|
1584
1421
|
const resolvedPropSchema = propSchema;
|
|
@@ -1586,10 +1423,10 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1586
1423
|
let schemaNode = applyEnumName(convertSchema({
|
|
1587
1424
|
schema: resolvedPropSchema,
|
|
1588
1425
|
name: resolveChildName(name, propName)
|
|
1589
|
-
},
|
|
1426
|
+
}, rawOptions), name, propName, options.enumSuffix);
|
|
1590
1427
|
const tupleNode = (0, _kubb_ast.narrowSchema)(schemaNode, "tuple");
|
|
1591
1428
|
if (tupleNode?.items) {
|
|
1592
|
-
const namedItems = tupleNode.items.map((item) => applyEnumName(item, name, propName,
|
|
1429
|
+
const namedItems = tupleNode.items.map((item) => applyEnumName(item, name, propName, options.enumSuffix));
|
|
1593
1430
|
if (namedItems.some((item, i) => item !== tupleNode.items[i])) schemaNode = {
|
|
1594
1431
|
...tupleNode,
|
|
1595
1432
|
items: namedItems
|
|
@@ -1607,11 +1444,11 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1607
1444
|
const additionalProperties = schema.additionalProperties;
|
|
1608
1445
|
let additionalPropertiesNode;
|
|
1609
1446
|
if (additionalProperties === true) additionalPropertiesNode = true;
|
|
1610
|
-
else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = convertSchema({ schema: additionalProperties },
|
|
1447
|
+
else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = convertSchema({ schema: additionalProperties }, rawOptions);
|
|
1611
1448
|
else if (additionalProperties === false) additionalPropertiesNode = void 0;
|
|
1612
|
-
else if (additionalProperties) additionalPropertiesNode = (0, _kubb_ast.createSchema)({ type: resolveTypeOption(
|
|
1449
|
+
else if (additionalProperties) additionalPropertiesNode = (0, _kubb_ast.createSchema)({ type: resolveTypeOption(options.unknownType) });
|
|
1613
1450
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
1614
|
-
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? (0, _kubb_ast.createSchema)({ type: resolveTypeOption(
|
|
1451
|
+
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? (0, _kubb_ast.createSchema)({ type: resolveTypeOption(options.unknownType) }) : convertSchema({ schema: patternSchema }, rawOptions)])) : void 0;
|
|
1615
1452
|
const objectNode = (0, _kubb_ast.createSchema)({
|
|
1616
1453
|
type: "object",
|
|
1617
1454
|
primitive: "object",
|
|
@@ -1622,11 +1459,11 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1622
1459
|
});
|
|
1623
1460
|
if (isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
1624
1461
|
const discPropName = schema.discriminator.propertyName;
|
|
1625
|
-
return applyDiscriminatorEnum({
|
|
1462
|
+
return (0, _kubb_ast.applyDiscriminatorEnum)({
|
|
1626
1463
|
node: objectNode,
|
|
1627
1464
|
propertyName: discPropName,
|
|
1628
1465
|
values: Object.keys(schema.discriminator.mapping),
|
|
1629
|
-
enumName: name ? resolveEnumPropName(name, discPropName,
|
|
1466
|
+
enumName: name ? resolveEnumPropName(name, discPropName, options.enumSuffix) : void 0
|
|
1630
1467
|
});
|
|
1631
1468
|
}
|
|
1632
1469
|
return objectNode;
|
|
@@ -1639,12 +1476,12 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1639
1476
|
* a rest element of type `any` is emitted to match JSON Schema semantics (absent `items`
|
|
1640
1477
|
* means additional items are allowed).
|
|
1641
1478
|
*/
|
|
1642
|
-
function convertTuple({ schema, name, nullable, defaultValue,
|
|
1479
|
+
function convertTuple({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1643
1480
|
return (0, _kubb_ast.createSchema)({
|
|
1644
1481
|
type: "tuple",
|
|
1645
1482
|
primitive: "array",
|
|
1646
|
-
items: (schema.prefixItems ?? []).map((item) => convertSchema({ schema: item },
|
|
1647
|
-
rest: schema.items ? convertSchema({ schema: schema.items },
|
|
1483
|
+
items: (schema.prefixItems ?? []).map((item) => convertSchema({ schema: item }, rawOptions)),
|
|
1484
|
+
rest: schema.items ? convertSchema({ schema: schema.items }, rawOptions) : (0, _kubb_ast.createSchema)({ type: "any" }),
|
|
1648
1485
|
min: schema.minItems,
|
|
1649
1486
|
max: schema.maxItems,
|
|
1650
1487
|
...renderSchemaBase(schema, name, nullable, defaultValue)
|
|
@@ -1656,16 +1493,16 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1656
1493
|
* When the items schema is an inline enum, a name derived from the parent array's name and
|
|
1657
1494
|
* `enumSuffix` is forwarded so generators can emit a named enum declaration.
|
|
1658
1495
|
*/
|
|
1659
|
-
function convertArray({ schema, name, nullable, defaultValue,
|
|
1496
|
+
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1660
1497
|
const rawItems = schema.items;
|
|
1661
|
-
const itemName = rawItems?.enum?.length && name ? resolveEnumPropName(void 0, name,
|
|
1498
|
+
const itemName = rawItems?.enum?.length && name ? resolveEnumPropName(void 0, name, options.enumSuffix) : void 0;
|
|
1662
1499
|
return (0, _kubb_ast.createSchema)({
|
|
1663
1500
|
type: "array",
|
|
1664
1501
|
primitive: "array",
|
|
1665
1502
|
items: rawItems ? [convertSchema({
|
|
1666
1503
|
schema: rawItems,
|
|
1667
1504
|
name: itemName
|
|
1668
|
-
},
|
|
1505
|
+
}, rawOptions)] : [],
|
|
1669
1506
|
min: schema.minItems,
|
|
1670
1507
|
max: schema.maxItems,
|
|
1671
1508
|
unique: schema.uniqueItems ?? void 0,
|
|
@@ -1739,16 +1576,16 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1739
1576
|
* 10. Object / array / tuple / scalar by `type`
|
|
1740
1577
|
* 11. Empty schema fallback (`emptySchemaType` option)
|
|
1741
1578
|
*/
|
|
1742
|
-
function convertSchema({ schema, name },
|
|
1743
|
-
const
|
|
1579
|
+
function convertSchema({ schema, name }, rawOptions) {
|
|
1580
|
+
const options = {
|
|
1744
1581
|
...DEFAULT_PARSER_OPTIONS,
|
|
1745
|
-
...
|
|
1582
|
+
...rawOptions
|
|
1746
1583
|
};
|
|
1747
1584
|
const flattenedSchema = flattenSchema(schema);
|
|
1748
1585
|
if (flattenedSchema && flattenedSchema !== schema) return convertSchema({
|
|
1749
1586
|
schema: flattenedSchema,
|
|
1750
1587
|
name
|
|
1751
|
-
},
|
|
1588
|
+
}, rawOptions);
|
|
1752
1589
|
const nullable = isNullable(schema) || void 0;
|
|
1753
1590
|
const defaultValue = schema.default === null && nullable ? void 0 : schema.default;
|
|
1754
1591
|
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
@@ -1758,8 +1595,8 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1758
1595
|
nullable,
|
|
1759
1596
|
defaultValue,
|
|
1760
1597
|
type,
|
|
1761
|
-
|
|
1762
|
-
|
|
1598
|
+
rawOptions,
|
|
1599
|
+
options
|
|
1763
1600
|
};
|
|
1764
1601
|
if (isReference(schema)) return convertRef(ctx);
|
|
1765
1602
|
if (schema.allOf?.length) return convertAllOf(ctx);
|
|
@@ -1785,7 +1622,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1785
1622
|
type: t
|
|
1786
1623
|
},
|
|
1787
1624
|
name
|
|
1788
|
-
},
|
|
1625
|
+
}, rawOptions)),
|
|
1789
1626
|
...renderSchemaBase(schema, name, arrayNullable, defaultValue)
|
|
1790
1627
|
});
|
|
1791
1628
|
}
|
|
@@ -1803,7 +1640,7 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1803
1640
|
if (type === "boolean") return convertBoolean(ctx);
|
|
1804
1641
|
if (type === "null") return convertNull(ctx);
|
|
1805
1642
|
return (0, _kubb_ast.createSchema)({
|
|
1806
|
-
type: resolveTypeOption(
|
|
1643
|
+
type: resolveTypeOption(options.emptySchemaType),
|
|
1807
1644
|
name,
|
|
1808
1645
|
title: schema.title,
|
|
1809
1646
|
description: schema.description
|
|
@@ -1889,38 +1726,15 @@ function createOasParser(oas, { contentType } = {}) {
|
|
|
1889
1726
|
operations: Object.entries(paths).flatMap(([_path, methods]) => Object.entries(methods).map(([, operation]) => operation ? parseOperation(mergedOptions, oas, operation) : null).filter((op) => op !== null))
|
|
1890
1727
|
});
|
|
1891
1728
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Walks a `SchemaNode` tree and resolves all `ref` node names through the provided callbacks.
|
|
1894
|
-
*
|
|
1895
|
-
* `resolveName` handles all schema types; `resolveEnumName` (when provided) takes precedence
|
|
1896
|
-
* for `enum` nodes, enabling a separate naming strategy for enums (e.g. different suffix).
|
|
1897
|
-
*
|
|
1898
|
-
* Collision-resolved names (from `nameMapping`) are applied before user-supplied resolvers.
|
|
1899
|
-
*/
|
|
1900
|
-
function resolveRefs(node, resolveName, resolveEnumName) {
|
|
1901
|
-
return (0, _kubb_ast.transform)(node, { schema(schemaNode) {
|
|
1902
|
-
const schemaRef = (0, _kubb_ast.narrowSchema)(schemaNode, _kubb_ast.schemaTypes.ref);
|
|
1903
|
-
if (schemaRef && (schemaRef.ref || schemaRef.name)) {
|
|
1904
|
-
const rawRef = schemaRef.ref ?? schemaRef.name;
|
|
1905
|
-
const resolved = resolveName(nameMapping.get(rawRef) ?? rawRef);
|
|
1906
|
-
if (resolved) return {
|
|
1907
|
-
...schemaNode,
|
|
1908
|
-
name: resolved
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
if (schemaNode.type === "enum" && schemaNode.name) {
|
|
1912
|
-
const resolved = (resolveEnumName ?? resolveName)(schemaNode.name);
|
|
1913
|
-
if (resolved) return {
|
|
1914
|
-
...schemaNode,
|
|
1915
|
-
name: resolved
|
|
1916
|
-
};
|
|
1917
|
-
}
|
|
1918
|
-
} });
|
|
1919
|
-
}
|
|
1920
1729
|
return {
|
|
1921
1730
|
parse,
|
|
1922
1731
|
convertSchema,
|
|
1923
|
-
resolveRefs,
|
|
1732
|
+
resolveRefs: /* @__PURE__ */ __name((node, resolveName, resolveEnumName) => resolveRefs({
|
|
1733
|
+
node,
|
|
1734
|
+
nameMapping,
|
|
1735
|
+
resolveName,
|
|
1736
|
+
resolveEnumName
|
|
1737
|
+
}), "resolveRefs"),
|
|
1924
1738
|
nameMapping
|
|
1925
1739
|
};
|
|
1926
1740
|
}
|