@workos/oagen 0.24.4 → 0.24.6

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.
@@ -1614,7 +1614,7 @@ function detectPagination(response, queryParams, dataPath) {
1614
1614
  }
1615
1615
  //#endregion
1616
1616
  //#region src/parser/responses.ts
1617
- function classifyAndExtractResponse(schema, contextName) {
1617
+ function classifyAndExtractResponse(schema, contextName, componentSchemas) {
1618
1618
  if (schema.$ref) return {
1619
1619
  response: schemaToTypeRef(schema, contextName),
1620
1620
  inlineModels: [],
@@ -1623,7 +1623,7 @@ function classifyAndExtractResponse(schema, contextName) {
1623
1623
  const envelope = detectListEnvelope(schema);
1624
1624
  if (envelope.isEnvelope) return extractListResponse(schema, contextName, envelope.dataPath);
1625
1625
  if (isSingleResourceWrapper(schema)) return extractWrappedResource(schema, contextName);
1626
- return extractDirectResource(schema, contextName);
1626
+ return extractDirectResource(schema, contextName, componentSchemas);
1627
1627
  }
1628
1628
  const KNOWN_DATA_PATHS = new Set([
1629
1629
  "data",
@@ -1800,7 +1800,7 @@ function extractWrappedResource(schema, contextName) {
1800
1800
  isPaginated: false
1801
1801
  };
1802
1802
  }
1803
- function extractDirectResource(schema, contextName) {
1803
+ function extractDirectResource(schema, contextName, componentSchemas) {
1804
1804
  const inlineModels = [];
1805
1805
  if (schema.properties && (schema.type === "object" || !schema.type)) {
1806
1806
  const modelName = deriveModelName(schema, contextName);
@@ -1817,17 +1817,43 @@ function extractDirectResource(schema, contextName) {
1817
1817
  if (schema.allOf) {
1818
1818
  const mergedProperties = {};
1819
1819
  const mergedRequired = [];
1820
- for (const sub of schema.allOf) {
1821
- if (sub.properties) Object.assign(mergedProperties, sub.properties);
1822
- if (sub.required) mergedRequired.push(...sub.required);
1823
- }
1820
+ const unresolvedRefs = [];
1821
+ const seenRefs = /* @__PURE__ */ new Set();
1822
+ let mergedRefFields = false;
1823
+ const mergeSubSchemas = (subs) => {
1824
+ for (const sub of subs) {
1825
+ let resolved = sub;
1826
+ if (sub.$ref) {
1827
+ if (seenRefs.has(sub.$ref)) continue;
1828
+ seenRefs.add(sub.$ref);
1829
+ const segments = sub.$ref.split("/");
1830
+ const refName = segments[segments.length - 1];
1831
+ const refSchema = refName ? componentSchemas?.[refName] : void 0;
1832
+ if (!refSchema) {
1833
+ unresolvedRefs.push(sub.$ref);
1834
+ continue;
1835
+ }
1836
+ resolved = refSchema;
1837
+ mergedRefFields = true;
1838
+ }
1839
+ if (resolved.allOf) mergeSubSchemas(resolved.allOf);
1840
+ if (resolved.properties) Object.assign(mergedProperties, resolved.properties);
1841
+ if (resolved.required) mergedRequired.push(...resolved.required);
1842
+ }
1843
+ };
1844
+ mergeSubSchemas(schema.allOf);
1845
+ if (unresolvedRefs.length === 1 && !mergedRefFields) return {
1846
+ response: schemaToTypeRef({ $ref: unresolvedRefs[0] }, contextName),
1847
+ inlineModels,
1848
+ isPaginated: false
1849
+ };
1824
1850
  if (Object.keys(mergedProperties).length > 0) {
1825
1851
  const merged = {
1826
1852
  type: "object",
1827
1853
  properties: mergedProperties,
1828
1854
  required: mergedRequired
1829
1855
  };
1830
- const modelName = deriveModelName(merged, contextName);
1856
+ const modelName = mergedRefFields ? toPascalCase(contextName) : deriveModelName(merged, contextName);
1831
1857
  inlineModels.push(...extractInlineModel(modelName, merged));
1832
1858
  return {
1833
1859
  response: {
@@ -2230,7 +2256,7 @@ function buildOperation(method, path, op, pathLevelParams, operationIdTransform,
2230
2256
  const cookieParams = extractParams(allParams, "cookie", opContext, componentSchemas);
2231
2257
  const reqBodyModels = [];
2232
2258
  const { body: requestBody, encoding: requestBodyEncoding } = extractRequestBody(op.requestBody, op, reqBodyModels);
2233
- const { response, successResponses, errors, inlineModels, isPaginated, dataPath: responseDataPath, itemType: responseItemType } = extractResponses(op.responses, op, path, method);
2259
+ const { response, successResponses, errors, inlineModels, isPaginated, dataPath: responseDataPath, itemType: responseItemType } = extractResponses(op.responses, op, path, method, componentSchemas);
2234
2260
  inlineModels.push(...reqBodyModels);
2235
2261
  const paginationFromParams = detectPagination(response, queryParams, responseDataPath);
2236
2262
  let pagination;
@@ -2523,7 +2549,7 @@ function deriveResponseName(op, path, method) {
2523
2549
  if (op?.operationId) return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Response");
2524
2550
  return toPascalCase(path.split("/").filter(Boolean)[0] ?? "Unknown") + toPascalCase(method) + "Response";
2525
2551
  }
2526
- function extractResponses(responses, op, path, method) {
2552
+ function extractResponses(responses, op, path, method, componentSchemas) {
2527
2553
  const errors = [];
2528
2554
  let response = {
2529
2555
  kind: "primitive",
@@ -2550,7 +2576,7 @@ function extractResponses(responses, op, path, method) {
2550
2576
  const jsonContent = resp.content?.["application/json"];
2551
2577
  if (jsonContent?.schema) {
2552
2578
  const contextName = deriveResponseName(op, path ?? "/", method ?? "get");
2553
- const result = classifyAndExtractResponse(jsonContent.schema, contextName);
2579
+ const result = classifyAndExtractResponse(jsonContent.schema, contextName, componentSchemas);
2554
2580
  extractedType = result.response;
2555
2581
  inlineModels = result.inlineModels;
2556
2582
  isPaginated = result.isPaginated;
@@ -6278,7 +6304,7 @@ async function readManifest(dir) {
6278
6304
  }
6279
6305
  try {
6280
6306
  const parsed = JSON.parse(raw);
6281
- if (typeof parsed.version !== "number" || typeof parsed.language !== "string" || typeof parsed.generatedAt !== "string" || !Array.isArray(parsed.files) || !parsed.files.every((p) => typeof p === "string")) return null;
6307
+ if (typeof parsed.version !== "number" || typeof parsed.language !== "string" || !Array.isArray(parsed.files) || !parsed.files.every((p) => typeof p === "string")) return null;
6282
6308
  if (parsed.version > MANIFEST_VERSION) {
6283
6309
  console.warn(`[oagen] ${MANIFEST_FILENAME} schema version ${parsed.version} is newer than supported (${MANIFEST_VERSION}); ignoring for pruning.`);
6284
6310
  return null;
@@ -6295,7 +6321,6 @@ async function writeManifest(dir, opts) {
6295
6321
  version: MANIFEST_VERSION,
6296
6322
  language: opts.language,
6297
6323
  ...opts.sdkName !== void 0 ? { sdkName: opts.sdkName } : {},
6298
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
6299
6324
  ...opts.specSha !== void 0 ? { specSha: opts.specSha } : {},
6300
6325
  ...opts.specPath !== void 0 ? { specPath: opts.specPath } : {},
6301
6326
  ...opts.emitterSha !== void 0 ? { emitterSha: opts.emitterSha } : {},
@@ -6305,16 +6330,9 @@ async function writeManifest(dir, opts) {
6305
6330
  files: [...new Set(opts.files)].sort(),
6306
6331
  ...opts.operations !== void 0 ? { operations: opts.operations } : {}
6307
6332
  };
6308
- const previous = await readManifest(dir);
6309
- if (previous && sameManifestExceptGeneratedAt(previous, manifest)) manifest.generatedAt = previous.generatedAt;
6310
6333
  await fs.mkdir(dir, { recursive: true });
6311
6334
  await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
6312
6335
  }
6313
- function sameManifestExceptGeneratedAt(a, b) {
6314
- const { generatedAt: _aGeneratedAt, ...aComparable } = a;
6315
- const { generatedAt: _bGeneratedAt, ...bComparable } = b;
6316
- return JSON.stringify(aComparable) === JSON.stringify(bComparable);
6317
- }
6318
6336
  /** Return the set of previous paths no longer present in the current emission. */
6319
6337
  function computeStalePaths(prev, currentPaths) {
6320
6338
  const current = new Set(currentPaths);