@workos/oagen 0.6.0 → 0.7.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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as collectModelRefs, B as LoggingPolicy, C as TypeParam, D as assignModelsToServices, E as assertNever, F as BackoffStrategy, G as TelemetryPolicy, H as RequestGuardPolicy, I as DeepPartial, J as defaultSdkBehavior, K as TimeoutPolicy, L as ErrorPolicy, M as mapTypeRef, N as walkTypeRef, O as collectEnumRefs, P as AiAgentEnvVar, R as IdempotencyPolicy, S as SuccessResponse, T as UnionType, U as RetryPolicy, V as PaginationPolicy, W as SdkBehavior, Y as mergeSdkBehavior, _ as Parameter, a as EnumRef, b as ServerEntry, c as Field, d as MapType, f as Model, g as PaginationMeta, h as Operation, i as Enum, it as ApiSurface, j as collectRequestBodyModels, k as collectFieldDependencies, l as HttpMethod, m as NullableType, n as ArrayType, o as EnumValue, p as ModelRef, q as UserAgentPolicy, r as AuthScheme, s as ErrorResponse, st as Extractor, t as ApiSpec, u as LiteralType, ut as OverlayLookup, v as PrimitiveType, w as TypeRef, x as Service, y as SecurityRequirement, z as LogEvent } from "./types-C7g5sLuX.mjs";
1
+ import { A as collectEnumRefs, B as IdempotencyPolicy, C as Service, D as UnionType, E as TypeRef, F as walkTypeRef, G as RetryPolicy, H as LoggingPolicy, I as AiAgentEnvVar, J as TimeoutPolicy, K as SdkBehavior, L as BackoffStrategy, M as collectModelRefs, N as collectRequestBodyModels, O as assertNever, P as mapTypeRef, R as DeepPartial, S as ServerEntry, T as TypeParam, U as PaginationPolicy, V as LogEvent, W as RequestGuardPolicy, X as defaultSdkBehavior, Y as UserAgentPolicy, Z as mergeSdkBehavior, _ as Parameter, a as EnumRef, b as PrimitiveType, c as Field, d as MapType, f as Model, ft as OverlayLookup, g as PaginationMeta, h as Operation, i as Enum, j as collectFieldDependencies, k as assignModelsToServices, l as HttpMethod, lt as Extractor, m as NullableType, n as ArrayType, o as EnumValue, ot as ApiSurface, p as ModelRef, q as TelemetryPolicy, r as AuthScheme, s as ErrorResponse, t as ApiSpec, u as LiteralType, v as ParameterGroup, w as SuccessResponse, x as SecurityRequirement, y as ParameterGroupVariant, z as ErrorPolicy } from "./types-DJMbCtIO.mjs";
2
2
 
3
3
  //#region src/ir/operation-hints.d.ts
4
4
  /** Per-operation override keyed by "METHOD /path" (e.g. "POST /sso/token"). */
@@ -466,5 +466,5 @@ interface OagenConfig {
466
466
  mountRules?: Record<string, string>;
467
467
  }
468
468
  //#endregion
