@workos/oagen 0.24.3 → 0.24.5

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.
@@ -1541,7 +1541,7 @@ function detectPagination(response, queryParams, dataPath) {
1541
1541
  }
1542
1542
  //#endregion
1543
1543
  //#region src/parser/responses.ts
1544
- function classifyAndExtractResponse(schema, contextName) {
1544
+ function classifyAndExtractResponse(schema, contextName, componentSchemas) {
1545
1545
  if (schema.$ref) return {
1546
1546
  response: schemaToTypeRef(schema, contextName),
1547
1547
  inlineModels: [],
@@ -1550,7 +1550,7 @@ function classifyAndExtractResponse(schema, contextName) {
1550
1550
  const envelope = detectListEnvelope(schema);
1551
1551
  if (envelope.isEnvelope) return extractListResponse(schema, contextName, envelope.dataPath);
1552
1552
  if (isSingleResourceWrapper(schema)) return extractWrappedResource(schema, contextName);
1553
- return extractDirectResource(schema, contextName);
1553
+ return extractDirectResource(schema, contextName, componentSchemas);
1554
1554
  }
1555
1555
  const KNOWN_DATA_PATHS = new Set([
1556
1556
  "data",
@@ -1727,7 +1727,7 @@ function extractWrappedResource(schema, contextName) {
1727
1727
  isPaginated: false
1728
1728
  };
1729
1729
  }
1730
- function extractDirectResource(schema, contextName) {
1730
+ function extractDirectResource(schema, contextName, componentSchemas) {
1731
1731
  const inlineModels = [];
1732
1732
  if (schema.properties && (schema.type === "object" || !schema.type)) {
1733
1733
  const modelName = deriveModelName(schema, contextName);
@@ -1744,17 +1744,43 @@ function extractDirectResource(schema, contextName) {
1744
1744
  if (schema.allOf) {
1745
1745
  const mergedProperties = {};
1746
1746
  const mergedRequired = [];
1747
- for (const sub of schema.allOf) {
1748
- if (sub.properties) Object.assign(mergedProperties, sub.properties);
1749
- if (sub.required) mergedRequired.push(...sub.required);
1750
- }
1747
+ const unresolvedRefs = [];
1748
+ const seenRefs = /* @__PURE__ */ new Set();
1749
+ let mergedRefFields = false;
1750
+ const mergeSubSchemas = (subs) => {
1751
+ for (const sub of subs) {
1752
+ let resolved = sub;
1753
+ if (sub.$ref) {
1754
+ if (seenRefs.has(sub.$ref)) continue;
1755
+ seenRefs.add(sub.$ref);
1756
+ const segments = sub.$ref.split("/");
1757
+ const refName = segments[segments.length - 1];
1758
+ const refSchema = refName ? componentSchemas?.[refName] : void 0;
1759
+ if (!refSchema) {
1760
+ unresolvedRefs.push(sub.$ref);
1761
+ continue;
1762
+ }
1763
+ resolved = refSchema;
1764
+ mergedRefFields = true;
1765
+ }
1766
+ if (resolved.allOf) mergeSubSchemas(resolved.allOf);
1767
+ if (resolved.properties) Object.assign(mergedProperties, resolved.properties);
1768
+ if (resolved.required) mergedRequired.push(...resolved.required);
1769
+ }
1770
+ };
1771
+ mergeSubSchemas(schema.allOf);
1772
+ if (unresolvedRefs.length === 1 && !mergedRefFields) return {
1773
+ response: schemaToTypeRef({ $ref: unresolvedRefs[0] }, contextName),
1774
+ inlineModels,
1775
+ isPaginated: false
1776
+ };
1751
1777
  if (Object.keys(mergedProperties).length > 0) {
1752
1778
  const merged = {
1753
1779
  type: "object",
1754
1780
  properties: mergedProperties,
1755
1781
  required: mergedRequired
1756
1782
  };
1757
- const modelName = deriveModelName(merged, contextName);
1783
+ const modelName = mergedRefFields ? toPascalCase(contextName) : deriveModelName(merged, contextName);
1758
1784
  inlineModels.push(...extractInlineModel(modelName, merged));
1759
1785
  return {
1760
1786
  response: {
@@ -2157,7 +2183,7 @@ function buildOperation(method, path, op, pathLevelParams, operationIdTransform,
2157
2183
  const cookieParams = extractParams(allParams, "cookie", opContext, componentSchemas);
2158
2184
  const reqBodyModels = [];
2159
2185
  const { body: requestBody, encoding: requestBodyEncoding } = extractRequestBody(op.requestBody, op, reqBodyModels);
2160
- const { response, successResponses, errors, inlineModels, isPaginated, dataPath: responseDataPath, itemType: responseItemType } = extractResponses(op.responses, op, path, method);
2186
+ const { response, successResponses, errors, inlineModels, isPaginated, dataPath: responseDataPath, itemType: responseItemType } = extractResponses(op.responses, op, path, method, componentSchemas);
2161
2187
  inlineModels.push(...reqBodyModels);
2162
2188
  const paginationFromParams = detectPagination(response, queryParams, responseDataPath);
2163
2189
  let pagination;
@@ -2450,7 +2476,7 @@ function deriveResponseName(op, path, method) {
2450
2476
  if (op?.operationId) return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + "Response");
2451
2477
  return toPascalCase(path.split("/").filter(Boolean)[0] ?? "Unknown") + toPascalCase(method) + "Response";
2452
2478
  }
2453
- function extractResponses(responses, op, path, method) {
2479
+ function extractResponses(responses, op, path, method, componentSchemas) {
2454
2480
  const errors = [];
2455
2481
  let response = {
2456
2482
  kind: "primitive",
@@ -2477,7 +2503,7 @@ function extractResponses(responses, op, path, method) {
2477
2503
  const jsonContent = resp.content?.["application/json"];
2478
2504
  if (jsonContent?.schema) {
2479
2505
  const contextName = deriveResponseName(op, path ?? "/", method ?? "get");
2480
- const result = classifyAndExtractResponse(jsonContent.schema, contextName);
2506
+ const result = classifyAndExtractResponse(jsonContent.schema, contextName, componentSchemas);
2481
2507
  extractedType = result.response;
2482
2508
  inlineModels = result.inlineModels;
2483
2509
  isPaginated = result.isPaginated;