@workos/oagen-emitters 0.12.5 → 0.14.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,6 +1,14 @@
1
1
  import type { ApiSpec, EmitterContext, GeneratedFile, Service, Model, Enum } from '@workos/oagen';
2
2
  import { assignModelsToServices } from '@workos/oagen';
3
- import { servicePropertyName, resolveClassName, className, fileName, buildMountDirMap } from './naming.js';
3
+ import {
4
+ servicePropertyName,
5
+ resolveClassName,
6
+ className,
7
+ fileName,
8
+ buildMountDirMap,
9
+ buildExportedClassNameSet,
10
+ resolveServiceTarget,
11
+ } from './naming.js';
4
12
  import { classifyUnassignedModel } from './models.js';
5
13
  import { getMountTarget } from '../shared/resolved-ops.js';
6
14
  import { isListWrapperModel, isListMetadataModel } from '../shared/model-utils.js';
@@ -89,8 +97,12 @@ function buildInflectionMap(spec: ApiSpec, ctx: EmitterContext): Map<string, str
89
97
 
90
98
  inflections.set('workos', 'WorkOS');
91
99
 
100
+ const exportedClasses = buildExportedClassNameSet(ctx);
92
101
  for (const service of buildTopLevelServices(spec, ctx)) {
93
- const target = getMountTarget(service, ctx) || resolveClassName(service, ctx);
102
+ const target = resolveServiceTarget(
103
+ getMountTarget(service, ctx) || resolveClassName(service, ctx),
104
+ exportedClasses,
105
+ );
94
106
  const cls = className(target);
95
107
  const file = fileName(target);
96
108
  if (rubyCamelize(file) !== cls) inflections.set(file, cls);
@@ -203,10 +215,11 @@ function generateClientClass(spec: ApiSpec, ctx: EmitterContext): GeneratedFile
203
215
  lines.push(' class Client < BaseClient');
204
216
 
205
217
  const topLevelServices = buildTopLevelServices(spec, ctx);
218
+ const exportedClasses = buildExportedClassNameSet(ctx);
206
219
  for (const service of topLevelServices) {
207
- const target = getMountTarget(service, ctx) || resolveClassName(service, ctx);
208
- const cls = className(target);
209
- const prop = servicePropertyName(target);
220
+ const rawTarget = getMountTarget(service, ctx) || resolveClassName(service, ctx);
221
+ const cls = className(resolveServiceTarget(rawTarget, exportedClasses));
222
+ const prop = servicePropertyName(rawTarget);
210
223
  lines.push('');
211
224
  lines.push(` def ${prop}`);
212
225
  lines.push(` @${prop} ||= WorkOS::${cls}.new(self)`);
package/src/ruby/index.ts CHANGED
@@ -15,6 +15,7 @@ import { generateClient } from './client.js';
15
15
  import { generateTests } from './tests.js';
16
16
  import { buildOperationsMap } from './manifest.js';
17
17
  import { generateRbiFiles } from './rbi.js';
18
+ import { enrichModelsFromSpec, getSyntheticEnums } from '../shared/model-utils.js';
18
19
 
19
20
  /** Ensure every generated file's content ends with a trailing newline. */
20
21
  function ensureTrailingNewlines(files: GeneratedFile[]): GeneratedFile[] {
@@ -26,16 +27,40 @@ function ensureTrailingNewlines(files: GeneratedFile[]): GeneratedFile[] {
26
27
  return files;
27
28
  }
28
29
 
30
+ /**
31
+ * Flatten oneOf / allOf+oneOf variant fields onto each base model and pick
32
+ * up the synthetic models / enums `enrichModelsFromSpec` produces for inline
33
+ * variant shapes. Ruby emits flat hash-backed models, not sum types, so a
34
+ * discriminated base whose IR fields were stripped (the new EventSchema-
35
+ * style behaviour after the parser learned to walk allOf-wrapped variants)
36
+ * has its original fields restored — otherwise `ConnectApplication`-style
37
+ * bases would silently lose every variant field they had previously.
38
+ */
39
+ function enrichModelsForRuby(models: Model[]): Model[] {
40
+ const enriched = enrichModelsFromSpec(models);
41
+ const originalByName = new Map(models.map((m) => [m.name, m]));
42
+ return enriched.map((m) => {
43
+ if ((m as { discriminator?: unknown }).discriminator && m.fields.length === 0) {
44
+ const original = originalByName.get(m.name);
45
+ if (original && original.fields.length > 0) {
46
+ return { ...m, fields: original.fields };
47
+ }
48
+ }
49
+ return m;
50
+ });
51
+ }
52
+
29
53
  export const rubyEmitter: Emitter = {
30
54
  language: 'ruby',
31
55
 
32
56
  generateModels(models: Model[], ctx: EmitterContext): GeneratedFile[] {
33
- const modelFiles = generateModels(models, ctx);
57
+ const modelFiles = generateModels(enrichModelsForRuby(models), ctx);
34
58
  return ensureTrailingNewlines(modelFiles);
35
59
  },
36
60
 
37
61
  generateEnums(enums: Enum[], ctx: EmitterContext): GeneratedFile[] {
38
- return ensureTrailingNewlines(generateEnums(enums, ctx));
62
+ const syntheticEnums = getSyntheticEnums();
63
+ return ensureTrailingNewlines(generateEnums([...enums, ...syntheticEnums], ctx));
39
64
  },
40
65
 
41
66
  generateResources(services: Service[], ctx: EmitterContext): GeneratedFile[] {
@@ -7,9 +7,14 @@ import { servicePropertyName } from './naming.js';
7
7
  * Uses each resolved operation's actual mountOn (not the service default) so
8
8
  * operations remounted via operationHints land on the correct service prop.
9
9
  * Split operations emit one entry per wrapper (keyed by wrapper name + variant).
10
+ *
11
+ * The accessor (`service` field) uses the raw mountOn — accessor names stay
12
+ * unsuffixed even when the underlying service class gets a `Service` suffix
13
+ * on collision.
10
14
  */
11
15
  export function buildOperationsMap(spec: ApiSpec, ctx: EmitterContext): OperationsMap {
12
16
  void spec;
17
+ void ctx;
13
18
  const manifest: OperationsMap = {};
14
19
 
15
20
  for (const r of ctx.resolvedOperations ?? []) {
@@ -2,6 +2,10 @@ import type { Operation, Service, EmitterContext } from '@workos/oagen';
2
2
  import { toPascalCase, toSnakeCase } from '@workos/oagen';
3
3
  import { buildResolvedLookup, lookupMethodName, getMountTarget } from '../shared/resolved-ops.js';
4
4
  import { stripUrnPrefix, applyAcronymFixes } from '../shared/naming-utils.js';
5
+ import {
6
+ buildExportedClassNameSet as buildExportedClassNameSetShared,
7
+ resolveServiceTarget as resolveServiceTargetShared,
8
+ } from '../shared/service-name-collision.js';
5
9
 
6
10
  /**
7
11
  * Ruby class names that collide with core classes. When a model name resolves
@@ -117,6 +121,32 @@ export function moduleName(name: string): string {
117
121
  return toSnakeCase(name);
118
122
  }
119
123
 
124
+ /**
125
+ * Build the set of model + enum Ruby class names that the SDK exposes under
126
+ * `WorkOS::`. Used to detect collisions with operation-client class names —
127
+ * a colliding service gets a `Service` suffix (`OrganizationMembershipService`)
128
+ * so it doesn't shadow the model class under Zeitwerk's collapsed namespace.
129
+ */
130
+ export function buildExportedClassNameSet(ctx: EmitterContext): Set<string> {
131
+ return buildExportedClassNameSetShared(ctx, className);
132
+ }
133
+
134
+ /**
135
+ * Resolve a service's mount-target identifier, appending `Service` on
136
+ * collision with an exported model/enum class name. The returned PascalCase
137
+ * value feeds `className`/`fileName` to derive matching class + file names
138
+ * (e.g. `OrganizationMembershipService` / `organization_membership_service`).
139
+ *
140
+ * Accessor names (`servicePropertyName`) intentionally use the RAW target —
141
+ * `client.organization_membership` is more readable than the suffixed form.
142
+ *
143
+ * The directory used by `loader.collapse` (the model home) likewise uses the
144
+ * raw target.
145
+ */
146
+ export function resolveServiceTarget(target: string, exportedClasses: Set<string>): string {
147
+ return resolveServiceTargetShared(target, exportedClasses, className);
148
+ }
149
+
120
150
  /**
121
151
  * PascalCase class name for a parameter-group variant. Mirrors the Python
122
152
  * convention: group "password" + variant "plaintext" → `PasswordPlaintext`.
package/src/ruby/rbi.ts CHANGED
@@ -7,6 +7,9 @@ import {
7
7
  safeParamName,
8
8
  scopedGroupVariantClassName,
9
9
  resolveMethodName,
10
+ servicePropertyName,
11
+ buildExportedClassNameSet,
12
+ resolveServiceTarget,
10
13
  } from './naming.js';
11
14
  import {
12
15
  buildResolvedLookup,
@@ -129,9 +132,11 @@ export function generateRbiFiles(spec: ApiSpec, ctx: EmitterContext): GeneratedF
129
132
  if (isListWrapperModel(m)) listWrapperModels.set(m.name, m);
130
133
  }
131
134
  const groupOwners = buildGroupOwnerMap(ctx);
135
+ const exportedClasses = buildExportedClassNameSet(ctx);
132
136
 
133
137
  for (const [mountTarget, group] of groups) {
134
- const cls = className(mountTarget);
138
+ const resolvedTarget = resolveServiceTarget(mountTarget, exportedClasses);
139
+ const cls = className(resolvedTarget);
135
140
  const lines: string[] = [];
136
141
  lines.push('# typed: strong');
137
142
  lines.push('');
@@ -143,6 +148,9 @@ export function generateRbiFiles(spec: ApiSpec, ctx: EmitterContext): GeneratedF
143
148
  // layout in lib/workos/<service>.rb.
144
149
  const variants = collectVariantsForMountTarget(ctx, spec.models as Model[], mountTarget);
145
150
  for (const v of variants) {
151
+ // Rewrite mountTarget to the (possibly pluralized) service class so the
152
+ // RBI's `WorkOS::<Service>::<Variant>` reference matches the runtime.
153
+ v.mountTarget = resolvedTarget;
146
154
  for (const line of emitInlineVariantRbi(v)) lines.push(line);
147
155
  lines.push('');
148
156
  }
@@ -183,7 +191,8 @@ export function generateRbiFiles(spec: ApiSpec, ctx: EmitterContext): GeneratedF
183
191
  if (!owner) {
184
192
  throw new Error(`No owner mount target found for parameter group '${group.name}'`);
185
193
  }
186
- const variants = group.variants.map((v) => scopedGroupVariantClassName(owner, group.name, v.name));
194
+ const resolvedOwner = resolveServiceTarget(owner, exportedClasses);
195
+ const variants = group.variants.map((v) => scopedGroupVariantClassName(resolvedOwner, group.name, v.name));
187
196
  if (variants.length === 1) return variants[0];
188
197
  return `T.any(${variants.join(', ')})`;
189
198
  };
@@ -267,7 +276,7 @@ export function generateRbiFiles(spec: ApiSpec, ctx: EmitterContext): GeneratedF
267
276
  lines.push('end');
268
277
 
269
278
  files.push({
270
- path: `rbi/workos/${fileName(mountTarget)}.rbi`,
279
+ path: `rbi/workos/${fileName(resolvedTarget)}.rbi`,
271
280
  content: lines.join('\n'),
272
281
  integrateTarget: true,
273
282
  overwriteExisting: true,
@@ -283,11 +292,9 @@ export function generateRbiFiles(spec: ApiSpec, ctx: EmitterContext): GeneratedF
283
292
  lines.push(' class Client < BaseClient');
284
293
 
285
294
  for (const [mountTarget] of groups) {
286
- const cls = className(mountTarget);
287
- const prop = mountTarget
288
- .replace(/-/g, '_')
289
- .replace(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`)
290
- .replace(/^_/, '');
295
+ const resolvedTarget = resolveServiceTarget(mountTarget, exportedClasses);
296
+ const cls = className(resolvedTarget);
297
+ const prop = servicePropertyName(mountTarget);
291
298
  lines.push(` sig { returns(WorkOS::${cls}) }`);
292
299
  lines.push(` def ${prop}; end`);
293
300
  lines.push('');
@@ -8,6 +8,8 @@ import {
8
8
  safeParamName,
9
9
  resolveMethodName,
10
10
  scopedGroupVariantClassName,
11
+ buildExportedClassNameSet,
12
+ resolveServiceTarget,
11
13
  } from './naming.js';
12
14
  import { mapTypeRefForYard } from './type-map.js';
13
15
  import {
@@ -48,10 +50,12 @@ export function generateResources(services: Service[], ctx: EmitterContext): Gen
48
50
  // dispatcher and YARD `@param` reference resolves variant classes through
49
51
  // this map so cross-resource references stay consistent.
50
52
  const groupOwners = buildGroupOwnerMap(ctx);
53
+ const exportedClasses = buildExportedClassNameSet(ctx);
51
54
 
52
55
  for (const [mountTarget, group] of groups) {
53
- const cls = className(mountTarget);
54
- const file = fileName(mountTarget);
56
+ const resolvedTarget = resolveServiceTarget(mountTarget, exportedClasses);
57
+ const cls = className(resolvedTarget);
58
+ const file = fileName(resolvedTarget);
55
59
 
56
60
  const operations = group.operations;
57
61
  if (operations.length === 0) continue;
@@ -103,6 +107,7 @@ export function generateResources(services: Service[], ctx: EmitterContext): Gen
103
107
  listWrapperModels,
104
108
  requires,
105
109
  groupOwners,
110
+ exportedClasses,
106
111
  });
107
112
  methodBodies.push(body);
108
113
 
@@ -182,6 +187,7 @@ function emitMethod(args: {
182
187
  listWrapperModels: Map<string, Model>;
183
188
  requires: Set<string>;
184
189
  groupOwners: Map<string, string>;
190
+ exportedClasses: Set<string>;
185
191
  }): string {
186
192
  const {
187
193
  op,
@@ -195,6 +201,7 @@ function emitMethod(args: {
195
201
  listWrapperModels,
196
202
  requires,
197
203
  groupOwners,
204
+ exportedClasses,
198
205
  } = args;
199
206
  void enumNames;
200
207
 
@@ -204,7 +211,7 @@ function emitMethod(args: {
204
211
  if (!owner) {
205
212
  throw new Error(`No owner mount target found for parameter group '${group.name}'`);
206
213
  }
207
- return scopedGroupVariantClassName(owner, group.name, variantName);
214
+ return scopedGroupVariantClassName(resolveServiceTarget(owner, exportedClasses), group.name, variantName);
208
215
  };
209
216
 
210
217
  const plan = planOperation(op);
package/src/ruby/tests.ts CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  scopedGroupVariantClassName,
8
8
  servicePropertyName,
9
9
  resolveMethodName,
10
+ buildExportedClassNameSet,
11
+ resolveServiceTarget,
10
12
  } from './naming.js';
11
13
  import {
12
14
  buildResolvedLookup,
@@ -38,11 +40,13 @@ export function generateTests(spec: ApiSpec, ctx: EmitterContext): GeneratedFile
38
40
 
39
41
  const lookup = buildResolvedLookup(ctx);
40
42
  const groupOwners = buildGroupOwnerMap(ctx);
43
+ const exportedClasses = buildExportedClassNameSet(ctx);
41
44
 
42
45
  for (const [mountTarget, group] of groups) {
43
- const cls = className(mountTarget);
46
+ const resolvedTarget = resolveServiceTarget(mountTarget, exportedClasses);
47
+ const cls = className(resolvedTarget);
44
48
  const prop = servicePropertyName(mountTarget);
45
- const file = fileName(mountTarget);
49
+ const file = fileName(resolvedTarget);
46
50
 
47
51
  const lines: string[] = [];
48
52
  lines.push(`require 'test_helper'`);
@@ -85,7 +89,7 @@ export function generateTests(spec: ApiSpec, ctx: EmitterContext): GeneratedFile
85
89
 
86
90
  const resolved = lookupResolved(op, lookup);
87
91
  const hiddenParams = buildHiddenParams(resolved);
88
- const callArgs = buildCallArgsStub(op, modelByName, hiddenParams, groupOwners, models);
92
+ const callArgs = buildCallArgsStub(op, modelByName, hiddenParams, groupOwners, models, exportedClasses);
89
93
  const bodyMatcher = buildBodyMatcher(op, modelByName, hiddenParams, models);
90
94
 
91
95
  // Collect method info for the parameterized 401 test (T20).
@@ -118,7 +122,15 @@ export function generateTests(spec: ApiSpec, ctx: EmitterContext): GeneratedFile
118
122
  for (let vi = 1; vi < group.variants.length; vi++) {
119
123
  const variant = group.variants[vi];
120
124
  const overrides = new Map<string, number>([[group.name, vi]]);
121
- const variantCallArgs = buildCallArgsStub(op, modelByName, hiddenParams, groupOwners, models, overrides);
125
+ const variantCallArgs = buildCallArgsStub(
126
+ op,
127
+ modelByName,
128
+ hiddenParams,
129
+ groupOwners,
130
+ models,
131
+ exportedClasses,
132
+ overrides,
133
+ );
122
134
  const variantBodyMatcher = buildBodyMatcher(op, modelByName, hiddenParams, models, overrides);
123
135
  const suffix = `with_${fieldName(group.name)}_${fieldName(variant.name)}`;
124
136
  lines.push('');
@@ -338,6 +350,7 @@ function buildCallArgsStub(
338
350
  hiddenParams: Set<string>,
339
351
  groupOwners: Map<string, string>,
340
352
  models: Model[],
353
+ exportedClasses: Set<string>,
341
354
  variantOverrides: Map<string, number> = new Map(),
342
355
  ): string {
343
356
  const parts: string[] = [];
@@ -406,7 +419,11 @@ function buildCallArgsStub(
406
419
  if (!owner) {
407
420
  throw new Error(`No owner mount target found for parameter group '${group.name}'`);
408
421
  }
409
- const variantClass = scopedGroupVariantClassName(owner, group.name, variant.name);
422
+ const variantClass = scopedGroupVariantClassName(
423
+ resolveServiceTarget(owner, exportedClasses),
424
+ group.name,
425
+ variant.name,
426
+ );
410
427
  const fieldStubs = variant.parameters
411
428
  .map((p) => `${fieldName(p.name)}: ${stubValueFor(pickVariantParamType(p.type, bodyFieldTypes.get(p.name)))}`)
412
429
  .join(', ');
package/src/rust/index.ts CHANGED
@@ -16,6 +16,7 @@ import { generateClient } from './client.js';
16
16
  import { generateTests } from './tests.js';
17
17
  import { buildOperationsMap } from './manifest.js';
18
18
  import { UnionRegistry } from './type-map.js';
19
+ import { enrichModelsFromSpec, getSyntheticEnums } from '../shared/model-utils.js';
19
20
 
20
21
  /**
21
22
  * Shared per-emit registry that collects synthesised oneOf-style unions
@@ -34,16 +35,39 @@ function ensureTrailingNewlines(files: GeneratedFile[]): GeneratedFile[] {
34
35
  return files;
35
36
  }
36
37
 
38
+ /**
39
+ * Flatten oneOf / allOf+oneOf variant fields onto each base model and pull
40
+ * in synthetic models / enums for inline variant shapes. Rust emits flat
41
+ * structs (a synthesised enum-union from `UnionRegistry` exists, but the
42
+ * field-on-base pattern is what matches `ConnectApplication` today). A
43
+ * discriminated base whose IR fields the parser stripped gets its original
44
+ * fields restored to avoid losing variant data.
45
+ */
46
+ function enrichModelsForRust(models: Model[]): Model[] {
47
+ const enriched = enrichModelsFromSpec(models);
48
+ const originalByName = new Map(models.map((m) => [m.name, m]));
49
+ return enriched.map((m) => {
50
+ if ((m as { discriminator?: unknown }).discriminator && m.fields.length === 0) {
51
+ const original = originalByName.get(m.name);
52
+ if (original && original.fields.length > 0) {
53
+ return { ...m, fields: original.fields };
54
+ }
55
+ }
56
+ return m;
57
+ });
58
+ }
59
+
37
60
  export const rustEmitter: Emitter = {
38
61
  language: 'rust',
39
62
 
40
63
  generateModels(models: Model[], ctx: EmitterContext): GeneratedFile[] {
41
64
  unionRegistry.reset();
42
- return ensureTrailingNewlines(generateModels(models, ctx, unionRegistry));
65
+ return ensureTrailingNewlines(generateModels(enrichModelsForRust(models), ctx, unionRegistry));
43
66
  },
44
67
 
45
68
  generateEnums(enums: Enum[], ctx: EmitterContext): GeneratedFile[] {
46
- return ensureTrailingNewlines(generateEnums(enums, ctx));
69
+ const syntheticEnums = getSyntheticEnums();
70
+ return ensureTrailingNewlines(generateEnums([...enums, ...syntheticEnums], ctx));
47
71
  },
48
72
 
49
73
  generateResources(services: Service[], ctx: EmitterContext): GeneratedFile[] {
@@ -1,5 +1,5 @@
1
1
  import type { Model, Field, TypeRef, Enum } from '@workos/oagen';
2
- import { toSnakeCase } from '@workos/oagen';
2
+ import { toSnakeCase, toUpperSnakeCase } from '@workos/oagen';
3
3
  import { readFileSync, existsSync } from 'node:fs';
4
4
  import { resolve } from 'node:path';
5
5
  // @ts-ignore -- js-yaml has no type declarations in this project
@@ -83,7 +83,7 @@ function discoverSpecPath(): string | null {
83
83
  let _rawSpecCache: Record<string, any> | null = null;
84
84
  let _rawSpecLoaded = false;
85
85
 
86
- function loadRawSpec(): Record<string, any> | null {
86
+ export function loadRawSpec(): Record<string, any> | null {
87
87
  if (_rawSpecLoaded) return _rawSpecCache;
88
88
  _rawSpecLoaded = true;
89
89
  const specPath = discoverSpecPath();
@@ -114,7 +114,10 @@ function lookupRawSchema(name: string): Record<string, any> | null {
114
114
  */
115
115
  interface SyntheticCollector {
116
116
  models: Model[];
117
- enums: Array<{ name: string; values: Array<{ value: string; description?: string }> }>;
117
+ enums: Array<{
118
+ name: string;
119
+ values: Array<{ value: string; description?: string }>;
120
+ }>;
118
121
  /** Track names already used to avoid duplicates. */
119
122
  usedNames: Set<string>;
120
123
  }
@@ -582,10 +585,17 @@ export function enrichModelsFromSpec(models: Model[]): Model[] {
582
585
  return modified ? { ...model, fields: newFields } : model;
583
586
  });
584
587
 
585
- // Convert synthetic enum collector entries to proper Enum objects
588
+ // Convert synthetic enum collector entries to proper Enum objects. PHP's
589
+ // emitter (and others built on top of `EnumValue.name`) crash when this
590
+ // field is missing, so derive it from the value via the same upper-snake
591
+ // transform the parser uses for declared enums.
586
592
  _lastSyntheticEnums = collector.enums.map((e) => ({
587
593
  name: e.name,
588
- values: e.values.map((v) => ({ value: v.value, description: v.description })),
594
+ values: e.values.map((v) => ({
595
+ name: toUpperSnakeCase(String(v.value)),
596
+ value: v.value,
597
+ description: v.description,
598
+ })),
589
599
  })) as Enum[];
590
600
 
591
601
  // Append synthetic models, skipping those whose snake_case name collides
@@ -0,0 +1,56 @@
1
+ import type { EmitterContext, Model, Enum } from '@workos/oagen';
2
+ import { isListWrapperModel, isListMetadataModel } from './model-utils.js';
3
+
4
+ /**
5
+ * Suffix applied to an operation-client class name when it collides with an
6
+ * exported model/enum class name in the same SDK namespace. Standardized
7
+ * across emitters so colliding services look the same in every language —
8
+ * e.g. `OrganizationMembershipService` regardless of language.
9
+ *
10
+ * Languages whose operation clients already carry a unique suffix (Go's
11
+ * `…Service`, Rust's `…Api`, .NET's `…Service`) skip this helper entirely.
12
+ */
13
+ export const SERVICE_COLLISION_SUFFIX = 'Service';
14
+
15
+ /**
16
+ * Build the set of model + enum class names that the SDK exports under its
17
+ * top-level namespace. Each emitter passes its own `classNameFn` so the
18
+ * comparison happens on the language-specific class-name form (e.g. Ruby's
19
+ * `RoleList`, Python's `RoleList`).
20
+ *
21
+ * List-wrapper and list-metadata models are excluded — they aren't exposed
22
+ * as user-facing types.
23
+ */
24
+ export function buildExportedClassNameSet(ctx: EmitterContext, classNameFn: (name: string) => string): Set<string> {
25
+ const out = new Set<string>();
26
+ for (const model of ctx.spec.models as Model[]) {
27
+ if (isListWrapperModel(model) || isListMetadataModel(model)) continue;
28
+ out.add(classNameFn(model.name));
29
+ }
30
+ for (const enumDef of ctx.spec.enums as Enum[]) {
31
+ out.add(classNameFn(enumDef.name));
32
+ }
33
+ return out;
34
+ }
35
+
36
+ /**
37
+ * Resolve the PascalCase mount-target identifier for an operation client,
38
+ * appending `Service` when the un-suffixed class name would shadow an
39
+ * exported model or enum.
40
+ *
41
+ * Operates on the PascalCase target (the mount-target string the IR carries),
42
+ * so the returned value feeds cleanly into each language's `className` and
43
+ * `fileName` helpers — e.g. `OrganizationMembership` → `OrganizationMembershipService`,
44
+ * then `fileName` → `organization_membership_service` / `organization-membership-service`.
45
+ *
46
+ * The accessor on the client (`client.organization_membership`) is intentionally
47
+ * NOT suffixed — callers should keep using the raw target for `servicePropertyName`
48
+ * so the accessor reads naturally.
49
+ */
50
+ export function resolveServiceTarget(
51
+ target: string,
52
+ exportedClasses: Set<string>,
53
+ classNameFn: (name: string) => string,
54
+ ): string {
55
+ return exportedClasses.has(classNameFn(target)) ? `${target}${SERVICE_COLLISION_SUFFIX}` : target;
56
+ }