469
- export { ACRONYM_SET, type AiAgentEnvVar, type ApiSpec, type ArrayType, type AuthScheme, type BackoffStrategy, type Change, CommandError, ConfigError, ConfigLoadError, ConfigVersionMismatchError, type DeepPartial, type DiffReport, type Emitter, type EmitterContext, type Enum, type EnumAdded, type EnumModified, type EnumRef, type EnumRemoved, type EnumValue, type EnumValueChange, type ErrorPolicy, type ErrorResponse, ExtractorError, type Field, type FieldChange, type FormatCommand, type GeneratedFile, type HttpMethod, type IdempotencyPolicy, InternalError, type LiteralType, type LogEvent, type LoggingPolicy, type MapType, type Model, type ModelAdded, type ModelModified, type ModelRef, type ModelRemoved, type NullableType, type OagenConfig, OagenError, type Operation, type OperationAdded, type OperationHint, type OperationModified, type OperationPlan, type OperationRemoved, type PaginationMeta, type PaginationPolicy, type ParamChange, type Parameter, type PrimitiveType, RegistryError, type RequestGuardPolicy, type ResolvedOperation, type ResolvedWrapper, type RetryPolicy, type SdkBehavior, type SecurityRequirement, type ServerEntry, type Service, type ServiceAdded, type ServiceRemoved, SpecParseError, type SplitHint, type SuccessResponse, type TelemetryPolicy, type TimeoutPolicy, type TypeParam, type TypeRef, type UnionType, type UserAgentPolicy, applyFileHeaders, assertNever, assignModelsToServices, buildEmitterContext, cleanSchemaName, collectEnumRefs, collectFieldDependencies, collectModelRefs, collectReferencedNames, collectRequestBodyModels, defaultSdkBehavior, deriveMethodName, diffSpecs, generate, generateAllFiles, generateFiles, getEmitter, integrateGeneratedFiles, mapFilesForTargetIntegration, mapTypeRef, mergeSdkBehavior, parseSpec, planOperation, registerEmitter, resolveOperations, stripBackendPrefixes, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, toUpperSnakeCase, treeShakeFiles, walkTypeRef };
469
+ export { ACRONYM_SET, type AiAgentEnvVar, type ApiSpec, type ArrayType, type AuthScheme, type BackoffStrategy, type Change, CommandError, ConfigError, ConfigLoadError, ConfigVersionMismatchError, type DeepPartial, type DiffReport, type Emitter, type EmitterContext, type Enum, type EnumAdded, type EnumModified, type EnumRef, type EnumRemoved, type EnumValue, type EnumValueChange, type ErrorPolicy, type ErrorResponse, ExtractorError, type Field, type FieldChange, type FormatCommand, type GeneratedFile, type HttpMethod, type IdempotencyPolicy, InternalError, type LiteralType, type LogEvent, type LoggingPolicy, type MapType, type Model, type ModelAdded, type ModelModified, type ModelRef, type ModelRemoved, type NullableType, type OagenConfig, OagenError, type Operation, type OperationAdded, type OperationHint, type OperationModified, type OperationPlan, type OperationRemoved, type PaginationMeta, type PaginationPolicy, type ParamChange, type Parameter, type ParameterGroup, type ParameterGroupVariant, type PrimitiveType, RegistryError, type RequestGuardPolicy, type ResolvedOperation, type ResolvedWrapper, type RetryPolicy, type SdkBehavior, type SecurityRequirement, type ServerEntry, type Service, type ServiceAdded, type ServiceRemoved, SpecParseError, type SplitHint, type SuccessResponse, type TelemetryPolicy, type TimeoutPolicy, type TypeParam, type TypeRef, type UnionType, type UserAgentPolicy, applyFileHeaders, assertNever, assignModelsToServices, buildEmitterContext, cleanSchemaName, collectEnumRefs, collectFieldDependencies, collectModelRefs, collectReferencedNames, collectRequestBodyModels, defaultSdkBehavior, deriveMethodName, diffSpecs, generate, generateAllFiles, generateFiles, getEmitter, integrateGeneratedFiles, mapFilesForTargetIntegration, mapTypeRef, mergeSdkBehavior, parseSpec, planOperation, registerEmitter, resolveOperations, stripBackendPrefixes, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, toUpperSnakeCase, treeShakeFiles, walkTypeRef };
470
470
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as walkTypeRef, C as assertNever, D as collectModelRefs, E as collectFieldDependencies, O as collectRequestBodyModels, S as SpecParseError, T as collectEnumRefs, _ as ConfigVersionMismatchError, a as singularize, b as OagenError, c as stripListItemMarkers, d as toPascalCase, f as toSnakeCase, g as ConfigLoadError, h as ConfigError, k as mapTypeRef, l as toCamelCase, m as CommandError, n as ACRONYM_SET, p as toUpperSnakeCase, r as cleanSchemaName, s as stripBackendPrefixes, u as toKebabCase, v as ExtractorError, w as assignModelsToServices, x as RegistryError, y as InternalError } from "./tree-sitter-C53w_0WE.mjs";
2
- import { a as integrateGeneratedFiles, c as applyFileHeaders, d as generateAllFiles, f as generateFiles, i as generate, l as buildEmitterContext, m as resolveOperations, n as getEmitter, o as mapFilesForTargetIntegration, p as deriveMethodName, r as registerEmitter, s as treeShakeFiles, t as diffSpecs, u as collectReferencedNames } from "./diff-CltJMcwG.mjs";
2
+ import { a as integrateGeneratedFiles, c as applyFileHeaders, d as generateAllFiles, f as generateFiles, i as generate, l as buildEmitterContext, m as resolveOperations, n as getEmitter, o as mapFilesForTargetIntegration, p as deriveMethodName, r as registerEmitter, s as treeShakeFiles, t as diffSpecs, u as collectReferencedNames } from "./diff-BYadQQV7.mjs";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
@@ -353,7 +353,7 @@ function findSchemaByName(pascalName, schemas) {
353
353
  for (const [k, v] of Object.entries(schemas)) if (resolveSchemaName(k) === pascalName) return v;
354
354
  return null;
355
355
  }
