@workos/oagen 0.17.0 → 0.17.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.
package/dist/smoke.mjs CHANGED
@@ -483,6 +483,14 @@ function buildInlineModel(name, schema) {
483
483
  * to apply the same name transform to $ref model/enum references.
484
484
  */
485
485
  let activeSchemaNameTransform = null;
486
+ /**
487
+ * Module-level set of resolved schema names whose components/schemas entry is
488
+ * an enum (i.e. has `enum:`). Populated by extractSchemas() so schemaToTypeRef()
489
+ * can classify a `$ref` to a top-level enum schema as `kind: 'enum'` instead of
490
+ * `kind: 'model'`. Without this, every `$ref` was naively returned as a model
491
+ * ref, even when the target was a shared enum like `PaginationOrder`.
492
+ */
493
+ let activeEnumSchemaNames = /* @__PURE__ */ new Set();
486
494
  /** Apply cleanSchemaName + the active transform (if any) to a raw schema name. */
487
495
  function resolveSchemaName(rawName) {
488
496
  let name = cleanSchemaName(toPascalCase(rawName));
@@ -508,6 +516,8 @@ function extractSchemas(schemas, options) {
508
516
  for (const [, originals] of transformedToOriginals) if (originals.length > 1) for (const n of originals) unsafeToTransform.add(n);
509
517
  activeSchemaNameTransform = (name) => unsafeToTransform.has(name) ? name : transform(name);
510
518
  } else activeSchemaNameTransform = null;
519
+ activeEnumSchemaNames = /* @__PURE__ */ new Set();
520
+ for (const [name, schema] of Object.entries(schemas)) if (schema.enum) activeEnumSchemaNames.add(resolveSchemaName(name));
511
521
  const modelsByCleanName = /* @__PURE__ */ new Map();
512
522
  for (const [name, schema] of Object.entries(schemas)) {
513
523
  const pascalName = resolveSchemaName(name);
@@ -542,6 +552,7 @@ function extractSchemas(schemas, options) {
542
552
  /** Clear the module-level schemaNameTransform. Called by parseSpec() after all extraction phases. */
543
553
  function clearSchemaNameTransform() {
544
554
  activeSchemaNameTransform = null;
555
+ activeEnumSchemaNames = /* @__PURE__ */ new Set();
545
556
  }
546
557
  /**
547
558
  * Walk a single TypeRef and extract inline enum refs as top-level enum definitions.
@@ -1106,9 +1117,14 @@ function schemaToTypeRef(schema, contextName, parentModelName) {
1106
1117
  if (schema.$ref) {
1107
1118
  const segments = schema.$ref.split("/");
1108
1119
  const rawName = segments[segments.length - 1];
1120
+ const resolved = resolveSchemaName(rawName);
1121
+ if (activeEnumSchemaNames.has(resolved)) return {
1122
+ kind: "enum",
1123
+ name: resolved
1124
+ };
1109
1125
  return {
1110
1126
  kind: "model",
1111
- name: resolveSchemaName(rawName)
1127
+ name: resolved
1112
1128
  };
1113
1129
  }
1114
1130
  if (Array.isArray(schema.type)) {
@@ -1796,10 +1812,23 @@ function inferServiceName(path, tag) {
1796
1812
  if (first.startsWith("{")) return "Default";
1797
1813
  return toPascalCase(first);
1798
1814
  }
1815
+ /**
1816
+ * Strip overload indices (e.g. NestJS emits `Foo_bar[0]` when a controller
1817
+ * method handles multiple routes) from an operationId so derived names never
1818
+ * leak the bracketed digit. Without this, `authenticate[0]` would surface as
1819
+ * `authenticate0` in method names and `Authenticate0Request` in body model
1820
+ * names. Brackets at the end (or with trailing whitespace) are common in
1821
+ * NestJS-style backends; this regex is intentionally narrow to avoid eating
1822
+ * legitimate digits like `oauth2`.
1823
+ */
1824
+ function normalizeOperationIdForNaming(operationId) {
1825
+ return operationId.replace(/\[\d+\]\s*$/, "");
1826
+ }
1799
1827
  function inferOperationName(method, path, operationId, operationIdTransform) {
1800
1828
  if (operationId) {
1801
- if (operationIdTransform) return operationIdTransform(operationId);
1802
- return toCamelCase(operationId);
1829
+ const normalized = normalizeOperationIdForNaming(operationId);
1830
+ if (operationIdTransform) return operationIdTransform(normalized);
1831
+ return toCamelCase(normalized);
1803
1832
  }
1804
1833
  const verb = inferVerb(method, path);
1805
1834
  const resource = inferResourceFromPath(path);
@@ -2117,7 +2146,7 @@ function extractRequestBody(body, op, inlineModels) {
2117
2146
  };
2118
2147
  return {};
2119
2148
  }
2120
- const contextName = cleanSchemaName(op?.operationId ? toPascalCase(op.operationId) + "Request" : "RequestBody");
2149
+ const contextName = cleanSchemaName(op?.operationId ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Request" : "RequestBody");
2121
2150
  if (schema.properties && (schema.type === "object" || !schema.type)) {
2122
2151
  const requiredSet = new Set(schema.required ?? []);
2123
2152
  const fields = [];
@@ -2198,7 +2227,7 @@ function deriveOneOfVariantName(variant, baseName, existingModels) {
2198
2227
  return name;
2199
2228
  }
2200
2229
  function deriveResponseName(op, path, method) {
2201
- if (op?.operationId) return cleanSchemaName(toPascalCase(op.operationId) + "Response");
2230
+ if (op?.operationId) return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Response");
2202
2231
  return toPascalCase(path.split("/").filter(Boolean)[0] ?? "Unknown") + toPascalCase(method) + "Response";
2203
2232
  }
2204
2233
  function extractResponses(responses, op, path, method) {