@kubb/adapter-oas 5.0.0-alpha.33 → 5.0.0-alpha.35
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 +109 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +104 -94
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/adapter.ts +5 -7
- package/src/constants.ts +7 -8
- package/src/discriminator.ts +15 -16
- package/src/parser.ts +105 -131
- package/src/resolvers.ts +6 -7
- package/src/types.ts +6 -7
package/dist/index.cjs
CHANGED
|
@@ -21,22 +21,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
let _kubb_ast = require("@kubb/ast");
|
|
25
24
|
let _kubb_core = require("@kubb/core");
|
|
26
25
|
let node_path = require("node:path");
|
|
27
|
-
node_path = __toESM(node_path);
|
|
26
|
+
node_path = __toESM(node_path, 1);
|
|
28
27
|
let _redocly_openapi_core = require("@redocly/openapi-core");
|
|
29
28
|
let _stoplight_yaml = require("@stoplight/yaml");
|
|
30
|
-
_stoplight_yaml = __toESM(_stoplight_yaml);
|
|
29
|
+
_stoplight_yaml = __toESM(_stoplight_yaml, 1);
|
|
31
30
|
let oas_normalize = require("oas-normalize");
|
|
32
|
-
oas_normalize = __toESM(oas_normalize);
|
|
31
|
+
oas_normalize = __toESM(oas_normalize, 1);
|
|
33
32
|
let remeda = require("remeda");
|
|
34
33
|
let swagger2openapi = require("swagger2openapi");
|
|
35
|
-
swagger2openapi = __toESM(swagger2openapi);
|
|
34
|
+
swagger2openapi = __toESM(swagger2openapi, 1);
|
|
36
35
|
let oas = require("oas");
|
|
37
|
-
oas = __toESM(oas);
|
|
36
|
+
oas = __toESM(oas, 1);
|
|
38
37
|
let jsonpointer = require("jsonpointer");
|
|
39
|
-
jsonpointer = __toESM(jsonpointer);
|
|
38
|
+
jsonpointer = __toESM(jsonpointer, 1);
|
|
40
39
|
let oas_types = require("oas/types");
|
|
41
40
|
let oas_utils = require("oas/utils");
|
|
42
41
|
//#region src/constants.ts
|
|
@@ -143,9 +142,9 @@ const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
|
143
142
|
* Replaces a plain object lookup with a `Map` for explicit key membership testing via `.has()`.
|
|
144
143
|
*/
|
|
145
144
|
const typeOptionMap = new Map([
|
|
146
|
-
["any",
|
|
147
|
-
["unknown",
|
|
148
|
-
["void",
|
|
145
|
+
["any", _kubb_core.ast.schemaTypes.any],
|
|
146
|
+
["unknown", _kubb_core.ast.schemaTypes.unknown],
|
|
147
|
+
["void", _kubb_core.ast.schemaTypes.void]
|
|
149
148
|
]);
|
|
150
149
|
//#endregion
|
|
151
150
|
//#region src/discriminator.ts
|
|
@@ -167,11 +166,11 @@ const typeOptionMap = new Map([
|
|
|
167
166
|
function applyDiscriminatorInheritance(root) {
|
|
168
167
|
const childMap = /* @__PURE__ */ new Map();
|
|
169
168
|
for (const schema of root.schemas) {
|
|
170
|
-
let unionNode =
|
|
169
|
+
let unionNode = _kubb_core.ast.narrowSchema(schema, "union");
|
|
171
170
|
if (!unionNode) {
|
|
172
|
-
const intersectionMembers =
|
|
171
|
+
const intersectionMembers = _kubb_core.ast.narrowSchema(schema, "intersection")?.members;
|
|
173
172
|
if (intersectionMembers) for (const m of intersectionMembers) {
|
|
174
|
-
const u =
|
|
173
|
+
const u = _kubb_core.ast.narrowSchema(m, "union");
|
|
175
174
|
if (u) {
|
|
176
175
|
unionNode = u;
|
|
177
176
|
break;
|
|
@@ -181,17 +180,17 @@ function applyDiscriminatorInheritance(root) {
|
|
|
181
180
|
if (!unionNode?.discriminatorPropertyName || !unionNode.members) continue;
|
|
182
181
|
const { discriminatorPropertyName, members } = unionNode;
|
|
183
182
|
for (const member of members) {
|
|
184
|
-
const intersectionNode =
|
|
183
|
+
const intersectionNode = _kubb_core.ast.narrowSchema(member, "intersection");
|
|
185
184
|
if (!intersectionNode?.members) continue;
|
|
186
185
|
let refNode;
|
|
187
186
|
let objNode;
|
|
188
187
|
for (const m of intersectionNode.members) {
|
|
189
|
-
refNode ??=
|
|
190
|
-
objNode ??=
|
|
188
|
+
refNode ??= _kubb_core.ast.narrowSchema(m, "ref");
|
|
189
|
+
objNode ??= _kubb_core.ast.narrowSchema(m, "object");
|
|
191
190
|
}
|
|
192
191
|
if (!refNode?.name || !objNode) continue;
|
|
193
192
|
const prop = objNode.properties.find((p) => p.name === discriminatorPropertyName);
|
|
194
|
-
const enumNode = prop ?
|
|
193
|
+
const enumNode = prop ? _kubb_core.ast.narrowSchema(prop.schema, "enum") : void 0;
|
|
195
194
|
if (!enumNode?.enumValues?.length) continue;
|
|
196
195
|
const enumValues = enumNode.enumValues.filter((v) => v !== null);
|
|
197
196
|
if (!enumValues.length) continue;
|
|
@@ -204,20 +203,21 @@ function applyDiscriminatorInheritance(root) {
|
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
205
|
if (childMap.size === 0) return root;
|
|
207
|
-
return
|
|
206
|
+
return _kubb_core.ast.transform(root, { schema(node, { parent }) {
|
|
208
207
|
if (parent?.kind !== "Input" || !node.name) return;
|
|
209
208
|
const entry = childMap.get(node.name);
|
|
210
209
|
if (!entry) return;
|
|
211
|
-
const objectNode =
|
|
210
|
+
const objectNode = _kubb_core.ast.narrowSchema(node, "object");
|
|
212
211
|
if (!objectNode) return;
|
|
213
212
|
const { propertyName, enumValues } = entry;
|
|
214
|
-
const
|
|
213
|
+
const enumSchema = _kubb_core.ast.createSchema({
|
|
214
|
+
type: "enum",
|
|
215
|
+
enumValues
|
|
216
|
+
});
|
|
217
|
+
const newProp = _kubb_core.ast.createProperty({
|
|
215
218
|
name: propertyName,
|
|
216
219
|
required: true,
|
|
217
|
-
schema:
|
|
218
|
-
type: "enum",
|
|
219
|
-
enumValues
|
|
220
|
-
})
|
|
220
|
+
schema: enumSchema
|
|
221
221
|
});
|
|
222
222
|
const existingIdx = objectNode.properties.findIndex((p) => p.name === propertyName);
|
|
223
223
|
const newProperties = existingIdx >= 0 ? objectNode.properties.map((p, i) => i === existingIdx ? newProp : p) : [...objectNode.properties, newProp];
|
|
@@ -711,7 +711,7 @@ function getPrimitiveType(type) {
|
|
|
711
711
|
* Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
|
|
712
712
|
*/
|
|
713
713
|
function getMediaType(contentType) {
|
|
714
|
-
return Object.values(
|
|
714
|
+
return Object.values(_kubb_core.ast.mediaTypes).includes(contentType) ? contentType : null;
|
|
715
715
|
}
|
|
716
716
|
/**
|
|
717
717
|
* Returns all resolved parameters for an operation, merging path-level and operation-level entries.
|
|
@@ -1050,10 +1050,10 @@ function createSchemaParser(ctx) {
|
|
|
1050
1050
|
resolvingRefs.delete(refPath);
|
|
1051
1051
|
}
|
|
1052
1052
|
} catch {}
|
|
1053
|
-
return
|
|
1053
|
+
return _kubb_core.ast.createSchema({
|
|
1054
1054
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1055
1055
|
type: "ref",
|
|
1056
|
-
name:
|
|
1056
|
+
name: _kubb_core.ast.extractRefName(schema.$ref),
|
|
1057
1057
|
ref: schema.$ref,
|
|
1058
1058
|
schema: resolvedSchema
|
|
1059
1059
|
});
|
|
@@ -1071,7 +1071,7 @@ function createSchemaParser(ctx) {
|
|
|
1071
1071
|
const { kind: _kind, ...memberNodeProps } = memberNode;
|
|
1072
1072
|
const mergedNullable = nullable || memberNode.nullable || void 0;
|
|
1073
1073
|
const mergedDefault = schema.default === null && mergedNullable ? void 0 : schema.default ?? memberNode.default;
|
|
1074
|
-
return
|
|
1074
|
+
return _kubb_core.ast.createSchema({
|
|
1075
1075
|
...memberNodeProps,
|
|
1076
1076
|
name,
|
|
1077
1077
|
title: schema.title ?? memberNode.title,
|
|
@@ -1096,7 +1096,7 @@ function createSchemaParser(ctx) {
|
|
|
1096
1096
|
const inOneOf = parentUnion.some((oneOfItem) => isReference(oneOfItem) && oneOfItem.$ref === childRef);
|
|
1097
1097
|
const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef);
|
|
1098
1098
|
if (inOneOf || inMapping) {
|
|
1099
|
-
const discriminatorValue =
|
|
1099
|
+
const discriminatorValue = _kubb_core.ast.findDiscriminator(deref.discriminator.mapping, childRef);
|
|
1100
1100
|
if (discriminatorValue) filteredDiscriminantValues.push({
|
|
1101
1101
|
propertyName: deref.discriminator.propertyName,
|
|
1102
1102
|
value: discriminatorValue
|
|
@@ -1128,13 +1128,13 @@ function createSchemaParser(ctx) {
|
|
|
1128
1128
|
const { allOf: _allOf, ...schemaWithoutAllOf } = schema;
|
|
1129
1129
|
allOfMembers.push(parseSchema({ schema: schemaWithoutAllOf }, rawOptions));
|
|
1130
1130
|
}
|
|
1131
|
-
for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push(
|
|
1131
|
+
for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push(_kubb_core.ast.createDiscriminantNode({
|
|
1132
1132
|
propertyName,
|
|
1133
1133
|
value
|
|
1134
1134
|
}));
|
|
1135
|
-
return
|
|
1135
|
+
return _kubb_core.ast.createSchema({
|
|
1136
1136
|
type: "intersection",
|
|
1137
|
-
members: [...
|
|
1137
|
+
members: [..._kubb_core.ast.mergeAdjacentObjects(allOfMembers.slice(0, syntheticStart)), ..._kubb_core.ast.mergeAdjacentObjects(allOfMembers.slice(syntheticStart))],
|
|
1138
1138
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1139
1139
|
});
|
|
1140
1140
|
}
|
|
@@ -1143,9 +1143,9 @@ function createSchemaParser(ctx) {
|
|
|
1143
1143
|
*/
|
|
1144
1144
|
function convertUnion({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1145
1145
|
function pickDiscriminatorPropertyNode(node, propertyName) {
|
|
1146
|
-
const discriminatorProperty =
|
|
1146
|
+
const discriminatorProperty = _kubb_core.ast.narrowSchema(node, "object")?.properties?.find((property) => property.name === propertyName);
|
|
1147
1147
|
if (!discriminatorProperty) return null;
|
|
1148
|
-
return
|
|
1148
|
+
return _kubb_core.ast.createSchema({
|
|
1149
1149
|
type: "object",
|
|
1150
1150
|
primitive: "object",
|
|
1151
1151
|
properties: [discriminatorProperty]
|
|
@@ -1167,37 +1167,38 @@ function createSchemaParser(ctx) {
|
|
|
1167
1167
|
if (sharedPropertiesNode || discriminator?.mapping) {
|
|
1168
1168
|
const members = unionMembers.map((s) => {
|
|
1169
1169
|
const ref = isReference(s) ? s.$ref : void 0;
|
|
1170
|
-
const discriminatorValue =
|
|
1170
|
+
const discriminatorValue = _kubb_core.ast.findDiscriminator(discriminator?.mapping, ref);
|
|
1171
1171
|
const memberNode = parseSchema({ schema: s }, rawOptions);
|
|
1172
1172
|
if (!discriminatorValue || !discriminator) return memberNode;
|
|
1173
|
-
|
|
1173
|
+
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(_kubb_core.ast.setDiscriminatorEnum({
|
|
1174
|
+
node: sharedPropertiesNode,
|
|
1175
|
+
propertyName: discriminator.propertyName,
|
|
1176
|
+
values: [discriminatorValue]
|
|
1177
|
+
}), discriminator.propertyName) : void 0;
|
|
1178
|
+
return _kubb_core.ast.createSchema({
|
|
1174
1179
|
type: "intersection",
|
|
1175
|
-
members: [memberNode,
|
|
1176
|
-
node: sharedPropertiesNode,
|
|
1177
|
-
propertyName: discriminator.propertyName,
|
|
1178
|
-
values: [discriminatorValue]
|
|
1179
|
-
}), discriminator.propertyName) : void 0) ?? (0, _kubb_ast.createDiscriminantNode)({
|
|
1180
|
+
members: [memberNode, narrowedDiscriminatorNode ?? _kubb_core.ast.createDiscriminantNode({
|
|
1180
1181
|
propertyName: discriminator.propertyName,
|
|
1181
1182
|
value: discriminatorValue
|
|
1182
1183
|
})]
|
|
1183
1184
|
});
|
|
1184
1185
|
});
|
|
1185
|
-
const unionNode =
|
|
1186
|
+
const unionNode = _kubb_core.ast.createSchema({
|
|
1186
1187
|
type: "union",
|
|
1187
1188
|
...unionBase,
|
|
1188
1189
|
members
|
|
1189
1190
|
});
|
|
1190
1191
|
if (!sharedPropertiesNode) return unionNode;
|
|
1191
|
-
return
|
|
1192
|
+
return _kubb_core.ast.createSchema({
|
|
1192
1193
|
type: "intersection",
|
|
1193
1194
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1194
1195
|
members: [unionNode, sharedPropertiesNode]
|
|
1195
1196
|
});
|
|
1196
1197
|
}
|
|
1197
|
-
return
|
|
1198
|
+
return _kubb_core.ast.createSchema({
|
|
1198
1199
|
type: "union",
|
|
1199
1200
|
...unionBase,
|
|
1200
|
-
members:
|
|
1201
|
+
members: _kubb_core.ast.simplifyUnion(unionMembers.map((s) => parseSchema({ schema: s }, rawOptions)))
|
|
1201
1202
|
});
|
|
1202
1203
|
}
|
|
1203
1204
|
/**
|
|
@@ -1205,7 +1206,7 @@ function createSchemaParser(ctx) {
|
|
|
1205
1206
|
*/
|
|
1206
1207
|
function convertConst({ schema, name, nullable, defaultValue }) {
|
|
1207
1208
|
const constValue = schema.const;
|
|
1208
|
-
if (constValue === null) return
|
|
1209
|
+
if (constValue === null) return _kubb_core.ast.createSchema({
|
|
1209
1210
|
type: "null",
|
|
1210
1211
|
primitive: "null",
|
|
1211
1212
|
name,
|
|
@@ -1213,9 +1214,10 @@ function createSchemaParser(ctx) {
|
|
|
1213
1214
|
description: schema.description,
|
|
1214
1215
|
deprecated: schema.deprecated
|
|
1215
1216
|
});
|
|
1216
|
-
|
|
1217
|
+
const constPrimitive = getPrimitiveType(typeof constValue === "number" ? "number" : typeof constValue === "boolean" ? "boolean" : "string");
|
|
1218
|
+
return _kubb_core.ast.createSchema({
|
|
1217
1219
|
type: "enum",
|
|
1218
|
-
primitive:
|
|
1220
|
+
primitive: constPrimitive,
|
|
1219
1221
|
enumValues: [constValue],
|
|
1220
1222
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1221
1223
|
});
|
|
@@ -1226,7 +1228,7 @@ function createSchemaParser(ctx) {
|
|
|
1226
1228
|
*/
|
|
1227
1229
|
function convertFormat({ schema, name, nullable, defaultValue, options }) {
|
|
1228
1230
|
const base = buildSchemaNode(schema, name, nullable, defaultValue);
|
|
1229
|
-
if (schema.format === "int64") return
|
|
1231
|
+
if (schema.format === "int64") return _kubb_core.ast.createSchema({
|
|
1230
1232
|
type: options.integerType === "bigint" ? "bigint" : "integer",
|
|
1231
1233
|
primitive: "integer",
|
|
1232
1234
|
...base,
|
|
@@ -1238,14 +1240,14 @@ function createSchemaParser(ctx) {
|
|
|
1238
1240
|
if (schema.format === "date-time" || schema.format === "date" || schema.format === "time") {
|
|
1239
1241
|
const dateType = getDateType(options, schema.format);
|
|
1240
1242
|
if (!dateType) return null;
|
|
1241
|
-
if (dateType.type === "datetime") return
|
|
1243
|
+
if (dateType.type === "datetime") return _kubb_core.ast.createSchema({
|
|
1242
1244
|
...base,
|
|
1243
1245
|
primitive: "string",
|
|
1244
1246
|
type: "datetime",
|
|
1245
1247
|
offset: dateType.offset,
|
|
1246
1248
|
local: dateType.local
|
|
1247
1249
|
});
|
|
1248
|
-
return
|
|
1250
|
+
return _kubb_core.ast.createSchema({
|
|
1249
1251
|
...base,
|
|
1250
1252
|
primitive: "string",
|
|
1251
1253
|
type: dateType.type,
|
|
@@ -1255,36 +1257,36 @@ function createSchemaParser(ctx) {
|
|
|
1255
1257
|
const specialType = getSchemaType(schema.format);
|
|
1256
1258
|
if (!specialType) return null;
|
|
1257
1259
|
const specialPrimitive = specialType === "number" || specialType === "integer" || specialType === "bigint" ? specialType : "string";
|
|
1258
|
-
if (specialType === "number" || specialType === "integer" || specialType === "bigint") return
|
|
1260
|
+
if (specialType === "number" || specialType === "integer" || specialType === "bigint") return _kubb_core.ast.createSchema({
|
|
1259
1261
|
...base,
|
|
1260
1262
|
primitive: specialPrimitive,
|
|
1261
1263
|
type: specialType
|
|
1262
1264
|
});
|
|
1263
|
-
if (specialType === "url") return
|
|
1265
|
+
if (specialType === "url") return _kubb_core.ast.createSchema({
|
|
1264
1266
|
...base,
|
|
1265
1267
|
primitive: "string",
|
|
1266
1268
|
type: "url",
|
|
1267
1269
|
min: schema.minLength,
|
|
1268
1270
|
max: schema.maxLength
|
|
1269
1271
|
});
|
|
1270
|
-
if (specialType === "ipv4") return
|
|
1272
|
+
if (specialType === "ipv4") return _kubb_core.ast.createSchema({
|
|
1271
1273
|
...base,
|
|
1272
1274
|
primitive: "string",
|
|
1273
1275
|
type: "ipv4"
|
|
1274
1276
|
});
|
|
1275
|
-
if (specialType === "ipv6") return
|
|
1277
|
+
if (specialType === "ipv6") return _kubb_core.ast.createSchema({
|
|
1276
1278
|
...base,
|
|
1277
1279
|
primitive: "string",
|
|
1278
1280
|
type: "ipv6"
|
|
1279
1281
|
});
|
|
1280
|
-
if (specialType === "uuid" || specialType === "email") return
|
|
1282
|
+
if (specialType === "uuid" || specialType === "email") return _kubb_core.ast.createSchema({
|
|
1281
1283
|
...base,
|
|
1282
1284
|
primitive: "string",
|
|
1283
1285
|
type: specialType,
|
|
1284
1286
|
min: schema.minLength,
|
|
1285
1287
|
max: schema.maxLength
|
|
1286
1288
|
});
|
|
1287
|
-
return
|
|
1289
|
+
return _kubb_core.ast.createSchema({
|
|
1288
1290
|
...base,
|
|
1289
1291
|
primitive: specialPrimitive,
|
|
1290
1292
|
type: specialType
|
|
@@ -1320,7 +1322,7 @@ function createSchemaParser(ctx) {
|
|
|
1320
1322
|
if (extensionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1321
1323
|
const enumPrimitiveType = enumPrimitive === "number" || enumPrimitive === "integer" ? "number" : enumPrimitive === "boolean" ? "boolean" : "string";
|
|
1322
1324
|
const sourceValues = extensionKey ? [...new Set(schema[extensionKey])] : [...new Set(filteredValues)];
|
|
1323
|
-
return
|
|
1325
|
+
return _kubb_core.ast.createSchema({
|
|
1324
1326
|
...enumBase,
|
|
1325
1327
|
primitive: enumPrimitiveType,
|
|
1326
1328
|
namedEnumValues: sourceValues.map((label, index) => ({
|
|
@@ -1330,7 +1332,7 @@ function createSchemaParser(ctx) {
|
|
|
1330
1332
|
}))
|
|
1331
1333
|
});
|
|
1332
1334
|
}
|
|
1333
|
-
return
|
|
1335
|
+
return _kubb_core.ast.createSchema({
|
|
1334
1336
|
...enumBase,
|
|
1335
1337
|
enumValues: [...new Set(filteredValues)]
|
|
1336
1338
|
});
|
|
@@ -1343,19 +1345,20 @@ function createSchemaParser(ctx) {
|
|
|
1343
1345
|
const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
|
|
1344
1346
|
const resolvedPropSchema = propSchema;
|
|
1345
1347
|
const propNullable = isNullable(resolvedPropSchema);
|
|
1346
|
-
|
|
1348
|
+
const propNode = parseSchema({
|
|
1347
1349
|
schema: resolvedPropSchema,
|
|
1348
|
-
name:
|
|
1349
|
-
}, rawOptions)
|
|
1350
|
-
|
|
1350
|
+
name: _kubb_core.ast.childName(name, propName)
|
|
1351
|
+
}, rawOptions);
|
|
1352
|
+
let schemaNode = _kubb_core.ast.setEnumName(propNode, name, propName, options.enumSuffix);
|
|
1353
|
+
const tupleNode = _kubb_core.ast.narrowSchema(schemaNode, "tuple");
|
|
1351
1354
|
if (tupleNode?.items) {
|
|
1352
|
-
const namedItems = tupleNode.items.map((item) =>
|
|
1355
|
+
const namedItems = tupleNode.items.map((item) => _kubb_core.ast.setEnumName(item, name, propName, options.enumSuffix));
|
|
1353
1356
|
if (namedItems.some((item, i) => item !== tupleNode.items[i])) schemaNode = {
|
|
1354
1357
|
...tupleNode,
|
|
1355
1358
|
items: namedItems
|
|
1356
1359
|
};
|
|
1357
1360
|
}
|
|
1358
|
-
return
|
|
1361
|
+
return _kubb_core.ast.createProperty({
|
|
1359
1362
|
name: propName,
|
|
1360
1363
|
schema: {
|
|
1361
1364
|
...schemaNode,
|
|
@@ -1369,10 +1372,10 @@ function createSchemaParser(ctx) {
|
|
|
1369
1372
|
if (additionalProperties === true) additionalPropertiesNode = true;
|
|
1370
1373
|
else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = parseSchema({ schema: additionalProperties }, rawOptions);
|
|
1371
1374
|
else if (additionalProperties === false) additionalPropertiesNode = false;
|
|
1372
|
-
else if (additionalProperties) additionalPropertiesNode =
|
|
1375
|
+
else if (additionalProperties) additionalPropertiesNode = _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
|
|
1373
1376
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
1374
|
-
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ?
|
|
1375
|
-
const objectNode =
|
|
1377
|
+
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.unknownType) }) : parseSchema({ schema: patternSchema }, rawOptions)])) : void 0;
|
|
1378
|
+
const objectNode = _kubb_core.ast.createSchema({
|
|
1376
1379
|
type: "object",
|
|
1377
1380
|
primitive: "object",
|
|
1378
1381
|
properties,
|
|
@@ -1384,11 +1387,13 @@ function createSchemaParser(ctx) {
|
|
|
1384
1387
|
});
|
|
1385
1388
|
if (isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
1386
1389
|
const discPropName = schema.discriminator.propertyName;
|
|
1387
|
-
|
|
1390
|
+
const values = Object.keys(schema.discriminator.mapping);
|
|
1391
|
+
const enumName = name ? _kubb_core.ast.enumPropName(name, discPropName, options.enumSuffix) : void 0;
|
|
1392
|
+
return _kubb_core.ast.setDiscriminatorEnum({
|
|
1388
1393
|
node: objectNode,
|
|
1389
1394
|
propertyName: discPropName,
|
|
1390
|
-
values
|
|
1391
|
-
enumName
|
|
1395
|
+
values,
|
|
1396
|
+
enumName
|
|
1392
1397
|
});
|
|
1393
1398
|
}
|
|
1394
1399
|
return objectNode;
|
|
@@ -1397,11 +1402,13 @@ function createSchemaParser(ctx) {
|
|
|
1397
1402
|
* Converts an OAS 3.1 `prefixItems` tuple into a `TupleSchemaNode`.
|
|
1398
1403
|
*/
|
|
1399
1404
|
function convertTuple({ schema, name, nullable, defaultValue, rawOptions }) {
|
|
1400
|
-
|
|
1405
|
+
const tupleItems = (schema.prefixItems ?? []).map((item) => parseSchema({ schema: item }, rawOptions));
|
|
1406
|
+
const rest = schema.items ? parseSchema({ schema: schema.items }, rawOptions) : _kubb_core.ast.createSchema({ type: "any" });
|
|
1407
|
+
return _kubb_core.ast.createSchema({
|
|
1401
1408
|
type: "tuple",
|
|
1402
1409
|
primitive: "array",
|
|
1403
|
-
items:
|
|
1404
|
-
rest
|
|
1410
|
+
items: tupleItems,
|
|
1411
|
+
rest,
|
|
1405
1412
|
min: schema.minItems,
|
|
1406
1413
|
max: schema.maxItems,
|
|
1407
1414
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
@@ -1412,14 +1419,15 @@ function createSchemaParser(ctx) {
|
|
|
1412
1419
|
*/
|
|
1413
1420
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1414
1421
|
const rawItems = schema.items;
|
|
1415
|
-
const itemName = rawItems?.enum?.length && name ?
|
|
1416
|
-
|
|
1422
|
+
const itemName = rawItems?.enum?.length && name ? _kubb_core.ast.enumPropName(void 0, name, options.enumSuffix) : void 0;
|
|
1423
|
+
const items = rawItems ? [parseSchema({
|
|
1424
|
+
schema: rawItems,
|
|
1425
|
+
name: itemName
|
|
1426
|
+
}, rawOptions)] : [];
|
|
1427
|
+
return _kubb_core.ast.createSchema({
|
|
1417
1428
|
type: "array",
|
|
1418
1429
|
primitive: "array",
|
|
1419
|
-
items
|
|
1420
|
-
schema: rawItems,
|
|
1421
|
-
name: itemName
|
|
1422
|
-
}, rawOptions)] : [],
|
|
1430
|
+
items,
|
|
1423
1431
|
min: schema.minItems,
|
|
1424
1432
|
max: schema.maxItems,
|
|
1425
1433
|
unique: schema.uniqueItems ?? void 0,
|
|
@@ -1430,7 +1438,7 @@ function createSchemaParser(ctx) {
|
|
|
1430
1438
|
* Converts a `type: 'string'` schema into a `StringSchemaNode`.
|
|
1431
1439
|
*/
|
|
1432
1440
|
function convertString({ schema, name, nullable, defaultValue }) {
|
|
1433
|
-
return
|
|
1441
|
+
return _kubb_core.ast.createSchema({
|
|
1434
1442
|
type: "string",
|
|
1435
1443
|
primitive: "string",
|
|
1436
1444
|
min: schema.minLength,
|
|
@@ -1443,7 +1451,7 @@ function createSchemaParser(ctx) {
|
|
|
1443
1451
|
* Converts a `type: 'number'` or `type: 'integer'` schema.
|
|
1444
1452
|
*/
|
|
1445
1453
|
function convertNumeric({ schema, name, nullable, defaultValue }, type) {
|
|
1446
|
-
return
|
|
1454
|
+
return _kubb_core.ast.createSchema({
|
|
1447
1455
|
type,
|
|
1448
1456
|
primitive: type,
|
|
1449
1457
|
min: schema.minimum,
|
|
@@ -1458,7 +1466,7 @@ function createSchemaParser(ctx) {
|
|
|
1458
1466
|
* Converts a `type: 'boolean'` schema.
|
|
1459
1467
|
*/
|
|
1460
1468
|
function convertBoolean({ schema, name, nullable, defaultValue }) {
|
|
1461
|
-
return
|
|
1469
|
+
return _kubb_core.ast.createSchema({
|
|
1462
1470
|
type: "boolean",
|
|
1463
1471
|
primitive: "boolean",
|
|
1464
1472
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
@@ -1468,7 +1476,7 @@ function createSchemaParser(ctx) {
|
|
|
1468
1476
|
* Converts an explicit `type: 'null'` schema.
|
|
1469
1477
|
*/
|
|
1470
1478
|
function convertNull({ schema, name, nullable }) {
|
|
1471
|
-
return
|
|
1479
|
+
return _kubb_core.ast.createSchema({
|
|
1472
1480
|
type: "null",
|
|
1473
1481
|
primitive: "null",
|
|
1474
1482
|
name,
|
|
@@ -1515,7 +1523,7 @@ function createSchemaParser(ctx) {
|
|
|
1515
1523
|
const formatResult = convertFormat(ctx);
|
|
1516
1524
|
if (formatResult) return formatResult;
|
|
1517
1525
|
}
|
|
1518
|
-
if (schema.type === "string" && schema.contentMediaType === "application/octet-stream") return
|
|
1526
|
+
if (schema.type === "string" && schema.contentMediaType === "application/octet-stream") return _kubb_core.ast.createSchema({
|
|
1519
1527
|
type: "blob",
|
|
1520
1528
|
primitive: "string",
|
|
1521
1529
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
@@ -1523,7 +1531,7 @@ function createSchemaParser(ctx) {
|
|
|
1523
1531
|
if (Array.isArray(schema.type) && schema.type.length > 1) {
|
|
1524
1532
|
const nonNullTypes = schema.type.filter((t) => t !== "null");
|
|
1525
1533
|
const arrayNullable = schema.type.includes("null") || nullable || void 0;
|
|
1526
|
-
if (nonNullTypes.length > 1) return
|
|
1534
|
+
if (nonNullTypes.length > 1) return _kubb_core.ast.createSchema({
|
|
1527
1535
|
type: "union",
|
|
1528
1536
|
members: nonNullTypes.map((t) => parseSchema({
|
|
1529
1537
|
schema: {
|
|
@@ -1548,8 +1556,9 @@ function createSchemaParser(ctx) {
|
|
|
1548
1556
|
if (type === "integer") return convertNumeric(ctx, "integer");
|
|
1549
1557
|
if (type === "boolean") return convertBoolean(ctx);
|
|
1550
1558
|
if (type === "null") return convertNull(ctx);
|
|
1551
|
-
|
|
1552
|
-
|
|
1559
|
+
const emptyType = typeOptionMap.get(options.emptySchemaType);
|
|
1560
|
+
return _kubb_core.ast.createSchema({
|
|
1561
|
+
type: emptyType,
|
|
1553
1562
|
name,
|
|
1554
1563
|
title: schema.title,
|
|
1555
1564
|
description: schema.description
|
|
@@ -1560,8 +1569,8 @@ function createSchemaParser(ctx) {
|
|
|
1560
1569
|
*/
|
|
1561
1570
|
function parseParameter(options, param) {
|
|
1562
1571
|
const required = param["required"] ?? false;
|
|
1563
|
-
const schema = param["schema"] ? parseSchema({ schema: param["schema"] }, options) :
|
|
1564
|
-
return
|
|
1572
|
+
const schema = param["schema"] ? parseSchema({ schema: param["schema"] }, options) : _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
|
|
1573
|
+
return _kubb_core.ast.createParameter({
|
|
1565
1574
|
name: param["name"],
|
|
1566
1575
|
in: param["in"],
|
|
1567
1576
|
schema: {
|
|
@@ -1588,7 +1597,7 @@ function createSchemaParser(ctx) {
|
|
|
1588
1597
|
})();
|
|
1589
1598
|
const requestBody = requestBodySchemaNode ? {
|
|
1590
1599
|
description: requestBodyDescription,
|
|
1591
|
-
schema:
|
|
1600
|
+
schema: _kubb_core.ast.syncOptionality(requestBodySchemaNode, requestBodyRequired),
|
|
1592
1601
|
keysToOmit: requestBodyKeysToOmit?.length ? requestBodyKeysToOmit : void 0,
|
|
1593
1602
|
required: requestBodyRequired || void 0,
|
|
1594
1603
|
contentType: requestBodyContentType
|
|
@@ -1596,12 +1605,12 @@ function createSchemaParser(ctx) {
|
|
|
1596
1605
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1597
1606
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1598
1607
|
const responseSchema = getResponseSchema(document, operation, statusCode, { contentType: ctx.contentType });
|
|
1599
|
-
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({ schema: responseSchema }, options) :
|
|
1608
|
+
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({ schema: responseSchema }, options) : _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType) });
|
|
1600
1609
|
const description = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.description : void 0;
|
|
1601
1610
|
const rawContent = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.content : void 0;
|
|
1602
1611
|
const mediaType = rawContent ? getMediaType(Object.keys(rawContent)[0] ?? "") : getMediaType(operation.contentType ?? "");
|
|
1603
1612
|
const keysToOmit = responseSchema?.properties ? Object.entries(responseSchema.properties).filter(([, prop]) => !isReference(prop) && prop.writeOnly).map(([key]) => key) : void 0;
|
|
1604
|
-
return
|
|
1613
|
+
return _kubb_core.ast.createResponse({
|
|
1605
1614
|
statusCode,
|
|
1606
1615
|
description,
|
|
1607
1616
|
schema,
|
|
@@ -1610,7 +1619,7 @@ function createSchemaParser(ctx) {
|
|
|
1610
1619
|
});
|
|
1611
1620
|
});
|
|
1612
1621
|
const urlPath = new URLPath(operation.path);
|
|
1613
|
-
return
|
|
1622
|
+
return _kubb_core.ast.createOperation({
|
|
1614
1623
|
operationId: operation.getOperationId(),
|
|
1615
1624
|
method: operation.method.toUpperCase(),
|
|
1616
1625
|
path: urlPath.path,
|
|
@@ -1658,10 +1667,11 @@ function parseOas(document, options = {}) {
|
|
|
1658
1667
|
name
|
|
1659
1668
|
}, mergedOptions));
|
|
1660
1669
|
const paths = new oas.default(document).getPaths();
|
|
1670
|
+
const operations = Object.entries(paths).flatMap(([_path, methods]) => Object.entries(methods).map(([, operation]) => operation ? _parseOperation(mergedOptions, operation) : null).filter((op) => op !== null));
|
|
1661
1671
|
return {
|
|
1662
|
-
root:
|
|
1672
|
+
root: _kubb_core.ast.createInput({
|
|
1663
1673
|
schemas,
|
|
1664
|
-
operations
|
|
1674
|
+
operations
|
|
1665
1675
|
}),
|
|
1666
1676
|
nameMapping
|
|
1667
1677
|
};
|
|
@@ -1720,13 +1730,13 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
1720
1730
|
return inputNode;
|
|
1721
1731
|
},
|
|
1722
1732
|
getImports(node, resolve) {
|
|
1723
|
-
return
|
|
1733
|
+
return _kubb_core.ast.collectImports({
|
|
1724
1734
|
node,
|
|
1725
1735
|
nameMapping,
|
|
1726
1736
|
resolve: (schemaName) => {
|
|
1727
1737
|
const result = resolve(schemaName);
|
|
1728
1738
|
if (!result) return;
|
|
1729
|
-
return
|
|
1739
|
+
return _kubb_core.ast.createImport({
|
|
1730
1740
|
name: [result.name],
|
|
1731
1741
|
path: result.path
|
|
1732
1742
|
});
|
|
@@ -1749,7 +1759,7 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
1749
1759
|
const node = discriminator === "inherit" ? applyDiscriminatorInheritance(parsedRoot) : parsedRoot;
|
|
1750
1760
|
nameMapping = parsedNameMapping;
|
|
1751
1761
|
parsedDocument = document;
|
|
1752
|
-
inputNode =
|
|
1762
|
+
inputNode = _kubb_core.ast.createInput({
|
|
1753
1763
|
...node,
|
|
1754
1764
|
meta: {
|
|
1755
1765
|
title: document.info?.title,
|