@workos/oagen 0.14.1 → 0.16.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"differ-fdF9qogA.d.mts","names":[],"sources":["../src/compat/classify.ts","../src/compat/spec-filter.ts","../src/compat/differ.ts"],"mappings":";;;;UAaiB,gBAAA;EAcJ;EAZX,QAAA,EAAU,oBAAA;EAAV;EAEA,QAAA,EAAU,oBAAA;EAAV;EAEA,MAAA;EAAA;EAEA,kBAAA;EAEA;EAAA,UAAA,EAAY,gBAAA;EAEZ;EAAA,GAAA,EAAK,MAAA;EAEL;EAAA,GAAA,EAAK,MAAA;EAEL;EAAA,OAAA;EAOW;;AAIb;;;;EAJE,WAAA;AAAA;;UAIe,oBAAA;EACf,OAAA,EAAS,gBAAA;EACT,OAAA;IACE,QAAA;IACA,QAAA;IACA,QAAA;EAAA;AAAA;;;;;iBAYY,qBAAA,CACd,QAAA,EAAU,YAAA,EACV,SAAA,EAAW,YAAA,cACX,MAAA,EAAQ,iBAAA,GACP,gBAAA;;;;iBAkUa,mBAAA,CAAoB,MAAA,EAAQ,YAAA,GAAe,gBAAA;;iBAc3C,gBAAA,CAAiB,OAAA,EAAS,gBAAA,KAAqB,oBAAA;;;;AAhY/D;;;;iBCJgB,gBAAA,CAAiB,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,aAAA,GAAgB,GAAA;;;;;iBA0CvD,qBAAA,CAAsB,IAAA,EAAM,OAAA,GAAU,GAAA,SAAY,GAAA;;;;;;iBAalD,qBAAA,CAAsB,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,aAAA,GAAgB,GAAA;;;;;;iBAqB5D,sBAAA,CAAuB,IAAA,EAAM,OAAA,GAAU,GAAA;;;;;iBAcvC,mBAAA,CAAoB,IAAA,EAAM,OAAA,GAAU,GAAA;;;;;;;;;;;;AD1CpD;;;;iBC8FgB,aAAA,CACd,OAAA,EAAS,UAAA,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AAM,OAAA,GAAU,GAAA,SAAY,GAAA;;;;;;iBAalD,qBAAA,CAAsB,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,aAAA,GAAgB,GAAA;;;;;;iBAqB5D,sBAAA,CAAuB,IAAA,EAAM,OAAA,GAAU,GAAA;;;;;iBAcvC,mBAAA,CAAoB,IAAA,EAAM,OAAA,GAAU,GAAA;;;;;;;;;;;;AD1CpD;;;;iBC8FgB,aAAA,CACd,OAAA,EAAS,UAAA,EACT,YAAA,EAAc,GAAA,UACd,IAAA;EACE,UAAA,GAAa,GAAA;EACb,WAAA,GAAc,GAAA;EACd,UAAA,GAAa,GAAA,SAAY,GAAA;AAAA,IAE1B,UAAA;;;;UChIc,gBAAA;EACf,OAAA,EAAS,gBAAA;EACT,OAAA,EAAS,oBAAA;AAAA;;;;;iBAOK,aAAA,CACd,QAAA,EAAU,cAAA,EACV,SAAA,EAAW,cAAA,EACX,MAAA,GAAS,iBAAA,GACR,gBAAA;;;;;;AFJH;;;iBE4pBgB,YAAA,CAAa,QAAA,EAAU,UAAA,EAAY,SAAA,EAAW,UAAA,EAAY,KAAA,EAAO,aAAA,GAAgB,UAAA"}
package/dist/index.mjs CHANGED
@@ -380,6 +380,7 @@ function findNestedFieldSchema(fieldName, parentSchema, schemas) {
380
380
  function extractNestedSchema(name, schema) {
381
381
  if (schema.oneOf) {
382
382
  const models = [];
383
+ const constNamingDiscriminator = deriveConstNamingDiscriminator(schema.oneOf.filter((v) => !v.$ref && v.properties && (v.type === "object" || !v.type)));
383
384
  for (const variant of schema.oneOf) {
384
385
  if (variant.$ref) continue;
385
386
  if (variant.properties && (variant.type === "object" || !variant.type)) {
@@ -389,7 +390,7 @@ function extractNestedSchema(name, schema) {
389
390
  if (!fs) continue;
390
391
  fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));
391
392
  }
392
- const variantName = models.length === 0 ? name : `${name}${models.length + 1}`;
393
+ const variantName = nameVariantModel(variant, name, models, constNamingDiscriminator);
393
394
  models.push({
394
395
  name: variantName,
395
396
  description: variant.description,
@@ -427,6 +428,69 @@ function extractNestedSchema(name, schema) {
427
428
  }
428
429
  return [];
429
430
  }
431
+ /**
432
+ * Derive a meaningful name for a oneOf object variant past the first,
433
+ * falling back to the numeric-suffix scheme (`Foo2`, `Foo3`) when no
434
+ * better signal is available. The "better signal" is a const-valued
435
+ * discriminator property that distinguishes one variant from the others.
436
+ *
437
+ * For a schema like `ApiKey.owner` whose oneOf has two variants — one
438
+ * with `type: { const: "organization" }` and one with `type: { const:
439
+ * "user" }` — this returns `ApiKeyOwner` for the first variant (the
440
+ * baseline name that the union TypeRef will reference, so consumer-
441
+ * visible typed fields stay backward-compatible) and `UserApiKeyOwner`
442
+ * for the second instead of `ApiKeyOwner2`. SDK consumers reading the
443
+ * generated types can tell the variants apart at a glance.
444
+ *
445
+ * The first variant always keeps the bare parent name because
446
+ * `schemaToTypeRef` builds union variants whose model refs collapse to
447
+ * `qualifyInlineModelName(field, parent)` — so the first model name
448
+ * must match for the union's degenerate-collapse to land on a valid
449
+ * type. Renaming variant 0 would orphan it.
450
+ *
451
+ * Falls back to numeric suffix when:
452
+ * - The variant has no discriminator property (no shared const
453
+ * property across all object variants), OR
454
+ * - The const value PascalCases to an empty/whitespace name, OR
455
+ * - The derived name collides with the parent name or an already-
456
+ * emitted variant name (numeric keeps uniqueness).
457
+ */
458
+ function nameVariantModel(variant, parentName, alreadyEmitted, discriminator) {
459
+ if (alreadyEmitted.length === 0) return parentName;
460
+ if (discriminator) {
461
+ const constValue = getConstPropertyValue(variant, discriminator.property);
462
+ if (constValue) {
463
+ const prefix = toPascalCase(constValue);
464
+ if (prefix) {
465
+ const candidate = parentName.startsWith(prefix) ? parentName : `${prefix}${parentName}`;
466
+ if (!(candidate === parentName || alreadyEmitted.some((m) => m.name === candidate))) return candidate;
467
+ }
468
+ }
469
+ }
470
+ return `${parentName}${alreadyEmitted.length + 1}`;
471
+ }
472
+ /**
473
+ * Returns a discriminator descriptor when every inline object variant in a
474
+ * oneOf has a string-const value on the same property — the signature of a
475
+ * discriminated union without an explicit `discriminator:` keyword. Used by
476
+ * `nameVariantModel` to derive variant names from the const values.
477
+ *
478
+ * Distinct from `detectConstPropertyDiscriminator` (which requires every
479
+ * variant to carry a `$ref` or `title` so a name mapping can be built):
480
+ * this pass operates on inline anonymous variants, where naming is exactly
481
+ * what we're trying to derive.
482
+ */
483
+ function deriveConstNamingDiscriminator(variants) {
484
+ if (variants.length < 2) return null;
485
+ const candidates = Object.keys(variants[0]?.properties ?? {});
486
+ for (const propName of candidates) {
487
+ const values = variants.map((v) => getConstPropertyValue(v, propName));
488
+ if (values.some((v) => v === null)) continue;
489
+ if (new Set(values).size !== values.length) continue;
490
+ return { property: propName };
491
+ }
492
+ return null;
493
+ }
430
494
  /** Build a single Field from a schema property entry. Shared across all extraction sites. */
431
495
  function buildFieldFromSchema(fieldName, fieldSchema, contextName, requiredSet) {
432
496
  return {