356
- /** Walk into a schema to find a field's sub-schema, resolving allOf. */
356
+ /** Walk into a schema to find a field's sub-schema, resolving allOf and oneOf/anyOf. */
357
357
  function findNestedFieldSchema(fieldName, parentSchema, schemas) {
358
358
  if (parentSchema.properties?.[fieldName]) return parentSchema.properties[fieldName];
359
359
  if (parentSchema.allOf) for (const sub of parentSchema.allOf) {
@@ -365,6 +365,15 @@ function findNestedFieldSchema(fieldName, parentSchema, schemas) {
365
365
  }
366
366
  if (resolved.properties?.[fieldName]) return resolved.properties[fieldName];
367
367
  }
368
+ for (const variant of [...parentSchema.oneOf ?? [], ...parentSchema.anyOf ?? []]) {
369
+ let resolved = variant;
370
+ if (variant.$ref) {
371
+ const segments = variant.$ref.split("/");
372
+ const refName = segments[segments.length - 1];
373
+ if (refName && schemas[refName]) resolved = schemas[refName];
374
+ }
375
+ if (resolved.properties?.[fieldName]) return resolved.properties[fieldName];
376
+ }
368
377
  return null;
369
378
  }
370
379
  /** Extract a model (and nested models) from an inline field schema. */
@@ -530,6 +539,19 @@ function extractModel(name, schema, schemas) {
530
539
  if (!fieldSchema) continue;
531
540
  fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));
532
541
  }
542
+ if (fields.length === 0 && (schema.oneOf || schema.anyOf)) {
543
+ const variants = schema.oneOf ?? schema.anyOf ?? [];
544
+ const emptyRequired = /* @__PURE__ */ new Set();
545
+ const seenFieldNames = /* @__PURE__ */ new Set();
546
+ for (const variant of variants) {
547
+ if (!variant.properties) continue;
548
+ for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {
549
+ if (!fieldSchema || seenFieldNames.has(fieldName)) continue;
550
+ seenFieldNames.add(fieldName);
551
+ fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, emptyRequired));
552
+ }
553
+ }
554
+ }
533
555
  if (schema.additionalProperties && typeof schema.additionalProperties === "object" && schema.properties) {
534
556
  if (Object.keys(schema.additionalProperties).length > 0) {
535
557
  const valueType = schemaToTypeRef(schema.additionalProperties, "additionalProperties", name);
@@ -569,6 +591,18 @@ function extractAllOfModel(name, schema, schemas) {
569
591
  });
570
592
  if (f.required) requiredSet.add(f.name);
571
593
  }
