@kubb/adapter-oas 5.0.0-alpha.24 → 5.0.0-alpha.26

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
@@ -70,7 +70,8 @@ const structuralKeys = new Set([
70
70
  *
71
71
  * Only formats whose AST type differs from the OAS `type` field appear here.
72
72
  * Formats that depend on runtime options (`int64`, `date-time`, `date`, `time`) are handled separately
73
- * in the parser. `ipv4`, `ipv6`, and `hostname` map to `'url'` as the closest supported scalar.
73
+ * in the parser. `ipv4` and `ipv6` map to their own dedicated schema types; `hostname` and
74
+ * `idn-hostname` map to `'url'` as the closest generic string-format type.
74
75
  *
75
76
  * @example
76
77
  * ```ts
@@ -88,8 +89,8 @@ const formatMap = {
88
89
  uri: "url",
89
90
  "uri-reference": "url",
90
91
  url: "url",
91
- ipv4: "url",
92
- ipv6: "url",
92
+ ipv4: "ipv4",
93
+ ipv6: "ipv6",
93
94
  hostname: "url",
94
95
  "idn-hostname": "url",
95
96
  binary: "blob",
@@ -528,10 +529,11 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
528
529
  * ```
529
530
  */
530
531
  async function mergeDocuments(pathOrApi) {
531
- const documents = await Promise.all(pathOrApi.map((p) => parseDocument(p, {
532
+ const documents = [];
533
+ for (const p of pathOrApi) documents.push(await parseDocument(p, {
532
534
  enablePaths: false,
533
535
  canBundle: false
534
- })));
536
+ }));
535
537
  if (documents.length === 0) throw new Error("No OAS documents provided for merging.");
536
538
  const seed = {
537
539
  openapi: MERGE_OPENAPI_VERSION,
@@ -997,21 +999,35 @@ function normalizeArrayEnum(schema) {
997
999
  function createSchemaParser(ctx) {
998
1000
  const document = ctx.document;
999
1001
  /**
1002
+ * Tracks `$ref` paths that are currently being resolved to prevent infinite
1003
+ * recursion when schemas contain circular references (e.g. `Pet → parent → Pet`).
1004
+ */
1005
+ const resolvingRefs = /* @__PURE__ */ new Set();
1006
+ /**
1000
1007
  * Converts a `$ref` schema into a `RefSchemaNode`.
1008
+ *
1009
+ * The resolved schema is stored in `node.schema`. Usage-site sibling fields
1010
+ * (description, readOnly, nullable, etc.) are stored directly on the ref node.
1011
+ * Use `syncSchemaRef(node)` in printers to get a merged view of both.
1012
+ * Circular refs are detected via `resolvingRefs` and leave `schema` as `undefined`.
1001
1013
  */
1002
- function convertRef({ schema, nullable, defaultValue }) {
1014
+ function convertRef({ schema, name, nullable, defaultValue, rawOptions }) {
1015
+ let resolvedSchema;
1016
+ const refPath = schema.$ref;
1017
+ if (refPath && !resolvingRefs.has(refPath)) try {
1018
+ const referenced = resolveRef(document, refPath);
1019
+ if (referenced) {
1020
+ resolvingRefs.add(refPath);
1021
+ resolvedSchema = parseSchema({ schema: referenced }, rawOptions);
1022
+ resolvingRefs.delete(refPath);
1023
+ }
1024
+ } catch {}
1003
1025
  return createSchema({
1026
+ ...buildSchemaNode(schema, name, nullable, defaultValue),
1004
1027
  type: "ref",
1005
1028
  name: extractRefName(schema.$ref),
1006
1029
  ref: schema.$ref,
1007
- nullable,
1008
- description: schema.description,
1009
- deprecated: schema.deprecated,
1010
- readOnly: schema.readOnly,
1011
- writeOnly: schema.writeOnly,
1012
- pattern: schema.type === "string" ? schema.pattern : void 0,
1013
- example: schema.example,
1014
- default: defaultValue
1030
+ schema: resolvedSchema
1015
1031
  });
1016
1032
  }
1017
1033
  /**
@@ -1219,7 +1235,26 @@ function createSchemaParser(ctx) {
1219
1235
  if (specialType === "url") return createSchema({
1220
1236
  ...base,
1221
1237
  primitive: "string",
1222
- type: "url"
1238
+ type: "url",
1239
+ min: schema.minLength,
1240
+ max: schema.maxLength
1241
+ });
1242
+ if (specialType === "ipv4") return createSchema({
1243
+ ...base,
1244
+ primitive: "string",
1245
+ type: "ipv4"
1246
+ });
1247
+ if (specialType === "ipv6") return createSchema({
1248
+ ...base,
1249
+ primitive: "string",
1250
+ type: "ipv6"
1251
+ });
1252
+ if (specialType === "uuid" || specialType === "email") return createSchema({
1253
+ ...base,
1254
+ primitive: "string",
1255
+ type: specialType,
1256
+ min: schema.minLength,
1257
+ max: schema.maxLength
1223
1258
  });
1224
1259
  return createSchema({
1225
1260
  ...base,
@@ -1305,7 +1340,7 @@ function createSchemaParser(ctx) {
1305
1340
  let additionalPropertiesNode;
1306
1341
  if (additionalProperties === true) additionalPropertiesNode = true;
1307
1342
  else if (additionalProperties && Object.keys(additionalProperties).length > 0) additionalPropertiesNode = parseSchema({ schema: additionalProperties }, rawOptions);
1308
- else if (additionalProperties === false) additionalPropertiesNode = void 0;
1343
+ else if (additionalProperties === false) additionalPropertiesNode = false;
1309
1344
  else if (additionalProperties) additionalPropertiesNode = createSchema({ type: typeOptionMap.get(options.unknownType) });
1310
1345
  const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
1311
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;
@@ -1315,6 +1350,8 @@ function createSchemaParser(ctx) {
1315
1350
  properties,
1316
1351
  additionalProperties: additionalPropertiesNode,
1317
1352
  patternProperties,
1353
+ minProperties: schema.minProperties,
1354
+ maxProperties: schema.maxProperties,
1318
1355
  ...buildSchemaNode(schema, name, nullable, defaultValue)
1319
1356
  });
1320
1357
  if (isDiscriminator(schema) && schema.discriminator.mapping) {
@@ -1385,6 +1422,7 @@ function createSchemaParser(ctx) {
1385
1422
  max: schema.maximum,
1386
1423
  exclusiveMinimum: typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum : void 0,
1387
1424
  exclusiveMaximum: typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : void 0,
1425
+ multipleOf: schema.multipleOf,
1388
1426
  ...buildSchemaNode(schema, name, nullable, defaultValue)
1389
1427
  });
1390
1428
  }