@workos/oagen 0.17.3 → 0.18.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.
@@ -886,13 +886,16 @@ function deriveInlineVariantMapping(variants, discriminatorProperty, contextName
886
886
  return mapping;
887
887
  }
888
888
  function extractEnum(name, schema) {
889
+ const values = (schema.enum ?? []).map((v) => ({
890
+ name: toUpperSnakeCase(String(v)),
891
+ value: typeof v === "number" ? v : String(v),
892
+ description: void 0
893
+ }));
894
+ const rawDefault = schema.default;
889
895
  return {
890
896
  name,
891
- values: (schema.enum ?? []).map((v) => ({
892
- name: toUpperSnakeCase(String(v)),
893
- value: typeof v === "number" ? v : String(v),
894
- description: void 0
895
- }))
897
+ values,
898
+ default: rawDefault !== void 0 && values.some((v) => v.value === rawDefault) ? rawDefault : void 0
896
899
  };
897
900
  }
898
901
  function extractModel(name, schema, schemas) {
@@ -1757,7 +1760,7 @@ const HTTP_METHODS = [
1757
1760
  "options",
1758
1761
  "trace"
1759
1762
  ];
1760
- function extractOperations(paths, operationIdTransform) {
1763
+ function extractOperations(paths, operationIdTransform, componentSchemas) {
1761
1764
  if (!paths) return {
1762
1765
  services: [],
1763
1766
  inlineModels: []
@@ -1770,7 +1773,7 @@ function extractOperations(paths, operationIdTransform) {
1770
1773
  const op = pathItem[method];
1771
1774
  if (!op) continue;
1772
1775
  const serviceName = inferServiceName(path, op.tags?.[0]);
1773
- const { operation, inlineModels: opModels } = buildOperation(method, path, op, pathLevelParams, operationIdTransform, serviceName);
1776
+ const { operation, inlineModels: opModels } = buildOperation(method, path, op, pathLevelParams, operationIdTransform, serviceName, componentSchemas);
1774
1777
  inlineModels.push(...opModels);
1775
1778
  const ops = serviceMap.get(serviceName) ?? [];
1776
1779
  ops.push(operation);
@@ -2013,14 +2016,14 @@ function extractBodyParameterGroups(op, operationContext) {
2013
2016
  }
2014
2017
  return groups.length > 0 ? groups : void 0;
2015
2018
  }
2016
- function buildOperation(method, path, op, pathLevelParams, operationIdTransform, serviceName) {
2019
+ function buildOperation(method, path, op, pathLevelParams, operationIdTransform, serviceName, componentSchemas) {
2017
2020
  const allParams = [...pathLevelParams, ...op.parameters ?? []];
2018
2021
  const hasIdempotencyHeader = allParams.some((p) => p.in === "header" && p.name.toLowerCase() === "idempotency-key");
2019
2022
  const opContext = serviceName;
2020
- const pathParams = extractParams(allParams, "path", opContext);
2021
- const queryParams = extractParams(allParams, "query", opContext);
2022
- const headerParams = extractParams(allParams, "header", opContext).filter((p) => p.name.toLowerCase() !== "idempotency-key");
2023
- const cookieParams = extractParams(allParams, "cookie", opContext);
2023
+ const pathParams = extractParams(allParams, "path", opContext, componentSchemas);
2024
+ const queryParams = extractParams(allParams, "query", opContext, componentSchemas);
2025
+ const headerParams = extractParams(allParams, "header", opContext, componentSchemas).filter((p) => p.name.toLowerCase() !== "idempotency-key");
2026
+ const cookieParams = extractParams(allParams, "cookie", opContext, componentSchemas);
2024
2027
  const reqBodyModels = [];
2025
2028
  const { body: requestBody, encoding: requestBodyEncoding } = extractRequestBody(op.requestBody, op, reqBodyModels);
2026
2029
  const { response, successResponses, errors, inlineModels, isPaginated, dataPath: responseDataPath, itemType: responseItemType } = extractResponses(op.responses, op, path, method);
@@ -2092,21 +2095,42 @@ function buildDescription(summary, description) {
2092
2095
  if (summary && description && summary !== description) return `${summary}\n\n${description}`;
2093
2096
  return description ?? summary;
2094
2097
  }
2095
- function extractParams(params, location, operationContext) {
2096
- return params.filter((p) => p.in === location).map((p) => ({
2097
- name: p.name,
2098
- type: p.schema ? schemaToTypeRef(p.schema, p.name, operationContext ? toPascalCase(operationContext) : void 0) : {
2099
- kind: "primitive",
2100
- type: "string"
2101
- },
2102
- required: p.required ?? false,
2103
- description: p.description,
2104
- deprecated: p.deprecated || p.schema?.deprecated || void 0,
2105
- default: p.schema?.default,
2106
- example: p.example ?? p.schema?.example,
2107
- style: p.style,
2108
- explode: p.explode
2109
- }));
2098
+ function extractParams(params, location, operationContext, componentSchemas) {
2099
+ return params.filter((p) => p.in === location).map((p) => {
2100
+ const refTarget = resolveParamSchemaRef(p.schema, componentSchemas);
2101
+ return {
2102
+ name: p.name,
2103
+ type: p.schema ? schemaToTypeRef(p.schema, p.name, operationContext ? toPascalCase(operationContext) : void 0) : {
2104
+ kind: "primitive",
2105
+ type: "string"
2106
+ },
2107
+ required: p.required ?? false,
2108
+ description: p.description,
2109
+ deprecated: p.deprecated || p.schema?.deprecated || refTarget?.deprecated || void 0,
2110
+ default: p.schema?.default ?? refTarget?.default,
2111
+ example: p.example ?? p.schema?.example ?? refTarget?.example,
2112
+ style: p.style,
2113
+ explode: p.explode
2114
+ };
2115
+ });
2116
+ }
2117
+ /**
2118
+ * If a parameter's schema is a `$ref` to `#/components/schemas/X`, return the
2119
+ * referenced component schema. Used to surface schema-level metadata (default,
2120
+ * example, deprecated) that wouldn't otherwise be visible at the param level.
2121
+ *
2122
+ * Refs are not pre-resolved by the bundler (`dereference: false` in refs.ts),
2123
+ * so without this, a param like `schema: { $ref: '.../PaginationOrder' }`
2124
+ * silently loses the target's `default: desc` and the SDK stops emitting the
2125
+ * spec-mandated default value in generated method signatures.
2126
+ */
2127
+ function resolveParamSchemaRef(schema, componentSchemas) {
2128
+ if (!schema || !componentSchemas) return void 0;
2129
+ const ref = schema.$ref;
2130
+ if (!ref) return void 0;
2131
+ const match = /^#\/components\/schemas\/(.+)$/.exec(ref);
2132
+ if (!match) return void 0;
2133
+ return componentSchemas[match[1]];
2110
2134
  }
2111
2135
  function extractRequestBody(body, op, inlineModels) {
2112
2136
  if (!body?.content) return {};
@@ -2460,7 +2484,7 @@ async function parseSpec(specPath, options) {
2460
2484
  const version = spec.openapi ?? "";
2461
2485
  if (!version.startsWith("3.")) throw new SpecParseError(`Unsupported OpenAPI version: ${version}. oagen requires OpenAPI 3.x`, `Update the spec to OpenAPI 3.0 or 3.1. If you are using Swagger 2.x, convert it first with \`npx swagger2openapi ${specPath}\`.`);
2462
2486
  const { models, enums } = extractSchemas(spec.components?.schemas, { schemaNameTransform: options?.schemaNameTransform });
2463
- const { services, inlineModels } = extractOperations(spec.paths, options?.operationIdTransform);
2487
+ const { services, inlineModels } = extractOperations(spec.paths, options?.operationIdTransform, spec.components?.schemas);
2464
2488
  clearSchemaNameTransform();
2465
2489
  const finalModels = collapseJsonSuffixModels(mergeFieldInlineModels(mergeInlineResponseModels(models, inlineModels), extractInlineModelsFromSchemas(spec.components?.schemas)), services);
2466
2490
  collectInlineEnumsFromModels(finalModels, enums);