594
+ } else if (resolved.oneOf || resolved.anyOf) {
595
+ const variants = resolved.oneOf ?? resolved.anyOf ?? [];
596
+ const emptyRequired = /* @__PURE__ */ new Set();
597
+ const seenFieldNames = new Set(fields.map((f) => f.name));
598
+ for (const variant of variants) {
599
+ if (!variant.properties) continue;
600
+ for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {
601
+ if (!fieldSchema || seenFieldNames.has(fieldName)) continue;
602
+ seenFieldNames.add(fieldName);
603
+ fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, emptyRequired));
604
+ }
605
+ }
572
606
  } else {
573
607
  if (resolved.required) for (const r of resolved.required) requiredSet.add(r);
574
608
  if (resolved.properties) {
@@ -1425,6 +1459,94 @@ function inferDeeperContext(path) {
1425
1459
  if (nonParams.length >= 3) return toPascalCase(nonParams.slice(1, -1).join("_"));
1426
1460
  return null;
1427
1461
  }
1462
+ /**
1463
+ * Extract mutually-exclusive parameter groups from the `x-mutually-exclusive-parameter-groups`
1464
+ * operation extension. Cross-references grouped parameter names against the already-extracted
1465
+ * IR parameter arrays so emitters get object-identity references.
1466
+ */
1467
+ function extractParameterGroups(op, allIRParams, operationContext) {
1468
+ const raw = op["x-mutually-exclusive-parameter-groups"];
1469
+ if (!raw || typeof raw !== "object") return void 0;
1470
+ const paramByName = /* @__PURE__ */ new Map();
1471
+ for (const p of allIRParams) paramByName.set(p.name, p);
1472
+ const groups = [];
1473
+ for (const [groupName, groupDef] of Object.entries(raw)) {
1474
+ if (!groupDef || typeof groupDef !== "object") throw new Error(`Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: expected an object with "optional" and "variants".`);
1475
+ if (typeof groupDef.optional !== "boolean") throw new Error(`Malformed x-mutually-exclusive-parameter-groups.${groupName}.optional in ${operationContext}: expected a boolean.`);
1476
+ if (!groupDef.variants || typeof groupDef.variants !== "object") throw new Error(`Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants in ${operationContext}: expected an object mapping variant names to parameter name arrays.`);
1477
+ if (Object.keys(groupDef.variants).length === 0) throw new Error(`Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: group has zero variants.`);
1478
+ const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {
1479
+ if (!Array.isArray(paramNames) || paramNames.length === 0) throw new Error(`Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`);
1480
+ return {
1481
+ name: variantName,
1482
+ parameters: paramNames.map((pName) => {
1483
+ const irParam = paramByName.get(pName);
1484
+ if (!irParam) throw new Error(`x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} references parameter "${pName}" which does not exist in the operation's parameters[] (${operationContext}).`);
1485
+ return irParam;
1486
+ })
1487
+ };
1488
+ });
1489
+ groups.push({
1490
+ name: groupName,
1491
+ optional: groupDef.optional,
1492
+ variants
1493
+ });
1494
+ }
1495
+ return groups.length > 0 ? groups : void 0;
1496
+ }
1497
+ /**
1498
+ * Extract mutually-exclusive body parameter groups from the
1499
+ * `x-mutually-exclusive-body-groups` operation extension. Unlike query
1500
+ * parameter groups (whose parameters live in operation.queryParams), body
1501
+ * group parameters are synthetic — built from the oneOf variant schemas in
1502
+ * the request body. Emitters use the group's presence to generate sum-type
1503
+ * interfaces and custom JSON marshalling instead of flat optional fields.
1504
+ */
1505
+ function extractBodyParameterGroups(op, operationContext) {
1506
+ const raw = op["x-mutually-exclusive-body-groups"];
1507
+ if (!raw || typeof raw !== "object") return void 0;
1508
+ const bodySchema = op.requestBody?.content?.["application/json"]?.schema;
1509
+ const variantFieldSchemas = /* @__PURE__ */ new Map();
1510
+ if (bodySchema) {
1511
+ for (const sub of bodySchema.allOf ?? []) for (const variant of sub.oneOf ?? []) if (variant.properties) {
1512
+ for (const [name, fieldSchema] of Object.entries(variant.properties)) if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);
1513
+ }
1514
+ for (const variant of bodySchema.oneOf ?? []) if (variant.properties) {
1515
+ for (const [name, fieldSchema] of Object.entries(variant.properties)) if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);
1516
+ }
1517
+ }
1518
+ const groups = [];
1519
+ for (const [groupName, groupDef] of Object.entries(raw)) {
1520
+ if (!groupDef || typeof groupDef !== "object") continue;
1521
+ if (typeof groupDef.optional !== "boolean") continue;
1522
+ if (!groupDef.variants || typeof groupDef.variants !== "object") continue;
1523
+ if (Object.keys(groupDef.variants).length === 0) continue;
1524
+ const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {
1525
+ if (!Array.isArray(paramNames) || paramNames.length === 0) throw new Error(`Malformed x-mutually-exclusive-body-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`);
1526
+ return {
1527
+ name: variantName,
1528
+ parameters: paramNames.map((pName) => {
1529
+ const fieldSchema = variantFieldSchemas.get(pName);
1530
+ return {
1531
+ name: pName,
1532
+ type: fieldSchema ? schemaToTypeRef(fieldSchema, toPascalCase(pName)) : {
1533
+ kind: "primitive",
1534
+ type: "string"
1535
+ },
1536
+ required: false,
1537
+ description: fieldSchema?.description
1538
+ };
1539
+ })
1540
+ };
1541
+ });
1542
+ groups.push({
1543
+ name: groupName,
1544
+ optional: groupDef.optional,
1545
+ variants
1546
+ });
1547
+ }
1548
+ return groups.length > 0 ? groups : void 0;
1549
+ }
1428
1550
  function buildOperation(method, path, op, pathLevelParams, operationIdTransform, serviceName) {
1429
1551
  const allParams = [...pathLevelParams, ...op.parameters ?? []];
1430
1552
  const hasIdempotencyHeader = allParams.some((p) => p.in === "header" && p.name.toLowerCase() === "idempotency-key");
@@ -1450,6 +1572,16 @@ function buildOperation(method, path, op, pathLevelParams, operationIdTransform,
1450
1572
  };
1451
1573
  } else if (paginationFromParams) pagination = paginationFromParams;
