@workos/oagen 0.24.6 → 0.25.1

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.
@@ -2534,13 +2534,14 @@ function flattenDiscriminatedUnionBody(schema) {
2534
2534
  /** Derive a unique variant name for a oneOf inline model. */
2535
2535
  function deriveOneOfVariantName(variant, baseName, existingModels) {
2536
2536
  if (variant.properties) {
2537
- for (const [, propSchema] of Object.entries(variant.properties)) if (propSchema?.const && typeof propSchema.const === "string") return toPascalCase(propSchema.const) + baseName.replace(/Request$/, "") + "Request";
2537
+ for (const [, propSchema] of Object.entries(variant.properties)) if (propSchema?.const && typeof propSchema.const === "string") return resolveSchemaName(toPascalCase(propSchema.const) + baseName.replace(/Request$/, "") + "Request");
2538
2538
  }
2539
2539
  const existingNames = new Set(existingModels.map((m) => m.name));
2540
- let name = baseName;
2540
+ const transformedBaseName = resolveSchemaName(baseName);
2541
+ let name = transformedBaseName;
2541
2542
  let suffix = 2;
2542
2543
  while (existingNames.has(name)) {
2543
- name = `${baseName}${suffix}`;
2544
+ name = `${transformedBaseName}${suffix}`;
2544
2545
  suffix++;
2545
2546
  }
2546
2547
  return name;
@@ -5780,11 +5781,44 @@ function deriveMethodName(op, _service) {
5780
5781
  return `${verb}_${verb === "list" ? resource : noun}`;
5781
5782
  }
5782
5783
  /**
5784
+ * Resolve a service name to its mount target.
5785
+ *
5786
+ * Rule keys are either exact service names or trailing-`*` prefix patterns
5787
+ * (e.g. `UserManagement*`). Precedence:
5788
+ *
5789
+ * 1. An exact key always wins.
5790
+ * 2. Otherwise the wildcard with the longest prefix wins, so
5791
+ * `UserManagementOrganizationMembership*` beats `UserManagement*`.
5792
+ *
5793
+ * Matching is plain string comparison (`startsWith`) — `*` is only recognised
5794
+ * as the final character and no regex is ever built from rule keys.
5795
+ *
5796
+ * @param name - The IR service name to resolve.
5797
+ * @param mounts - Exact-name or trailing-`*` pattern → target service mappings.
5798
+ * @returns The mount target, or `name` unchanged when no rule matches.
5799
+ */
5800
+ function resolveMountTarget(name, mounts) {
5801
+ const exact = mounts[name];
5802
+ if (exact !== void 0) return exact;
5803
+ let best;
5804
+ let bestLen = -1;
5805
+ for (const [pattern, target] of Object.entries(mounts)) {
5806
+ if (!pattern.endsWith("*")) continue;
5807
+ const prefix = pattern.slice(0, -1);
5808
+ if (name.startsWith(prefix) && prefix.length > bestLen) {
5809
+ best = target;
5810
+ bestLen = prefix.length;
5811
+ }
5812
+ }
5813
+ return best ?? name;
5814
+ }
5815
+ /**
5783
5816
  * Resolve all operations in the spec, applying hints and mount rules.
5784
5817
  *
5785
5818
  * @param spec - The parsed API spec
5786
5819
  * @param hints - Per-operation overrides keyed by "METHOD /path"
5787
- * @param mountRules - Service name → target service mappings
5820
+ * @param mountRules - Service name → target service mappings; keys may be
5821
+ * exact names or trailing-`*` prefix patterns (see {@link resolveMountTarget})
5788
5822
  * @returns Resolved operations ready for emitter consumption
5789
5823
  */
5790
5824
  function resolveOperations(spec, hints, mountRules) {
@@ -5794,7 +5828,7 @@ function resolveOperations(spec, hints, mountRules) {
5794
5828
  for (const service of spec.services) for (const op of service.operations) {
5795
5829
  const hint = hintMap[`${op.httpMethod.toUpperCase()} ${op.path}`];
5796
5830
  const methodName = hint?.name ?? deriveMethodName(op, service);
5797
- const mountOn = hint?.mountOn ?? mounts[service.name] ?? service.name;
5831
+ const mountOn = hint?.mountOn ?? resolveMountTarget(service.name, mounts);
5798
5832
  let wrappers;
5799
5833
  if (hint?.split) wrappers = hint.split.map((sh) => ({
5800
5834
  name: sh.name,
@@ -5840,16 +5874,18 @@ function resolveResponseModelName(op) {
5840
5874
  *
5841
5875
  * Matching is on the POST-MOUNT name. Mount resolution never mutates
5842
5876
  * `spec.services` — the post-mount target lives on `ResolvedOperation.mountOn`
5843
- * (`mountOn = hint?.mountOn ?? mountRules[service.name] ?? service.name`) — so the
5844
- * post-mount name of a source service is derived here as
5845
- * `mountRules[service.name] ?? service.name`. Selecting a target (e.g.
5877
+ * (`mountOn = hint?.mountOn ?? resolveMountTarget(service.name, mountRules)`) — so
5878
+ * the post-mount name of a source service is derived here with the same
5879
+ * `resolveMountTarget` (exact rules and trailing-`*` prefix rules, longest
5880
+ * prefix wins). Selecting a target (e.g.
5846
5881
  * `DirectorySync`) is valid because every source tag that mounts into it
5847
5882
  * (`DirectoryUsers`, `DirectoryGroups`, …) shares that post-mount name, and the
5848
5883
  * emitters group resources by mount, so all siblings emit together.
5849
5884
  *
5850
5885
  * @param spec - The parsed API spec (never mutated; never filtered).
5851
5886
  * @param selected - Post-mount service names from `--services` (normalized/trimmed).
5852
- * @param mountRules - Source-service-name → post-mount-target mappings.
5887
+ * @param mountRules - Source-service-name (exact or trailing-`*` prefix pattern)
5888
+ * → post-mount-target mappings.
5853
5889
  * @returns The validated selection as a `Set` of post-mount names.
5854
5890
  * @throws A `ConfigError` listing valid post-mount names when a selection is
5855
5891
  * unknown — scoped generation never silently emits the wrong set.
@@ -5867,8 +5903,7 @@ function canonicalServiceKey(name) {
5867
5903
  }
5868
5904
  function resolveScopedServices(spec, selected, mountRules) {
5869
5905
  const mounts = mountRules ?? {};
5870
- const postMountName = (name) => mounts[name] ?? name;
5871
- const validPostMount = new Set(spec.services.map((s) => postMountName(s.name)));
5906
+ const validPostMount = new Set(spec.services.map((s) => resolveMountTarget(s.name, mounts)));
5872
5907
  const selectedSet = new Set(selected);
5873
5908
  const unknown = [...selectedSet].filter((s) => !validPostMount.has(s));
5874
5909
  if (unknown.length > 0) {