@kubb/adapter-oas 5.0.0-alpha.34 → 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.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { childName, collectImports, createDiscriminantNode, createImport, createInput, createOperation, createParameter, createProperty, createResponse, createSchema, enumPropName, extractRefName, findDiscriminator, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, transform } from "@kubb/ast";
3
- import { createAdapter } from "@kubb/core";
2
+ import { ast, createAdapter } from "@kubb/core";
4
3
  import path from "node:path";
5
4
  import { bundle, loadConfig } from "@redocly/openapi-core";
6
5
  import yaml from "@stoplight/yaml";
@@ -115,9 +114,9 @@ const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
115
114
  * Replaces a plain object lookup with a `Map` for explicit key membership testing via `.has()`.
116
115
  */
117
116
  const typeOptionMap = new Map([
118
- ["any", schemaTypes.any],
119
- ["unknown", schemaTypes.unknown],
120
- ["void", schemaTypes.void]
117
+ ["any", ast.schemaTypes.any],
118
+ ["unknown", ast.schemaTypes.unknown],
119
+ ["void", ast.schemaTypes.void]
121
120
  ]);
122
121
  //#endregion
123
122
  //#region src/discriminator.ts
@@ -139,11 +138,11 @@ const typeOptionMap = new Map([
139
138
  function applyDiscriminatorInheritance(root) {
140
139
  const childMap = /* @__PURE__ */ new Map();
141
140
  for (const schema of root.schemas) {
142
- let unionNode = narrowSchema(schema, "union");
141
+ let unionNode = ast.narrowSchema(schema, "union");
143
142
  if (!unionNode) {
144
- const intersectionMembers = narrowSchema(schema, "intersection")?.members;
143
+ const intersectionMembers = ast.narrowSchema(schema, "intersection")?.members;
145
144
  if (intersectionMembers) for (const m of intersectionMembers) {
146
- const u = narrowSchema(m, "union");
145
+ const u = ast.narrowSchema(m, "union");
147
146
  if (u) {
148
147
  unionNode = u;
149
148
  break;
@@ -153,17 +152,17 @@ function applyDiscriminatorInheritance(root) {
153
152
  if (!unionNode?.discriminatorPropertyName || !unionNode.members) continue;
154
153
  const { discriminatorPropertyName, members } = unionNode;
155
154
  for (const member of members) {
156
- const intersectionNode = narrowSchema(member, "intersection");
155
+ const intersectionNode = ast.narrowSchema(member, "intersection");
157
156
  if (!intersectionNode?.members) continue;
158
157
  let refNode;
159
158
  let objNode;
160
159
  for (const m of intersectionNode.members) {
161
- refNode ??= narrowSchema(m, "ref");
162
- objNode ??= narrowSchema(m, "object");
160
+ refNode ??= ast.narrowSchema(m, "ref");
161
+ objNode ??= ast.narrowSchema(m, "object");
163
162
  }
164
163
  if (!refNode?.name || !objNode) continue;
165
164
  const prop = objNode.properties.find((p) => p.name === discriminatorPropertyName);
166
- const enumNode = prop ? narrowSchema(prop.schema, "enum") : void 0;
165
+ const enumNode = prop ? ast.narrowSchema(prop.schema, "enum") : void 0;
167
166
  if (!enumNode?.enumValues?.length) continue;
168
167
  const enumValues = enumNode.enumValues.filter((v) => v !== null);
169
168
  if (!enumValues.length) continue;
@@ -176,20 +175,21 @@ function applyDiscriminatorInheritance(root) {
176
175
  }
177
176
  }
178
177
  if (childMap.size === 0) return root;
179
- return transform(root, { schema(node, { parent }) {
178
+ return ast.transform(root, { schema(node, { parent }) {
180
179
  if (parent?.kind !== "Input" || !node.name) return;
181
180
  const entry = childMap.get(node.name);
182
181
  if (!entry) return;
183
- const objectNode = narrowSchema(node, "object");
182
+ const objectNode = ast.narrowSchema(node, "object");
184
183
  if (!objectNode) return;
185
184
  const { propertyName, enumValues } = entry;
186
- const newProp = createProperty({
185
+ const enumSchema = ast.createSchema({
186
+ type: "enum",
187
+ enumValues
188
+ });
189
+ const newProp = ast.createProperty({
187
190
  name: propertyName,
188
191
  required: true,
189
- schema: createSchema({
190
- type: "enum",
191
- enumValues
192
- })
192
+ schema: enumSchema
193
193
  });
194
194
  const existingIdx = objectNode.properties.findIndex((p) => p.name === propertyName);
195
195
  const newProperties = existingIdx >= 0 ? objectNode.properties.map((p, i) => i === existingIdx ? newProp : p) : [...objectNode.properties, newProp];
@@ -683,7 +683,7 @@ function getPrimitiveType(type) {
683
683
  * Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
684
684
  */
685
685
  function getMediaType(contentType) {
686
- return Object.values(mediaTypes).includes(contentType) ? contentType : null;
686
+ return Object.values(ast.mediaTypes).includes(contentType) ? contentType : null;
687
687
  }
688
688
  /**
689
689
  * Returns all resolved parameters for an operation, merging path-level and operation-level entries.
@@ -1022,10 +1022,10 @@ function createSchemaParser(ctx) {
1022
1022
  resolvingRefs.delete(refPath);
1023
1023
  }
1024
1024
  } catch {}
1025
- return createSchema({
1025
+ return ast.createSchema({
1026
1026
  ...buildSchemaNode(schema, name, nullable, defaultValue),
1027
1027
  type: "ref",
1028
- name: extractRefName(schema.$ref),
1028
+ name: ast.extractRefName(schema.$ref),
1029
1029
  ref: schema.$ref,
1030
1030
  schema: resolvedSchema
1031
1031
  });
@@ -1043,7 +1043,7 @@ function createSchemaParser(ctx) {
1043
1043
  const { kind: _kind, ...memberNodeProps } = memberNode;
1044
1044
  const mergedNullable = nullable || memberNode.nullable || void 0;
1045
1045
  const mergedDefault = schema.default === null && mergedNullable ? void 0 : schema.default ?? memberNode.default;
1046
- return createSchema({
1046
+ return ast.createSchema({
1047
1047
  ...memberNodeProps,
1048
1048
  name,
1049
1049
  title: schema.title ?? memberNode.title,
@@ -1068,7 +1068,7 @@ function createSchemaParser(ctx) {
1068
1068
  const inOneOf = parentUnion.some((oneOfItem) => isReference(oneOfItem) && oneOfItem.$ref === childRef);
1069
1069
  const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef);
1070
1070
  if (inOneOf || inMapping) {
1071
- const discriminatorValue = findDiscriminator(deref.discriminator.mapping, childRef);
1071
+ const discriminatorValue = ast.findDiscriminator(deref.discriminator.mapping, childRef);
1072
1072
  if (discriminatorValue) filteredDiscriminantValues.push({
1073
1073
  propertyName: deref.discriminator.propertyName,
1074
1074
  value: discriminatorValue
@@ -1100,13 +1100,13 @@ function createSchemaParser(ctx) {
1100
1100
  const { allOf: _allOf, ...schemaWithoutAllOf } = schema;
1101
1101
  allOfMembers.push(parseSchema({ schema: schemaWithoutAllOf }, rawOptions));
1102
1102
  }
1103
- for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push(createDiscriminantNode({
1103
+ for (const { propertyName, value } of filteredDiscriminantValues) allOfMembers.push(ast.createDiscriminantNode({
1104
1104
  propertyName,
1105
1105
  value
1106
1106
  }));
1107
- return createSchema({
1107
+ return ast.createSchema({
1108
1108
  type: "intersection",
1109
- members: [...mergeAdjacentObjects(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjects(allOfMembers.slice(syntheticStart))],
1109
+ members: [...ast.mergeAdjacentObjects(allOfMembers.slice(0, syntheticStart)), ...ast.mergeAdjacentObjects(allOfMembers.slice(syntheticStart))],
1110
1110
  ...buildSchemaNode(schema, name, nullable, defaultValue)
1111
1111
  });
1112
1112
  }
@@ -1115,9 +1115,9 @@ function createSchemaParser(ctx) {
1115
1115
  */
1116
1116
  function convertUnion({ schema, name, nullable, defaultValue, rawOptions }) {
1117
1117
  function pickDiscriminatorPropertyNode(node, propertyName) {
1118
- const discriminatorProperty = narrowSchema(node, "object")?.properties?.find((property) => property.name === propertyName);
1118
+ const discriminatorProperty = ast.narrowSchema(node, "object")?.properties?.find((property) => property.name === propertyName);
1119
1119
  if (!discriminatorProperty) return null;
1120
- return createSchema({
1120
+ return ast.createSchema({
1121
1121
  type: "object",
1122
1122
  primitive: "object",
1123
1123
  properties: [discriminatorProperty]
@@ -1139,37 +1139,38 @@ function createSchemaParser(ctx) {
1139
1139
  if (sharedPropertiesNode || discriminator?.mapping) {
1140
1140
  const members = unionMembers.map((s) => {
1141
1141
  const ref = isReference(s) ? s.$ref : void 0;
1142
- const discriminatorValue = findDiscriminator(discriminator?.mapping, ref);
1142
+ const discriminatorValue = ast.findDiscriminator(discriminator?.mapping, ref);
1143
1143
  const memberNode = parseSchema({ schema: s }, rawOptions);
1144
1144
  if (!discriminatorValue || !discriminator) return memberNode;
1145
- return createSchema({
1145
+ const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.setDiscriminatorEnum({
1146
+ node: sharedPropertiesNode,
1147
+ propertyName: discriminator.propertyName,
1148
+ values: [discriminatorValue]
1149
+ }), discriminator.propertyName) : void 0;
1150
+ return ast.createSchema({
1146
1151
  type: "intersection",
1147
- members: [memberNode, (sharedPropertiesNode ? pickDiscriminatorPropertyNode(setDiscriminatorEnum({
1148
- node: sharedPropertiesNode,
1149
- propertyName: discriminator.propertyName,
1150
- values: [discriminatorValue]
1151
- }), discriminator.propertyName) : void 0) ?? createDiscriminantNode({
1152
+ members: [memberNode, narrowedDiscriminatorNode ?? ast.createDiscriminantNode({
1152
1153
  propertyName: discriminator.propertyName,
1153
1154
  value: discriminatorValue
1154
1155
  })]
1155
1156
  });
1156
1157
  });
1157
- const unionNode = createSchema({
1158
+ const unionNode = ast.createSchema({
1158
1159
  type: "union",
1159
1160
  ...unionBase,
1160
1161
  members
1161
1162
  });
1162
1163
  if (!sharedPropertiesNode) return unionNode;
1163
- return createSchema({
1164
+ return ast.createSchema({
1164
1165
  type: "intersection",
1165
1166
  ...buildSchemaNode(schema, name, nullable, defaultValue),
1166
1167
  members: [unionNode, sharedPropertiesNode]
1167
1168
  });
1168
1169
  }
1169
- return createSchema({
1170
+ return ast.createSchema({
1170
1171
  type: "union",
1171
1172
  ...unionBase,
1172
- members: simplifyUnion(unionMembers.map((s) => parseSchema({ schema: s }, rawOptions)))
1173
+ members: ast.simplifyUnion(unionMembers.map((s) => parseSchema({ schema: s }, rawOptions)))
1173
1174
  });
1174
1175
  }
1175
1176
  /**
@@ -1177,7 +1178,7 @@ function createSchemaParser(ctx) {
1177
1178
  */
1178
1179
  function convertConst({ schema, name, nullable, defaultValue }) {
1179
1180
  const constValue = schema.const;
1180
- if (constValue === null) return createSchema({
1181
+ if (constValue === null) return ast.createSchema({
1181
1182
  type: "null",
1182
1183
  primitive: "null",
1183
1184
  name,
@@ -1185,9 +1186,10 @@ function createSchemaParser(ctx) {
1185
1186
  description: schema.description,
1186
1187
  deprecated: schema.deprecated
1187
1188
  });
1188
- return createSchema({
1189
+ const constPrimitive = getPrimitiveType(typeof constValue === "number" ? "number" : typeof constValue === "boolean" ? "boolean" : "string");
1190
+ return ast.createSchema({
1189
1191
  type: "enum",
1190
- primitive: getPrimitiveType(typeof constValue === "number" ? "number" : typeof constValue === "boolean" ? "boolean" : "string"),
1192
+ primitive: constPrimitive,
1191
1193
  enumValues: [constValue],
1192
1194
  ...buildSchemaNode(schema, name, nullable, defaultValue)
1193
1195
  });
@@ -1198,7 +1200,7 @@ function createSchemaParser(ctx) {
1198
1200
  */
1199
1201
  function convertFormat({ schema, name, nullable, defaultValue, options }) {
1200
1202
  const base = buildSchemaNode(schema, name, nullable, defaultValue);
1201
- if (schema.format === "int64") return createSchema({
1203
+ if (schema.format === "int64") return ast.createSchema({
1202
1204
  type: options.integerType === "bigint" ? "bigint" : "integer",
1203
1205
  primitive: "integer",
1204
1206
  ...base,
@@ -1210,14 +1212,14 @@ function createSchemaParser(ctx) {
1210
1212
  if (schema.format === "date-time" || schema.format === "date" || schema.format === "time") {
1211
1213
  const dateType = getDateType(options, schema.format);
1212
1214
  if (!dateType) return null;
1213
- if (dateType.type === "datetime") return createSchema({
1215
+ if (dateType.type === "datetime") return ast.createSchema({
1214
1216
  ...base,
1215
1217
  primitive: "string",
1216
1218
  type: "datetime",
1217
1219
  offset: dateType.offset,
1218
1220
  local: dateType.local
1219
1221
  });
1220
- return createSchema({
1222
+ return ast.createSchema({
1221
1223
  ...base,
1222
1224
  primitive: "string",
1223
1225
  type: dateType.type,
@@ -1227,36 +1229,36 @@ function createSchemaParser(ctx) {
1227
1229
  const specialType = getSchemaType(schema.format);
1228
1230
  if (!specialType) return null;
1229
1231
  const specialPrimitive = specialType === "number" || specialType === "integer" || specialType === "bigint" ? specialType : "string";
1230
- if (specialType === "number" || specialType === "integer" || specialType === "bigint") return createSchema({
1232
+ if (specialType === "number" || specialType === "integer" || specialType === "bigint") return ast.createSchema({
1231
1233
  ...base,
1232
1234
  primitive: specialPrimitive,
1233
1235
  type: specialType
1234
1236
  });
1235
- if (specialType === "url") return createSchema({
1237
+ if (specialType === "url") return ast.createSchema({
1236
1238
  ...base,
1237
1239
  primitive: "string",
1238
1240
  type: "url",
1239
1241
  min: schema.minLength,
1240
1242
  max: schema.maxLength
1241
1243
  });
1242
- if (specialType === "ipv4") return createSchema({
1244
+ if (specialType === "ipv4") return ast.createSchema({
1243
1245
  ...base,
1244
1246
  primitive: "string",
1245
1247
  type: "ipv4"
1246
1248
  });
1247
- if (specialType === "ipv6") return createSchema({
1249
+ if (specialType === "ipv6") return ast.createSchema({
1248
1250
  ...base,
1249
1251
  primitive: "string",
1250
1252
  type: "ipv6"
1251
1253
  });
1252
- if (specialType === "uuid" || specialType === "email") return createSchema({
1254
+ if (specialType === "uuid" || specialType === "email") return ast.createSchema({
1253
1255
  ...base,
1254
1256
  primitive: "string",
1255
1257
  type: specialType,
1256
1258
  min: schema.minLength,
1257
1259
  max: schema.maxLength
1258
1260
  });
1259
- return createSchema({
1261
+ return ast.createSchema({
1260
1262
  ...base,
1261
1263
  primitive: specialPrimitive,
1262
1264
  type: specialType
@@ -1292,7 +1294,7 @@ function createSchemaParser(ctx) {
1292
1294
  if (extensionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
1293
1295
  const enumPrimitiveType = enumPrimitive === "number" || enumPrimitive === "integer" ? "number" : enumPrimitive === "boolean" ? "boolean" : "string";
1294
1296
  const sourceValues = extensionKey ? [...new Set(schema[extensionKey])] : [...new Set(filteredValues)];
1295
- return createSchema({
1297
+ return ast.createSchema({
1296
1298
  ...enumBase,
1297
1299
  primitive: enumPrimitiveType,
1298
1300
  namedEnumValues: sourceValues.map((label, index) => ({
@@ -1302,7 +1304,7 @@ function createSchemaParser(ctx) {
1302
1304
  }))
1303
1305
  });
1304
1306
  }
1305
- return createSchema({
1307
+ return ast.createSchema({
1306
1308
  ...enumBase,
1307
1309
  enumValues: [...new Set(filteredValues)]
1308
1310
  });
@@ -1315,19 +1317,20 @@ function createSchemaParser(ctx) {
1315
1317
  const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
1316
1318
  const resolvedPropSchema = propSchema;
1317
1319
  const propNullable = isNullable(resolvedPropSchema);
1318
- let schemaNode = setEnumName(parseSchema({
1320
+ const propNode = parseSchema({
1319
1321
  schema: resolvedPropSchema,
1320
- name: childName(name, propName)
1321
- }, rawOptions), name, propName, options.enumSuffix);
1322
- const tupleNode = narrowSchema(schemaNode, "tuple");
1322
+ name: ast.childName(name, propName)
1323
+ }, rawOptions);
1324
+ let schemaNode = ast.setEnumName(propNode, name, propName, options.enumSuffix);
1325
+ const tupleNode = ast.narrowSchema(schemaNode, "tuple");
1323
1326
  if (tupleNode?.items) {
1324
- const namedItems = tupleNode.items.map((item) => setEnumName(item, name, propName, options.enumSuffix));
1327
+ const namedItems = tupleNode.items.map((item) => ast.setEnumName(item, name, propName, options.enumSuffix));
1325
1328
  if (namedItems.some((item, i) => item !== tupleNode.items[i])) schemaNode = {
1326
1329
  ...tupleNode,
1327
1330
  items: namedItems
1328
1331
  };
1329
1332
  }
1330
- return createProperty({
1333
+ return ast.createProperty({
1331
1334
  name: propName,
1332
1335
  schema: {
1333
1336
  ...schemaNode,
@@ -1341,10 +1344,10 @@ function createSchemaParser(ctx) {
1341
1344
  if (additionalProperties === true) additionalPropertiesNode = true;
1342
1345
  else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = parseSchema({ schema: additionalProperties }, rawOptions);
1343
1346
  else if (additionalProperties === false) additionalPropertiesNode = false;
1344
- else if (additionalProperties) additionalPropertiesNode = createSchema({ type: typeOptionMap.get(options.unknownType) });
1347
+ else if (additionalProperties) additionalPropertiesNode = ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
1345
1348
  const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
1346
- const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? createSchema({ type: typeOptionMap.get(options.unknownType) }) : parseSchema({ schema: patternSchema }, rawOptions)])) : void 0;
1347
- const objectNode = createSchema({
1349
+ const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? ast.createSchema({ type: typeOptionMap.get(options.unknownType) }) : parseSchema({ schema: patternSchema }, rawOptions)])) : void 0;
1350
+ const objectNode = ast.createSchema({
1348
1351
  type: "object",
1349
1352
  primitive: "object",
1350
1353
  properties,
@@ -1356,11 +1359,13 @@ function createSchemaParser(ctx) {
1356
1359
  });
1357
1360
  if (isDiscriminator(schema) && schema.discriminator.mapping) {
1358
1361
  const discPropName = schema.discriminator.propertyName;
1359
- return setDiscriminatorEnum({
1362
+ const values = Object.keys(schema.discriminator.mapping);
1363
+ const enumName = name ? ast.enumPropName(name, discPropName, options.enumSuffix) : void 0;
1364
+ return ast.setDiscriminatorEnum({
1360
1365
  node: objectNode,
1361
1366
  propertyName: discPropName,
1362
- values: Object.keys(schema.discriminator.mapping),
1363
- enumName: name ? enumPropName(name, discPropName, options.enumSuffix) : void 0
1367
+ values,
1368
+ enumName
1364
1369
  });
1365
1370
  }
1366
1371
  return objectNode;
@@ -1369,11 +1374,13 @@ function createSchemaParser(ctx) {
1369
1374
  * Converts an OAS 3.1 `prefixItems` tuple into a `TupleSchemaNode`.
1370
1375
  */
1371
1376
  function convertTuple({ schema, name, nullable, defaultValue, rawOptions }) {
1372
- return createSchema({
1377
+ const tupleItems = (schema.prefixItems ?? []).map((item) => parseSchema({ schema: item }, rawOptions));
1378
+ const rest = schema.items ? parseSchema({ schema: schema.items }, rawOptions) : ast.createSchema({ type: "any" });
1379
+ return ast.createSchema({
1373
1380
  type: "tuple",
1374
1381
  primitive: "array",
1375
- items: (schema.prefixItems ?? []).map((item) => parseSchema({ schema: item }, rawOptions)),
1376
- rest: schema.items ? parseSchema({ schema: schema.items }, rawOptions) : createSchema({ type: "any" }),
1382
+ items: tupleItems,
1383
+ rest,
1377
1384
  min: schema.minItems,
1378
1385
  max: schema.maxItems,
1379
1386
  ...buildSchemaNode(schema, name, nullable, defaultValue)
@@ -1384,14 +1391,15 @@ function createSchemaParser(ctx) {
1384
1391
  */
1385
1392
  function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
1386
1393
  const rawItems = schema.items;
1387
- const itemName = rawItems?.enum?.length && name ? enumPropName(void 0, name, options.enumSuffix) : void 0;
1388
- return createSchema({
1394
+ const itemName = rawItems?.enum?.length && name ? ast.enumPropName(void 0, name, options.enumSuffix) : void 0;
1395
+ const items = rawItems ? [parseSchema({
1396
+ schema: rawItems,
1397
+ name: itemName
1398
+ }, rawOptions)] : [];
1399
+ return ast.createSchema({
1389
1400
  type: "array",
1390
1401
  primitive: "array",
1391
- items: rawItems ? [parseSchema({
1392
- schema: rawItems,
1393
- name: itemName
1394
- }, rawOptions)] : [],
1402
+ items,
1395
1403
  min: schema.minItems,
1396
1404
  max: schema.maxItems,
1397
1405
  unique: schema.uniqueItems ?? void 0,
@@ -1402,7 +1410,7 @@ function createSchemaParser(ctx) {
1402
1410
  * Converts a `type: 'string'` schema into a `StringSchemaNode`.
1403
1411
  */
1404
1412
  function convertString({ schema, name, nullable, defaultValue }) {
1405
- return createSchema({
1413
+ return ast.createSchema({
1406
1414
  type: "string",
1407
1415
  primitive: "string",
1408
1416
  min: schema.minLength,
@@ -1415,7 +1423,7 @@ function createSchemaParser(ctx) {
1415
1423
  * Converts a `type: 'number'` or `type: 'integer'` schema.
1416
1424
  */
1417
1425
  function convertNumeric({ schema, name, nullable, defaultValue }, type) {
1418
- return createSchema({
1426
+ return ast.createSchema({
1419
1427
  type,
1420
1428
  primitive: type,
1421
1429
  min: schema.minimum,
@@ -1430,7 +1438,7 @@ function createSchemaParser(ctx) {
1430
1438
  * Converts a `type: 'boolean'` schema.
1431
1439
  */
1432
1440
  function convertBoolean({ schema, name, nullable, defaultValue }) {
1433
- return createSchema({
1441
+ return ast.createSchema({
1434
1442
  type: "boolean",
1435
1443
  primitive: "boolean",
1436
1444
  ...buildSchemaNode(schema, name, nullable, defaultValue)
@@ -1440,7 +1448,7 @@ function createSchemaParser(ctx) {
1440
1448
  * Converts an explicit `type: 'null'` schema.
1441
1449
  */
1442
1450
  function convertNull({ schema, name, nullable }) {
1443
- return createSchema({
1451
+ return ast.createSchema({
1444
1452
  type: "null",
1445
1453
  primitive: "null",
1446
1454
  name,
@@ -1487,7 +1495,7 @@ function createSchemaParser(ctx) {
1487
1495
  const formatResult = convertFormat(ctx);
1488
1496
  if (formatResult) return formatResult;
1489
1497
  }
1490
- if (schema.type === "string" && schema.contentMediaType === "application/octet-stream") return createSchema({
1498
+ if (schema.type === "string" && schema.contentMediaType === "application/octet-stream") return ast.createSchema({
1491
1499
  type: "blob",
1492
1500
  primitive: "string",
1493
1501
  ...buildSchemaNode(schema, name, nullable, defaultValue)
@@ -1495,7 +1503,7 @@ function createSchemaParser(ctx) {
1495
1503
  if (Array.isArray(schema.type) && schema.type.length > 1) {
1496
1504
  const nonNullTypes = schema.type.filter((t) => t !== "null");
1497
1505
  const arrayNullable = schema.type.includes("null") || nullable || void 0;
1498
- if (nonNullTypes.length > 1) return createSchema({
1506
+ if (nonNullTypes.length > 1) return ast.createSchema({
1499
1507
  type: "union",
1500
1508
  members: nonNullTypes.map((t) => parseSchema({
1501
1509
  schema: {
@@ -1520,8 +1528,9 @@ function createSchemaParser(ctx) {
1520
1528
  if (type === "integer") return convertNumeric(ctx, "integer");
1521
1529
  if (type === "boolean") return convertBoolean(ctx);
1522
1530
  if (type === "null") return convertNull(ctx);
1523
- return createSchema({
1524
- type: typeOptionMap.get(options.emptySchemaType),
1531
+ const emptyType = typeOptionMap.get(options.emptySchemaType);
1532
+ return ast.createSchema({
1533
+ type: emptyType,
1525
1534
  name,
1526
1535
  title: schema.title,
1527
1536
  description: schema.description
@@ -1532,8 +1541,8 @@ function createSchemaParser(ctx) {
1532
1541
  */
1533
1542
  function parseParameter(options, param) {
1534
1543
  const required = param["required"] ?? false;
1535
- const schema = param["schema"] ? parseSchema({ schema: param["schema"] }, options) : createSchema({ type: typeOptionMap.get(options.unknownType) });
1536
- return createParameter({
1544
+ const schema = param["schema"] ? parseSchema({ schema: param["schema"] }, options) : ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
1545
+ return ast.createParameter({
1537
1546
  name: param["name"],
1538
1547
  in: param["in"],
1539
1548
  schema: {
@@ -1560,7 +1569,7 @@ function createSchemaParser(ctx) {
1560
1569
  })();
1561
1570
  const requestBody = requestBodySchemaNode ? {
1562
1571
  description: requestBodyDescription,
1563
- schema: syncOptionality(requestBodySchemaNode, requestBodyRequired),
1572
+ schema: ast.syncOptionality(requestBodySchemaNode, requestBodyRequired),
1564
1573
  keysToOmit: requestBodyKeysToOmit?.length ? requestBodyKeysToOmit : void 0,
1565
1574
  required: requestBodyRequired || void 0,
1566
1575
  contentType: requestBodyContentType
@@ -1568,12 +1577,12 @@ function createSchemaParser(ctx) {
1568
1577
  const responses = operation.getResponseStatusCodes().map((statusCode) => {
1569
1578
  const responseObj = operation.getResponseByStatusCode(statusCode);
1570
1579
  const responseSchema = getResponseSchema(document, operation, statusCode, { contentType: ctx.contentType });
1571
- const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({ schema: responseSchema }, options) : createSchema({ type: typeOptionMap.get(options.emptySchemaType) });
1580
+ const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({ schema: responseSchema }, options) : ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType) });
1572
1581
  const description = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.description : void 0;
1573
1582
  const rawContent = typeof responseObj === "object" && responseObj !== null && !Array.isArray(responseObj) ? responseObj.content : void 0;
1574
1583
  const mediaType = rawContent ? getMediaType(Object.keys(rawContent)[0] ?? "") : getMediaType(operation.contentType ?? "");
1575
1584
  const keysToOmit = responseSchema?.properties ? Object.entries(responseSchema.properties).filter(([, prop]) => !isReference(prop) && prop.writeOnly).map(([key]) => key) : void 0;
1576
- return createResponse({
1585
+ return ast.createResponse({
1577
1586
  statusCode,
1578
1587
  description,
1579
1588
  schema,
@@ -1582,7 +1591,7 @@ function createSchemaParser(ctx) {
1582
1591
  });
1583
1592
  });
1584
1593
  const urlPath = new URLPath(operation.path);
1585
- return createOperation({
1594
+ return ast.createOperation({
1586
1595
  operationId: operation.getOperationId(),
1587
1596
  method: operation.method.toUpperCase(),
1588
1597
  path: urlPath.path,
@@ -1630,10 +1639,11 @@ function parseOas(document, options = {}) {
1630
1639
  name
1631
1640
  }, mergedOptions));
1632
1641
  const paths = new BaseOas(document).getPaths();
1642
+ const operations = Object.entries(paths).flatMap(([_path, methods]) => Object.entries(methods).map(([, operation]) => operation ? _parseOperation(mergedOptions, operation) : null).filter((op) => op !== null));
1633
1643
  return {
1634
- root: createInput({
1644
+ root: ast.createInput({
1635
1645
  schemas,
1636
- operations: Object.entries(paths).flatMap(([_path, methods]) => Object.entries(methods).map(([, operation]) => operation ? _parseOperation(mergedOptions, operation) : null).filter((op) => op !== null))
1646
+ operations
1637
1647
  }),
1638
1648
  nameMapping
1639
1649
  };
@@ -1692,13 +1702,13 @@ const adapterOas = createAdapter((options) => {
1692
1702
  return inputNode;
1693
1703
  },
1694
1704
  getImports(node, resolve) {
1695
- return collectImports({
1705
+ return ast.collectImports({
1696
1706
  node,
1697
1707
  nameMapping,
1698
1708
  resolve: (schemaName) => {
1699
1709
  const result = resolve(schemaName);
1700
1710
  if (!result) return;
1701
- return createImport({
1711
+ return ast.createImport({
1702
1712
  name: [result.name],
1703
1713
  path: result.path
1704
1714
  });
@@ -1721,7 +1731,7 @@ const adapterOas = createAdapter((options) => {
1721
1731
  const node = discriminator === "inherit" ? applyDiscriminatorInheritance(parsedRoot) : parsedRoot;
1722
1732
  nameMapping = parsedNameMapping;
1723
1733
  parsedDocument = document;
1724
- inputNode = createInput({
1734
+ inputNode = ast.createInput({
1725
1735
  ...node,
1726
1736
  meta: {
1727
1737
  title: document.info?.title,