1452
1574
  const security = extractOperationSecurity(op.security);
1575
+ const allIRParams = [
1576
+ ...pathParams,
1577
+ ...queryParams,
1578
+ ...headerParams,
1579
+ ...cookieParams
1580
+ ];
1581
+ const opLabel = op.operationId ?? `${method.toUpperCase()} ${path}`;
1582
+ const queryParamGroups = extractParameterGroups(op, allIRParams, opLabel);
1583
+ const bodyParamGroups = extractBodyParameterGroups(op, opLabel);
1584
+ const parameterGroups = queryParamGroups || bodyParamGroups ? [...queryParamGroups ?? [], ...bodyParamGroups ?? []] : void 0;
1453
1585
  return {
1454
1586
  operation: {
1455
1587
  name: inferOperationName(method, path, op.operationId, operationIdTransform),
@@ -1469,7 +1601,8 @@ function buildOperation(method, path, op, pathLevelParams, operationIdTransform,
1469
1601
  injectIdempotencyKey: hasIdempotencyHeader,
1470
1602
  deprecated: op.deprecated || void 0,
1471
1603
  async: op["x-oagen-async"],
1472
- security
1604
+ security,
1605
+ parameterGroups
1473
1606
  },
1474
1607
  inlineModels
1475
1608
  };