@workos/oagen 0.22.5 → 0.22.7

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 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/ir/sdk-behavior.ts","../src/parser/refs.ts","../src/parser/inline-models.ts","../src/parser/schemas.ts","../src/parser/pagination.ts","../src/parser/responses.ts","../src/parser/operations.ts","../src/parser/normalize-inline-models.ts","../src/parser/collect-inline-enums.ts","../src/parser/normalize-model-refs.ts","../src/parser/parse.ts","../src/engine/operation-plan.ts","../src/snippets/example-builder.ts","../src/snippets/runner.ts","../src/snippets/shared.ts"],"sourcesContent":["/**\n * SDK Behavior IR — language-agnostic runtime policies for generated SDKs.\n *\n * These types capture the \"what\" of SDK behavior (retry, telemetry, errors, etc.)\n * while emitters provide the \"how\" (language-specific mechanism).\n *\n * Emitters access these via `ctx.spec.sdk` — always populated, never undefined.\n */\n\n// ── Retry ──────────────────────────────────────────────────────────\n\n/** Retry policy — when and how to retry failed requests. */\nexport interface RetryPolicy {\n /** HTTP status codes that trigger a retry. */\n retryableStatusCodes: number[];\n /** Maximum number of retry attempts (0 = no retries). */\n maxRetries: number;\n /** Whether to retry on connection errors (DNS failure, TCP reset). */\n retryOnConnectionError: boolean;\n /** Whether to retry on timeout errors. */\n retryOnTimeout: boolean;\n /** Backoff strategy between retries. */\n backoff: BackoffStrategy;\n}\n\n/** Exponential backoff configuration.\n *\n * Formula: `delay = min(initialDelay * multiplier^attempt, maxDelay)`\n * With jitter: `delay += delay * jitterFactor * random(0, 1)`\n */\nexport interface BackoffStrategy {\n /** Initial delay in seconds before the first retry. */\n initialDelay: number;\n /** Multiplier applied to the delay on each subsequent retry. */\n multiplier: number;\n /** Maximum delay in seconds (cap). */\n maxDelay: number;\n /** Jitter factor (0..1). 0.5 means up to 50% random jitter added. */\n jitterFactor: number;\n}\n\n// ── Errors ─────────────────────────────────────────────────────────\n\n/** Error mapping — status codes to named exception kinds. */\nexport interface ErrorPolicy {\n /** Map from HTTP status code to a logical error kind name (e.g. 400 → 'BadRequest').\n * Emitters append language-specific suffixes (e.g. 'BadRequestException'). */\n statusCodeMap: Record<number, string>;\n /** Catch-all error kind for 5xx status codes not in the map. */\n serverErrorKind: string;\n /** Catch-all error kind for unrecognized status codes. */\n clientErrorKind: string;\n /** URL template for error documentation. Use {code} as placeholder for the API error code.\n * Example: 'https://workos.com/docs/errors/{code}' */\n errorDocUrlTemplate?: string;\n}\n\n// ── Telemetry ──────────────────────────────────────────────────────\n\n/** Telemetry — what request metrics to track and send. */\nexport interface TelemetryPolicy {\n /** Whether telemetry is enabled by default. Users can opt out via constructor param. */\n enabledByDefault: boolean;\n /** Header name for client telemetry data (previous request's ID + latency). */\n headerName: string;\n /** Response header name for the request ID. */\n requestIdHeader: string;\n}\n\n// ── Pagination ─────────────────────────────────────────────────────\n\n/** Pagination behavior defaults. */\nexport interface PaginationPolicy {\n /** Delay in milliseconds between pages during auto-pagination. 0 = no delay. */\n autoPageDelayMs: number;\n}\n\n// ── Idempotency ────────────────────────────────────────────────────\n\n/** Idempotency auto-generation rules. */\nexport interface IdempotencyPolicy {\n /** Header name for the idempotency key. */\n headerName: string;\n /** Whether to auto-generate a UUID v4 idempotency key for POST requests when retries > 0. */\n autoGenerateForPost: boolean;\n}\n\n// ── Logging ────────────────────────────────────────────────────────\n\n/** Logging contract — what to log at which level. */\nexport interface LoggingPolicy {\n /** Whether structured logging hooks are generated. */\n enabled: boolean;\n /** Log events that the generated client emits. */\n events: LogEvent[];\n}\n\n/** A discrete loggable event in the request lifecycle. */\nexport type LogEvent =\n | 'request.start'\n | 'request.success'\n | 'request.retry'\n | 'request.rate_limited'\n | 'request.error'\n | 'request.connection_error';\n\n// ── User-Agent ─────────────────────────────────────────────────────\n\n/** User-Agent construction rules. */\nexport interface UserAgentPolicy {\n /** Template for the SDK identifier string.\n * Placeholders: {name} = spec name, {lang} = emitter language, {version} = SDK version.\n * Each emitter interpolates with its own language string and casing conventions.\n * Example: '{name} {lang}/{version}' → 'WorkOS PHP/4.32.0' */\n sdkIdentifierTemplate: string;\n /** Whether to append the runtime/language version (e.g. PHP 8.2, Python 3.12). */\n includeRuntimeVersion: boolean;\n /** Whether to allow app info enrichment via setAppInfo(name, version, url). */\n allowAppInfo: boolean;\n /** AI agent environment variable detection entries. */\n aiAgentEnvVars: AiAgentEnvVar[];\n}\n\n/** Maps an environment variable to an AI agent slug for User-Agent enrichment. */\nexport interface AiAgentEnvVar {\n /** Environment variable to check (e.g. 'CLAUDE_CODE'). */\n envVar: string;\n /** Agent name to append to User-Agent (e.g. 'ClaudeCode'). */\n agentName: string;\n}\n\n// ── Request Guards ─────────────────────────────────────────────────\n\n/** Guards that validate request params before sending. */\nexport interface RequestGuardPolicy {\n /** Keys that should be in RequestOptions, not in params.\n * If detected in the body or query params, the SDK throws an error. */\n optionKeys: string[];\n}\n\n// ── Timeouts ───────────────────────────────────────────────────────\n\n/** Timeout configuration. */\nexport interface TimeoutPolicy {\n /** Default HTTP request timeout in seconds. */\n defaultTimeoutSeconds: number;\n /** Environment variable name to override the timeout (e.g. 'WORKOS_REQUEST_TIMEOUT'). */\n timeoutEnvVar?: string;\n}\n\n// ── Root ───────────────────────────────────────────────────────────\n\n/** Language-agnostic runtime policies for generated SDKs.\n * Attached to `ApiSpec.sdk` and consumed by emitters via `ctx.spec.sdk`. */\nexport interface SdkBehavior {\n retry: RetryPolicy;\n errors: ErrorPolicy;\n telemetry: TelemetryPolicy;\n pagination: PaginationPolicy;\n idempotency: IdempotencyPolicy;\n logging: LoggingPolicy;\n userAgent: UserAgentPolicy;\n requestGuard: RequestGuardPolicy;\n timeout: TimeoutPolicy;\n}\n\n// ── Defaults ───────────────────────────────────────────────────────\n\n/**\n * Canonical SDK behavior defaults. These match the PHP emitter's current\n * implementation (the most complete). Per-language overrides can be applied\n * via `mergeSdkBehavior()` in each SDK's `oagen.config.ts`.\n *\n * - Retry: exponential backoff with jitter, retries on 429/5xx\n * - Errors: standard HTTP status → exception kind mapping\n * - Telemetry: enabled by default, tracks request ID + latency\n * - Pagination: no inter-page delay (Node overrides to 350ms)\n * - Idempotency: auto-generate UUID v4 for retryable POSTs\n * - Logging: all lifecycle events enabled\n * - User-Agent: SDK identifier + runtime version + app info + AI agent detection\n * - Request guards: detect misplaced RequestOptions keys in params\n * - Timeout: 60s default (Python overrides to 30s)\n */\nexport function defaultSdkBehavior(): SdkBehavior {\n return {\n retry: {\n retryableStatusCodes: [429, 500, 502, 503, 504],\n maxRetries: 3,\n retryOnConnectionError: true,\n retryOnTimeout: true,\n backoff: {\n initialDelay: 1.0,\n multiplier: 2.0,\n maxDelay: 30.0,\n jitterFactor: 0.5,\n },\n },\n errors: {\n statusCodeMap: {\n 400: 'BadRequest',\n 401: 'Authentication',\n 403: 'Authorization',\n 404: 'NotFound',\n 409: 'Conflict',\n 422: 'UnprocessableEntity',\n 429: 'RateLimitExceeded',\n },\n serverErrorKind: 'Server',\n clientErrorKind: 'Api',\n errorDocUrlTemplate: 'https://workos.com/docs/errors/{code}',\n },\n telemetry: {\n enabledByDefault: true,\n headerName: 'X-WorkOS-Client-Telemetry',\n requestIdHeader: 'X-Request-ID',\n },\n pagination: {\n autoPageDelayMs: 0,\n },\n idempotency: {\n headerName: 'Idempotency-Key',\n autoGenerateForPost: true,\n },\n logging: {\n enabled: true,\n events: [\n 'request.start',\n 'request.success',\n 'request.retry',\n 'request.rate_limited',\n 'request.error',\n 'request.connection_error',\n ],\n },\n userAgent: {\n sdkIdentifierTemplate: '{name} {lang}/{version}',\n includeRuntimeVersion: true,\n allowAppInfo: true,\n aiAgentEnvVars: [\n { envVar: 'CLAUDE_CODE', agentName: 'ClaudeCode' },\n { envVar: 'CURSOR_AGENT', agentName: 'Cursor' },\n { envVar: 'CLINE_ACTIVE', agentName: 'Cline' },\n { envVar: 'WINDSURF_ACTIVE', agentName: 'Windsurf' },\n { envVar: 'COPILOT_AGENT', agentName: 'Copilot' },\n ],\n },\n requestGuard: {\n optionKeys: [\n 'api_key',\n 'apiKey',\n 'idempotency_key',\n 'idempotencyKey',\n 'extra_headers',\n 'extraHeaders',\n 'max_retries',\n 'maxRetries',\n 'base_url',\n 'baseUrl',\n ],\n },\n timeout: {\n defaultTimeoutSeconds: 60,\n },\n };\n}\n\n// ── Merge ──────────────────────────────────────────────────────────\n\n/** Recursive partial type for deep overrides. */\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends (infer U)[]\n ? U[] // Arrays replace entirely (don't concat)\n : T[K] extends object\n ? DeepPartial<T[K]>\n : T[K];\n};\n\n/**\n * Deep-merge partial overrides into the canonical defaults.\n * Arrays replace entirely (so `retryableStatusCodes: [429]` replaces the full list,\n * rather than appending). Object properties are merged recursively.\n */\nexport function mergeSdkBehavior(overrides: DeepPartial<SdkBehavior>): SdkBehavior {\n return deepMerge(\n defaultSdkBehavior() as unknown as Record<string, unknown>,\n overrides as unknown as Record<string, unknown>,\n ) as unknown as SdkBehavior;\n}\n\n/**\n * Self-contained deep merge (no external imports — ir/ is layer 0).\n * Arrays and primitives from `source` replace those in `target`.\n * Objects are merged recursively.\n */\nfunction deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = { ...target };\n for (const key of Object.keys(source)) {\n const sourceVal = source[key];\n const targetVal = target[key];\n if (sourceVal === undefined) continue;\n if (\n sourceVal !== null &&\n typeof sourceVal === 'object' &&\n !Array.isArray(sourceVal) &&\n targetVal !== null &&\n typeof targetVal === 'object' &&\n !Array.isArray(targetVal)\n ) {\n result[key] = deepMerge(targetVal as Record<string, unknown>, sourceVal as Record<string, unknown>);\n } else {\n result[key] = sourceVal;\n }\n }\n return result;\n}\n","import { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { makeDocumentFromString, bundleDocument, createConfig, BaseResolver, Oas3_1Types } from '@redocly/openapi-core';\nimport { SpecParseError } from '../errors.js';\n\nexport interface BundledSpec {\n parsed: Record<string, unknown>;\n specPath: string;\n}\n\nexport async function loadAndBundleSpec(specPath: string): Promise<BundledSpec> {\n const absolutePath = resolve(specPath);\n const content = await readFile(absolutePath, 'utf-8');\n const document = makeDocumentFromString(content, pathToFileURL(absolutePath).href);\n\n const config = await createConfig({});\n const resolver = new BaseResolver();\n\n const result = await bundleDocument({\n document,\n config,\n types: Oas3_1Types,\n externalRefResolver: resolver,\n dereference: false,\n });\n\n if (result.problems.some((p) => p.severity === 'error')) {\n const errors = result.problems\n .filter((p) => p.severity === 'error')\n .map((p) => p.message)\n .join('\\n');\n throw new SpecParseError(\n `Failed to parse spec: ${errors}`,\n `Check the OpenAPI spec at \"${absolutePath}\" for syntax errors. Run a linter such as \\`npx @redocly/cli lint ${specPath}\\` to identify issues.`,\n );\n }\n\n return {\n parsed: result.bundle.parsed as Record<string, unknown>,\n specPath: absolutePath,\n };\n}\n","import type { Model, Field } from '../ir/types.js';\nimport { toPascalCase, stripListItemMarkers, singularize } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { buildFieldFromSchema, resolveSchemaName } from './schemas.js';\n\n/**\n * Qualify an inline model name with the parent schema name.\n * If `parentName` is provided and the field name doesn't already start with\n * the parent, the result is `${parentName}${PascalField}` with the trailing\n * word singularized (e.g., Connection + Domains → ConnectionDomain).\n */\nexport function qualifyInlineModelName(baseName: string, parentName?: string): string {\n if (!parentName) return baseName;\n // Strip ListItem/ByExternalId markers from parent name so inline model names\n // are clean and match the names produced by qualifyNestedName() in responses.ts.\n // e.g., ConnectionListItem + Domains → Connection + Domain = ConnectionDomain\n const cleanParent = stripListItemMarkers(parentName);\n if (baseName.startsWith(cleanParent)) return baseName;\n // Singularize the trailing PascalCase word of the combined name.\n // Split baseName into leading words + trailing word, singularize trailing.\n const trailingMatch = baseName.match(/^(.*?)([A-Z][a-z]*)$/);\n if (trailingMatch) {\n const [, prefix, trailingWord] = trailingMatch;\n const singular = singularize(trailingWord);\n return `${cleanParent}${prefix}${singular}`;\n }\n return `${cleanParent}${baseName}`;\n}\n\n/**\n * Walk all component schemas and extract inline Model definitions for fields\n * that are objects with properties (or arrays of such objects).\n * These correspond to the ModelRef entries created by schemaToTypeRef.\n */\nexport function extractInlineModelsFromSchemas(schemas: Record<string, SchemaObject> | undefined): Model[] {\n if (!schemas) return [];\n\n const inlineModels: Model[] = [];\n\n for (const [schemaName, schema] of Object.entries(schemas)) {\n const parentName = resolveSchemaName(schemaName);\n extractInlineModelsFromProperties(schema, inlineModels, parentName);\n }\n\n return inlineModels;\n}\n\nfunction extractInlineModelsFromProperties(schema: SchemaObject, results: Model[], parentName?: string): void {\n const properties = schema.properties ?? {};\n const allOfSchemas = schema.allOf ?? [];\n\n for (const sub of allOfSchemas) {\n if (sub.properties) {\n extractInlineModelsFromProperties(sub, results, parentName);\n }\n }\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n // Direct inline object with properties (with or without explicit type: 'object')\n if (fieldSchema.properties && (fieldSchema.type === 'object' || !fieldSchema.type)) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n results.push(buildInlineModel(modelName, fieldSchema));\n extractInlineModelsFromProperties(fieldSchema, results, modelName);\n }\n\n // Array of inline objects\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n const items = fieldSchema.items;\n if (items.properties && (items.type === 'object' || !items.type)) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n results.push(buildInlineModel(modelName, items));\n extractInlineModelsFromProperties(items, results, modelName);\n }\n }\n\n // oneOf containing objects — extract every inline object variant as a\n // model so each gets its own typed class. Variant 0 keeps the bare\n // qualified inline name (e.g. `ApiKeyCreatedDataOwner`); subsequent\n // variants are prefixed by their const-discriminator value via\n // `nameOneOfVariant` (e.g. `UserApiKeyCreatedDataOwner`). When the\n // oneOf doesn't have a const-discriminator (single object variant + null\n // for nullable, or single object variant only), only variant 0 is\n // extracted and the bare name pattern preserves backward compat.\n if (fieldSchema.oneOf) {\n const inlineObjectVariants = fieldSchema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n if (inlineObjectVariants.length > 0) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n const existingNames = new Set(results.map((r) => r.name));\n const namingDiscProp = deriveOneOfNamingDiscriminator(inlineObjectVariants);\n const emittedNames: string[] = [];\n for (const variant of inlineObjectVariants) {\n const variantName = nameOneOfVariant(variant, modelName, emittedNames, namingDiscProp);\n emittedNames.push(variantName);\n if (!existingNames.has(variantName)) {\n existingNames.add(variantName);\n results.push(buildInlineModel(variantName, variant));\n extractInlineModelsFromProperties(variant, results, variantName);\n }\n }\n }\n }\n }\n}\n\n/** Find a single string-const-valued property shared by every variant whose\n * values are all distinct — the implicit discriminator. Returns null when no\n * such property exists. Mirrors `deriveConstNamingDiscriminator` in schemas.ts. */\nfunction deriveOneOfNamingDiscriminator(variants: SchemaObject[]): string | null {\n if (variants.length < 2) return null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n const values = variants.map((v) => readConstString(v.properties?.[propName]));\n if (values.some((v) => v === null)) continue;\n if (new Set(values).size !== values.length) continue;\n return propName;\n }\n return null;\n}\n\nfunction readConstString(prop: SchemaObject | undefined): string | null {\n if (!prop) return null;\n if (typeof prop.const === 'string') return prop.const;\n if (Array.isArray(prop.enum) && prop.enum.length === 1 && typeof prop.enum[0] === 'string') {\n return prop.enum[0];\n }\n return null;\n}\n\n/** Produce a per-variant model name. Variant 0 keeps the bare parent name;\n * later variants are prefixed by the const-derived label. Mirrors\n * `nameVariantModel` in schemas.ts. Falls back to a numeric suffix when no\n * discriminator is available, the const value PascalCases to nothing, or\n * the derived candidate collides with the parent or an already-emitted name. */\nfunction nameOneOfVariant(\n variant: SchemaObject,\n parentName: string,\n alreadyEmitted: string[],\n discriminatorProperty: string | null,\n): string {\n if (alreadyEmitted.length === 0) return parentName;\n if (discriminatorProperty) {\n const constValue = readConstString(variant.properties?.[discriminatorProperty]);\n if (constValue) {\n const prefix = toPascalCase(constValue);\n if (prefix) {\n const candidate = parentName.startsWith(prefix) ? parentName : `${prefix}${parentName}`;\n const collision = candidate === parentName || alreadyEmitted.includes(candidate);\n if (!collision) return candidate;\n }\n }\n }\n return `${parentName}${alreadyEmitted.length + 1}`;\n}\n\nfunction buildInlineModel(name: string, schema: SchemaObject): Model {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties ?? {})) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n }\n\n return { name, description: schema.description, fields };\n}\n","import type { Model, Enum, EnumValue, Field, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\nimport {\n toPascalCase,\n toUpperSnakeCase,\n cleanSchemaName,\n singularize,\n stripListItemMarkers,\n splitWords,\n} from '../utils/naming.js';\n\n/**\n * Module-level transform set during extractSchemas(). Used by schemaToTypeRef()\n * to apply the same name transform to $ref model/enum references.\n */\nlet activeSchemaNameTransform: ((name: string) => string) | null = null;\n\n/**\n * Module-level set of resolved schema names whose components/schemas entry is\n * an enum (i.e. has `enum:`). Populated by extractSchemas() so schemaToTypeRef()\n * can classify a `$ref` to a top-level enum schema as `kind: 'enum'` instead of\n * `kind: 'model'`. Without this, every `$ref` was naively returned as a model\n * ref, even when the target was a shared enum like `PaginationOrder`.\n */\nlet activeEnumSchemaNames: Set<string> = new Set();\n\n/** Apply cleanSchemaName + the active transform (if any) to a raw schema name. */\nexport function resolveSchemaName(rawName: string): string {\n let name = cleanSchemaName(toPascalCase(rawName));\n if (activeSchemaNameTransform) name = activeSchemaNameTransform(name);\n return name;\n}\n\nexport interface SchemaExtractionOptions {\n schemaNameTransform?: (name: string) => string;\n}\n\nexport interface SchemaObject {\n type?: string | string[];\n format?: string;\n description?: string;\n properties?: Record<string, SchemaObject | undefined>;\n required?: string[];\n items?: SchemaObject;\n enum?: (string | number)[];\n allOf?: SchemaObject[];\n oneOf?: SchemaObject[];\n anyOf?: SchemaObject[];\n discriminator?: { propertyName: string; mapping?: Record<string, string> };\n readOnly?: boolean;\n writeOnly?: boolean;\n nullable?: boolean;\n $ref?: string;\n additionalProperties?: boolean | SchemaObject;\n const?: unknown;\n patternProperties?: Record<string, SchemaObject>;\n deprecated?: boolean;\n default?: unknown;\n example?: unknown;\n [key: string]: unknown;\n}\n\nexport interface ExtractedSchemas {\n models: Model[];\n enums: Enum[];\n}\n\nexport function extractSchemas(\n schemas: Record<string, SchemaObject> | undefined,\n options?: SchemaExtractionOptions,\n): ExtractedSchemas {\n const enums: Enum[] = [];\n\n if (!schemas) return { models: [], enums };\n\n // Build collision-safe transform if provided\n if (options?.schemaNameTransform) {\n const transform = options.schemaNameTransform;\n const rawNames = Object.keys(schemas);\n const cleanedNames = rawNames.map((n) => cleanSchemaName(toPascalCase(n)));\n const transformedToOriginals = new Map<string, string[]>();\n for (const cleaned of cleanedNames) {\n const transformed = transform(cleaned);\n if (!transformedToOriginals.has(transformed)) transformedToOriginals.set(transformed, []);\n transformedToOriginals.get(transformed)!.push(cleaned);\n }\n const unsafeToTransform = new Set<string>();\n for (const [, originals] of transformedToOriginals) {\n if (originals.length > 1) {\n for (const n of originals) unsafeToTransform.add(n);\n }\n }\n activeSchemaNameTransform = (name: string) => (unsafeToTransform.has(name) ? name : transform(name));\n } else {\n activeSchemaNameTransform = null;\n }\n\n // Pre-compute the set of resolved names whose component schema is an enum so\n // schemaToTypeRef() can classify `$ref` targets correctly. Built in a separate\n // pass because the per-schema loop mutates models/enums and we want this map\n // available before any TypeRef is resolved (operations + nested fields both\n // call schemaToTypeRef during extraction).\n activeEnumSchemaNames = new Set();\n for (const [name, schema] of Object.entries(schemas)) {\n if (schema.enum) activeEnumSchemaNames.add(resolveSchemaName(name));\n }\n\n const modelsByCleanName = new Map<string, Model>();\n\n for (const [name, schema] of Object.entries(schemas)) {\n const pascalName = resolveSchemaName(name);\n\n if (schema.enum) {\n enums.push(extractEnum(pascalName, schema));\n } else {\n const model = extractModel(pascalName, schema, schemas);\n const existing = modelsByCleanName.get(pascalName);\n if (existing) {\n // Keep the model with more fields when names collide after cleaning\n if (model.fields.length > existing.fields.length) {\n modelsByCleanName.set(pascalName, model);\n }\n } else {\n modelsByCleanName.set(pascalName, model);\n }\n\n for (const inlineModel of extractDiscriminatedAllOfVariantModels(schema, pascalName)) {\n const existingInline = modelsByCleanName.get(inlineModel.name);\n if (existingInline) {\n if (inlineModel.fields.length > existingInline.fields.length) {\n modelsByCleanName.set(inlineModel.name, inlineModel);\n }\n } else {\n modelsByCleanName.set(inlineModel.name, inlineModel);\n }\n }\n }\n }\n\n const models = [...modelsByCleanName.values()];\n\n // Collect inline models from nested object/oneOf properties\n // that schemaToTypeRef created model refs for but weren't extracted\n const modelNames = new Set(models.map((m) => m.name));\n const inlineQueue: Model[] = [...models];\n while (inlineQueue.length > 0) {\n const model = inlineQueue.pop()!;\n for (const field of model.fields) {\n collectNestedInlineModels(field.type, field.name, model.name, schemas ?? {}, models, modelNames, inlineQueue);\n }\n }\n\n // Collect inline enums from model fields\n for (const model of models) {\n collectInlineEnums(model.fields, enums);\n }\n\n // NOTE: activeSchemaNameTransform is intentionally NOT cleared here.\n // extractOperations() calls schemaToTypeRef() for $ref resolution and\n // needs the same transform active. parseSpec() calls clearSchemaNameTransform()\n // after all extraction is complete.\n return { models, enums };\n}\n\n/** Clear the module-level schemaNameTransform. Called by parseSpec() after all extraction phases. */\nexport function clearSchemaNameTransform(): void {\n activeSchemaNameTransform = null;\n activeEnumSchemaNames = new Set();\n}\n\n/**\n * Walk a single TypeRef and extract inline enum refs as top-level enum definitions.\n * Shared by both schemas.ts (field-level) and parse.ts (model-level) collection passes.\n */\nexport function collectInlineEnumFromRef(ref: TypeRef, enums: Enum[], seen: Set<string>): void {\n walkTypeRef(ref, {\n enum: (r) => {\n if (r.values && !seen.has(r.name)) {\n seen.add(r.name);\n enums.push({\n name: r.name,\n values: r.values.map((v) => ({\n name: toUpperSnakeCase(String(v)),\n value: v,\n description: undefined,\n })),\n });\n }\n },\n });\n}\n\n/**\n * Walk model fields and extract inline enum refs as top-level enum definitions.\n * This ensures type alias files are generated for inline enums.\n */\nfunction collectInlineEnums(fields: Field[], enums: Enum[]): void {\n const seen = new Set(enums.map((e) => e.name));\n for (const field of fields) {\n collectInlineEnumFromRef(field.type, enums, seen);\n }\n}\n\n/**\n * Walk a TypeRef tree and extract inline models for any model refs that point\n * to schemas with inline object properties (not in components/schemas).\n * This handles nested objects like `totp: { oneOf: [{ type: object, properties: {...} }] }`\n * that schemaToTypeRef turns into model refs but aren't extracted from components.\n */\nfunction collectNestedInlineModels(\n ref: TypeRef,\n fieldName: string,\n parentModelName: string,\n schemas: Record<string, SchemaObject>,\n models: Model[],\n modelNames: Set<string>,\n queue: Model[],\n): void {\n walkTypeRef(ref, {\n model: (modelRef) => {\n if (modelNames.has(modelRef.name)) return; // already extracted\n // Check if this model name corresponds to a component schema\n // by checking all possible original names that would map to this PascalCase name\n const isComponent = Object.keys(schemas).some((k) => resolveSchemaName(k) === modelRef.name);\n if (isComponent) return; // will be extracted from components\n\n // This is a reference to a nested inline model that wasn't extracted.\n // Look up the field schema in the parent model's component schema to extract it.\n const parentSchema = findSchemaByName(parentModelName, schemas);\n if (!parentSchema) return;\n\n const fieldSchema = findNestedFieldSchema(fieldName, parentSchema, schemas);\n if (!fieldSchema) return;\n\n // Extract inline models from the field schema\n const extracted = extractNestedSchema(modelRef.name, fieldSchema);\n for (const m of extracted) {\n if (!modelNames.has(m.name)) {\n models.push(m);\n modelNames.add(m.name);\n queue.push(m); // re-scan for deeper nesting\n }\n }\n },\n });\n}\n\n/** Find a component schema by PascalCase name. */\nfunction findSchemaByName(pascalName: string, schemas: Record<string, SchemaObject>): SchemaObject | null {\n for (const [k, v] of Object.entries(schemas)) {\n if (resolveSchemaName(k) === pascalName) return v;\n }\n return null;\n}\n\n/** Walk into a schema to find a field's sub-schema, resolving allOf and oneOf/anyOf. */\nfunction findNestedFieldSchema(\n fieldName: string,\n parentSchema: SchemaObject,\n schemas: Record<string, SchemaObject>,\n): SchemaObject | null {\n if (parentSchema.properties?.[fieldName]) {\n return parentSchema.properties[fieldName]!;\n }\n if (parentSchema.allOf) {\n for (const sub of parentSchema.allOf) {\n let resolved = sub;\n if (sub.$ref) {\n const segments = sub.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) resolved = schemas[refName];\n }\n if (resolved.properties?.[fieldName]) {\n return resolved.properties[fieldName]!;\n }\n }\n }\n // Also check inside oneOf/anyOf variants (pure oneOf schemas flatten variant\n // properties into the model, so the field may live inside a variant).\n for (const variant of [...(parentSchema.oneOf ?? []), ...(parentSchema.anyOf ?? [])]) {\n let resolved = variant;\n if (variant.$ref) {\n const segments = variant.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) resolved = schemas[refName];\n }\n if (resolved.properties?.[fieldName]) {\n return resolved.properties[fieldName]!;\n }\n }\n return null;\n}\n\n/** Extract a model (and nested models) from an inline field schema. */\nfunction extractNestedSchema(name: string, schema: SchemaObject): Model[] {\n // Handle oneOf: extract each object variant as its own model\n if (schema.oneOf) {\n const models: Model[] = [];\n\n // Collect the inline object variants up front. When every variant pins\n // the same property to a const value, we can derive meaningful names\n // from the const (e.g. `UserApiKeyOwner` instead of `ApiKeyOwner2`)\n // — much friendlier for SDK consumers than numeric suffixes.\n const inlineObjectVariants: SchemaObject[] = schema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n const constNamingDiscriminator = deriveConstNamingDiscriminator(inlineObjectVariants);\n\n for (const variant of schema.oneOf) {\n if (variant.$ref) continue;\n if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const requiredSet = new Set(variant.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(variant.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n const variantName = nameVariantModel(variant, name, models, constNamingDiscriminator);\n models.push({ name: variantName, description: variant.description, fields });\n }\n }\n return models;\n }\n\n // Handle direct object\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(schema.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n return [{ name, description: schema.description, fields }];\n }\n\n // Handle array with inline items\n if (schema.type === 'array' && schema.items?.properties) {\n const requiredSet = new Set(schema.items.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(schema.items.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n return [{ name, description: schema.items.description, fields }];\n }\n\n return [];\n}\n\n/**\n * Derive a meaningful name for a oneOf object variant past the first,\n * falling back to the numeric-suffix scheme (`Foo2`, `Foo3`) when no\n * better signal is available. The \"better signal\" is a const-valued\n * discriminator property that distinguishes one variant from the others.\n *\n * For a schema like `ApiKey.owner` whose oneOf has two variants — one\n * with `type: { const: \"organization\" }` and one with `type: { const:\n * \"user\" }` — this returns `ApiKeyOwner` for the first variant (the\n * baseline name that the union TypeRef will reference, so consumer-\n * visible typed fields stay backward-compatible) and `UserApiKeyOwner`\n * for the second instead of `ApiKeyOwner2`. SDK consumers reading the\n * generated types can tell the variants apart at a glance.\n *\n * The first variant always keeps the bare parent name because\n * `schemaToTypeRef` builds union variants whose model refs collapse to\n * `qualifyInlineModelName(field, parent)` — so the first model name\n * must match for the union's degenerate-collapse to land on a valid\n * type. Renaming variant 0 would orphan it.\n *\n * Falls back to numeric suffix when:\n * - The variant has no discriminator property (no shared const\n * property across all object variants), OR\n * - The const value PascalCases to an empty/whitespace name, OR\n * - The derived name collides with the parent name or an already-\n * emitted variant name (numeric keeps uniqueness).\n */\nfunction nameVariantModel(\n variant: SchemaObject,\n parentName: string,\n alreadyEmitted: Model[],\n discriminator: { property: string } | null,\n): string {\n // Variant 0 keeps the bare parent name so the union TypeRef's degenerate\n // collapse target exists in the model registry.\n if (alreadyEmitted.length === 0) return parentName;\n\n if (discriminator) {\n const constValue = getConstPropertyValue(variant, discriminator.property);\n if (constValue) {\n const prefix = toPascalCase(constValue);\n if (prefix) {\n const candidate = parentName.startsWith(prefix) ? parentName : `${prefix}${parentName}`;\n const collision = candidate === parentName || alreadyEmitted.some((m) => m.name === candidate);\n if (!collision) return candidate;\n }\n }\n }\n return `${parentName}${alreadyEmitted.length + 1}`;\n}\n\n/**\n * Returns a discriminator descriptor when every inline object variant in a\n * oneOf has a string-const value on the same property — the signature of a\n * discriminated union without an explicit `discriminator:` keyword. Used by\n * `nameVariantModel` to derive variant names from the const values.\n *\n * Distinct from `detectConstPropertyDiscriminator` (which requires every\n * variant to carry a `$ref` or `title` so a name mapping can be built):\n * this pass operates on inline anonymous variants, where naming is exactly\n * what we're trying to derive.\n */\nfunction deriveConstNamingDiscriminator(variants: SchemaObject[]): { property: string } | null {\n if (variants.length < 2) return null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n const values = variants.map((v) => getConstPropertyValue(v, propName));\n if (values.some((v) => v === null)) continue;\n if (new Set(values).size !== values.length) continue; // collisions = no signal\n return { property: propName };\n }\n return null;\n}\n\n/** Build a single Field from a schema property entry. Shared across all extraction sites. */\nexport function buildFieldFromSchema(\n fieldName: string,\n fieldSchema: SchemaObject,\n contextName: string,\n requiredSet: Set<string>,\n): Field {\n return {\n name: fieldName,\n type: schemaToTypeRef(fieldSchema, fieldName, contextName),\n required: requiredSet.has(fieldName),\n description: fieldSchema.description,\n readOnly: fieldSchema.readOnly || undefined,\n writeOnly: fieldSchema.writeOnly || undefined,\n deprecated: fieldSchema.deprecated || undefined,\n default: fieldSchema.default,\n example: fieldSchema.example,\n };\n}\n\n/**\n * If every non-null oneOf/anyOf variant is a string-valued const, return the\n * list of those const values so the union can collapse into a single enum.\n * Returns null when any variant isn't a pure string-const (model ref,\n * number const, nullable, etc.).\n */\nfunction collectLiteralStringConsts(variants: SchemaObject[]): string[] | null {\n if (variants.length === 0) return null;\n const values: string[] = [];\n for (const v of variants) {\n // A single-element enum is semantically identical to const.\n if (typeof v.const === 'string') {\n values.push(v.const);\n continue;\n }\n if (Array.isArray(v.enum) && v.enum.length === 1 && typeof v.enum[0] === 'string') {\n values.push(v.enum[0]);\n continue;\n }\n return null;\n }\n return values;\n}\n\n/** Build an EnumRef the same way the regular enum path does for naming. */\nfunction buildSyntheticEnumRef(\n values: string[],\n contextName: string | undefined,\n parentModelName: string | undefined,\n): TypeRef {\n const baseName = toPascalCase(contextName ?? 'UnknownEnum');\n const cleanParent = parentModelName ? stripListItemMarkers(parentModelName) : undefined;\n const qualifiedName = cleanParent && !baseName.startsWith(cleanParent) ? `${cleanParent}${baseName}` : baseName;\n // Run the same `schemaNameTransform` we apply to component-schema names so\n // a project-level rename map (e.g. `RadarAction` → `RadarListAction` in\n // `oagen.config.ts`) catches inline parameter enums too.\n const finalName = activeSchemaNameTransform ? activeSchemaNameTransform(qualifiedName) : qualifiedName;\n return { kind: 'enum', name: finalName, values };\n}\n\n/**\n * Detect an implicit discriminator on an oneOf where every variant is an\n * object schema that pins the same property to a const value. Returns\n * { property, mapping } so the IR can represent the union as discriminated\n * without needing an explicit `discriminator:` key in the spec.\n *\n * Both shapes are supported:\n * { properties: { event: { const: \"x\" } }, required: [\"event\"] }\n * { properties: { event: { type: \"string\", enum: [\"x\"] } } }\n *\n * Returns null when any variant doesn't fit the pattern or when variants\n * disagree on which property carries the discriminator.\n */\nfunction detectConstPropertyDiscriminator(\n variants: SchemaObject[],\n): { property: string; mapping: Record<string, string> } | null {\n if (variants.length < 2) return null;\n\n // Find properties whose const value is present on every variant.\n let candidateProperty: string | null = null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n if (variants.every((v) => getConstPropertyValue(v, propName) !== null)) {\n candidateProperty = propName;\n break;\n }\n }\n\n if (!candidateProperty) return null;\n\n const mapping: Record<string, string> = {};\n for (const v of variants) {\n const value = getConstPropertyValue(v, candidateProperty);\n if (value === null) return null;\n // Require a $ref or title so we have a concrete model name to map to.\n const variantName = resolveVariantModelName(v);\n if (!variantName) return null;\n mapping[value] = variantName;\n }\n\n return { property: candidateProperty, mapping };\n}\n\nfunction getConstPropertyValue(schema: SchemaObject, property: string): string | null {\n const prop = schema.properties?.[property];\n if (!prop) return null;\n if (typeof prop.const === 'string') return prop.const;\n if (Array.isArray(prop.enum) && prop.enum.length === 1 && typeof prop.enum[0] === 'string') {\n return prop.enum[0];\n }\n return null;\n}\n\nfunction resolveVariantModelName(schema: SchemaObject): string | null {\n if (schema.$ref) {\n return resolveSchemaName(schema.$ref.replace(/^#\\/components\\/schemas\\//, ''));\n }\n const title = typeof schema['title'] === 'string' ? (schema['title'] as string) : null;\n if (title) return resolveSchemaName(title);\n return null;\n}\n\n/** Look up the discriminator's mapped variant name for an inline object\n * variant by reading its const-valued discriminator property. Returns null\n * when the variant doesn't pin the property to a string const, or when\n * the value isn't in the mapping. */\nfunction mapVariantToDiscriminatorEntry(\n variant: SchemaObject,\n discriminator: { property: string; mapping: Record<string, string> },\n): string | null {\n const value = getConstPropertyValue(variant, discriminator.property);\n if (value === null) return null;\n return discriminator.mapping[value] ?? null;\n}\n\n/**\n * Derive a discriminator value → variant model name mapping for an inline-\n * variant `oneOf` whose explicit `discriminator:` has no `mapping:` clause.\n *\n * Each variant model name is reproduced via `nameVariantModel` so it matches\n * what `extractNestedSchema` registered when it walked the same `oneOf` to\n * pull variants out as named models. Variant 0 keeps the bare parent name\n * (e.g. `ApiKeyOwner`); subsequent variants get a const-derived prefix\n * (e.g. `UserApiKeyOwner` for the `type: const: user` variant).\n *\n * The \"parent name\" used here mirrors the one `collectNestedInlineModels`\n * passes to `extractNestedSchema`: it's the qualified inline model name\n * built from `contextName` (the field name) plus `parentModelName` (the\n * containing model). Returns null when any non-object variant is present\n * or when a variant lacks a const value on the discriminator property.\n */\nfunction deriveInlineVariantMapping(\n variants: SchemaObject[],\n discriminatorProperty: string,\n contextName: string | undefined,\n parentModelName: string | undefined,\n): Record<string, string> | null {\n if (variants.length === 0 || !contextName) return null;\n const inlineObjectVariants = variants.filter((v) => !v.$ref && v.properties && (v.type === 'object' || !v.type));\n if (inlineObjectVariants.length !== variants.length) return null;\n\n const baseInlineName = qualifyInlineModelName(toPascalCase(contextName), parentModelName);\n const namingDiscriminator = { property: discriminatorProperty };\n const mapping: Record<string, string> = {};\n const emittedSoFar: Model[] = [];\n for (const variant of inlineObjectVariants) {\n const constValue = getConstPropertyValue(variant, discriminatorProperty);\n if (constValue === null) return null;\n const variantName = nameVariantModel(variant, baseInlineName, emittedSoFar, namingDiscriminator);\n mapping[constValue] = variantName;\n emittedSoFar.push({ name: variantName, fields: [] });\n }\n return mapping;\n}\n\nfunction extractEnum(name: string, schema: SchemaObject): Enum {\n const values: EnumValue[] = (schema.enum ?? []).map((v) => ({\n name: toUpperSnakeCase(String(v)),\n value: typeof v === 'number' ? v : String(v),\n description: undefined,\n }));\n\n const rawDefault = schema.default;\n const def =\n rawDefault !== undefined && values.some((v) => v.value === rawDefault)\n ? (rawDefault as string | number)\n : undefined;\n\n return { name, values, default: def };\n}\nfunction extractModel(name: string, schema: SchemaObject, schemas?: Record<string, SchemaObject>): Model {\n if (schema.allOf) {\n return extractAllOfModel(name, schema, schemas);\n }\n\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties ?? {})) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n }\n\n // Pure oneOf/anyOf schemas (no allOf, no properties): merge variant fields\n // as optional. This handles schemas like UpdateOrganizationMembership which\n // is a oneOf with mutually exclusive field groups (role_slug vs role_slugs).\n if (fields.length === 0 && (schema.oneOf || schema.anyOf)) {\n const variants = schema.oneOf ?? schema.anyOf ?? [];\n const emptyRequired = new Set<string>();\n const seenFieldNames = new Set<string>();\n for (const variant of variants) {\n if (!variant.properties) continue;\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema || seenFieldNames.has(fieldName)) continue;\n seenFieldNames.add(fieldName);\n fields.push(buildFieldFromSchema(fieldName, fieldSchema as SchemaObject, name, emptyRequired));\n }\n }\n }\n\n // When additionalProperties is an object schema alongside properties,\n // surface it as a catch-all map field so emitters can generate Map<string, T>.\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object' && schema.properties) {\n const apKeys = Object.keys(schema.additionalProperties);\n if (apKeys.length > 0) {\n const valueType = schemaToTypeRef(schema.additionalProperties as SchemaObject, 'additionalProperties', name);\n fields.push({\n name: 'additionalProperties',\n type: { kind: 'map', valueType },\n required: false,\n description: 'Additional properties not captured by named fields',\n });\n }\n }\n\n return { name, description: schema.description, fields };\n}\n\nfunction extractAllOfModel(name: string, schema: SchemaObject, schemas?: Record<string, SchemaObject>): Model {\n const fields: Field[] = [];\n const requiredSet = new Set<string>();\n let resultDiscriminator: { property: string; mapping: Record<string, string> } | undefined;\n\n for (const subSchema of schema.allOf ?? []) {\n // Resolve $ref sub-schemas by looking up the referenced component schema\n let resolved = subSchema;\n if (subSchema.$ref && schemas) {\n const segments = subSchema.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) {\n resolved = schemas[refName];\n }\n }\n\n // If the resolved schema is itself an allOf, recursively extract its fields\n if (resolved.allOf) {\n const nested = extractAllOfModel(name, resolved, schemas);\n for (const f of nested.fields) {\n fields.push({ ...f, required: false }); // will be re-set below\n if (f.required) requiredSet.add(f.name);\n }\n } else if (resolved.oneOf || resolved.anyOf) {\n const variants = resolved.oneOf ?? resolved.anyOf ?? [];\n // Detect discriminated union: every variant pins the same property to a\n // distinct const value (e.g. EventSchema where each variant has event: const).\n // When detected, store the discriminator instead of flattening variant fields —\n // the base allOf schema already captures the common fields.\n const discriminatorInfo = detectAllOfVariantDiscriminator(variants, name);\n if (discriminatorInfo) {\n resultDiscriminator = discriminatorInfo;\n } else {\n // Flatten oneOf/anyOf variant fields into the parent model as optional\n // fields. This handles the common allOf + oneOf pattern where the spec\n // uses mutually exclusive variant groups (e.g. password vs password_hash).\n const emptyRequired = new Set<string>();\n const seenFieldNames = new Set(fields.map((f) => f.name));\n for (const variant of variants) {\n if (!variant.properties) continue;\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema || seenFieldNames.has(fieldName)) continue;\n seenFieldNames.add(fieldName);\n fields.push(buildFieldFromSchema(fieldName, fieldSchema as SchemaObject, name, emptyRequired));\n }\n }\n // Do NOT add variant-level required to the requiredSet — these fields\n // are optional at the parent level because they come from mutually\n // exclusive branches.\n }\n } else {\n if (resolved.required) {\n for (const r of resolved.required) requiredSet.add(r);\n }\n if (resolved.properties) {\n // Use an empty requiredSet — required flags are set in the final pass below\n const emptyRequired = new Set<string>();\n for (const [fieldName, fieldSchema] of Object.entries(resolved.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, emptyRequired));\n }\n }\n }\n }\n\n // Also collect required from the outer schema\n if (schema.required) {\n for (const r of schema.required) requiredSet.add(r);\n }\n\n // Set required flags\n for (const f of fields) {\n f.required = requiredSet.has(f.name);\n }\n\n return {\n name,\n description: schema.description,\n fields,\n ...(resultDiscriminator ? { discriminator: resultDiscriminator } : {}),\n };\n}\n\n/**\n * Walk through `allOf` wrappers to collect the effective top-level properties\n * of a schema. Stops at `oneOf` / `anyOf` boundaries — those are different\n * variant axes, not part of the same flat object.\n *\n * Used by `detectAllOfVariantDiscriminator` and `deriveDiscriminatedVariantName`\n * so a oneOf variant of the form `{ allOf: [{ properties: { … } }, { oneOf: […] }] }`\n * still surfaces its top-level `properties` (in particular its discriminator\n * `const`) instead of being treated as having none.\n */\nfunction getEffectiveProperties(schema: SchemaObject): Record<string, SchemaObject> {\n const props: Record<string, SchemaObject> = {};\n const visit = (s: SchemaObject): void => {\n if (s.properties) {\n for (const [k, v] of Object.entries(s.properties)) {\n if (!(k in props) && v) props[k] = v;\n }\n }\n if (s.allOf) {\n for (const sub of s.allOf) visit(sub);\n }\n // Do NOT walk into oneOf / anyOf — those are alternatives, not\n // simultaneously-present properties.\n };\n visit(schema);\n return props;\n}\n\nfunction getEffectiveConstPropertyValue(schema: SchemaObject, property: string): string | null {\n const direct = getConstPropertyValue(schema, property);\n if (direct !== null) return direct;\n const effective = getEffectiveProperties(schema)[property];\n if (!effective) return null;\n if (typeof effective.const === 'string') return effective.const;\n if (Array.isArray(effective.enum) && effective.enum.length === 1 && typeof effective.enum[0] === 'string') {\n return effective.enum[0];\n }\n return null;\n}\n\n/**\n * Detect an implicit discriminator on an allOf+oneOf where every variant is an\n * object that pins the same property to a distinct const value. Unlike\n * detectConstPropertyDiscriminator (which requires $ref or title for variant\n * model names), this version derives model names from the const value itself\n * using deriveDiscriminatedVariantName — matching how extractDiscriminatedAllOfVariantModels\n * names those models.\n *\n * Walks through allOf wrappers on each variant so a oneOf branch like\n * { allOf: [{ properties: { type: { const: 'oauth' } } }, { oneOf: […] }] }\n * still surfaces `type` as a candidate discriminator.\n *\n * Returns null when no discriminator can be reliably detected.\n */\nfunction detectAllOfVariantDiscriminator(\n variants: SchemaObject[],\n fallbackName: string,\n): { property: string; mapping: Record<string, string> } | null {\n if (variants.length < 2) return null;\n\n // Find a property whose const value is present on every variant\n // (looking through allOf wrappers on each variant).\n const firstProps = getEffectiveProperties(variants[0] ?? {});\n let candidateProperty: string | null = null;\n for (const propName of Object.keys(firstProps)) {\n if (variants.every((v) => getEffectiveConstPropertyValue(v, propName) !== null)) {\n candidateProperty = propName;\n break;\n }\n }\n if (!candidateProperty) return null;\n\n const mapping: Record<string, string> = {};\n const seenModelNames = new Set<string>();\n for (const v of variants) {\n const value = getEffectiveConstPropertyValue(v, candidateProperty);\n if (value === null) return null;\n const modelName = deriveDiscriminatedVariantName(v, fallbackName);\n // If two variants map to the same model name, the discriminator is ambiguous\n if (seenModelNames.has(modelName)) return null;\n seenModelNames.add(modelName);\n mapping[value] = modelName;\n }\n\n return { property: candidateProperty, mapping };\n}\n\nfunction extractDiscriminatedAllOfVariantModels(schema: SchemaObject, fallbackName: string): Model[] {\n const models: Model[] = [];\n const seenNames = new Set<string>();\n\n // Collect base-object properties + required from the allOf wrapper so each\n // variant can be emitted as a complete, self-contained type. Schemas like\n // `EventSchema` repeat the base fields inside every variant in the spec\n // (so this merge is a no-op there), but `ConnectApplication`'s OAuth /\n // M2M variants don't — without this, dispatcher consumers would get a\n // variant that's missing the shared `id` / `name` / `object` etc.\n const baseProperties: Record<string, SchemaObject> = {};\n const baseRequired = new Set<string>();\n for (const subSchema of schema.allOf ?? []) {\n if (subSchema.oneOf) continue; // the variant axis, handled below\n const flat = subSchema.allOf ? flattenVariantForExtraction(subSchema) : subSchema;\n if (flat.properties) {\n for (const [k, v] of Object.entries(flat.properties)) {\n if (!(k in baseProperties) && v) baseProperties[k] = v;\n }\n }\n if (flat.required) for (const r of flat.required) baseRequired.add(r);\n }\n\n for (const subSchema of schema.allOf ?? []) {\n for (const variant of subSchema.oneOf ?? []) {\n // Flatten any allOf wrapper on the variant (e.g. `ConnectApplication`'s\n // OAuth branch is `allOf: [{ properties: {…} }, { oneOf: [first-party\n // sub-variants] }]`). The flattened object has merged properties and\n // an inlined sub-variant `oneOf` so `extractInlineModelDeep` can pull\n // out a complete variant model.\n const flat = flattenVariantForExtraction(variant);\n if (!flat.properties || (flat.type !== undefined && flat.type !== 'object')) continue;\n\n // Merge base fields into the variant. Variant-specific properties win\n // on name collisions because the spec may pin a base field to a more\n // specific shape inside a variant.\n const mergedProperties: Record<string, SchemaObject> = { ...baseProperties };\n for (const [k, v] of Object.entries(flat.properties)) {\n if (v) mergedProperties[k] = v;\n }\n const mergedRequired = new Set<string>([...baseRequired, ...(flat.required ?? [])]);\n const merged: SchemaObject = {\n type: 'object',\n properties: mergedProperties,\n required: [...mergedRequired],\n };\n\n const variantName = deriveDiscriminatedVariantName(variant, fallbackName);\n for (const model of extractInlineModelDeep(variantName, merged)) {\n if (seenNames.has(model.name)) continue;\n seenNames.add(model.name);\n models.push(model);\n }\n }\n }\n\n return models;\n}\n\n/**\n * Flatten a oneOf variant schema into a single object-shaped schema for\n * variant-model extraction. Recursively merges `allOf` members and folds\n * any nested `oneOf` into an inline-oneOf field group whose properties are\n * the union across sub-branches (required only when present in every\n * sub-branch). Returns the schema unchanged when no flattening is needed.\n */\nfunction flattenVariantForExtraction(variant: SchemaObject): SchemaObject {\n if (!variant.allOf) return variant;\n\n const mergedProperties: Record<string, SchemaObject> = {};\n const mergedRequired = new Set<string>();\n const nestedOneOfs: SchemaObject[][] = [];\n\n const collect = (s: SchemaObject): void => {\n if (s.properties) {\n for (const [k, v] of Object.entries(s.properties)) {\n if (!(k in mergedProperties) && v) mergedProperties[k] = v;\n }\n }\n if (s.required) {\n for (const r of s.required) mergedRequired.add(r);\n }\n if (s.allOf) {\n for (const sub of s.allOf) collect(sub);\n }\n if (s.oneOf) nestedOneOfs.push(s.oneOf);\n };\n collect(variant);\n\n // Fold each nested oneOf into the merged shape: any field appearing in any\n // sub-branch is included as optional (or required iff present-and-required\n // in every sub-branch). Conflicting literal types widen to their primitive\n // base. This handles the `is_first_party: true | false` widening on the\n // OAuth variant's first-party sub-oneOf.\n for (const branches of nestedOneOfs) {\n const flatBranches = branches.map(flattenVariantForExtraction);\n const branchKeys = new Set<string>();\n for (const b of flatBranches) {\n for (const k of Object.keys(b.properties ?? {})) branchKeys.add(k);\n }\n for (const key of branchKeys) {\n const schemas: SchemaObject[] = [];\n for (const b of flatBranches) {\n const s = b.properties?.[key];\n if (s) schemas.push(s);\n }\n const merged = mergeBranchPropertySchemas(schemas);\n if (!(key in mergedProperties)) mergedProperties[key] = merged;\n const inAllBranches = flatBranches.every((b) => b.properties && key in b.properties);\n const requiredInAll = inAllBranches && flatBranches.every((b) => (b.required ?? []).includes(key));\n if (requiredInAll) mergedRequired.add(key);\n }\n }\n\n return {\n type: 'object',\n properties: mergedProperties,\n required: [...mergedRequired],\n };\n}\n\n/**\n * Merge same-named property schemas from across sub-variants. If every\n * occurrence is a boolean const, widen to plain boolean; if every occurrence\n * is a distinct string const, widen to plain string. Otherwise return the\n * first occurrence — emitters that build their own widened types (e.g. the\n * Node discriminated-models module) re-derive from the raw spec.\n */\nfunction mergeBranchPropertySchemas(schemas: SchemaObject[]): SchemaObject {\n if (schemas.length === 0) return {};\n if (schemas.length === 1) return schemas[0];\n\n const allBoolConst = schemas.every((s) => s.type === 'boolean' && typeof s.const === 'boolean');\n if (allBoolConst) {\n return { type: 'boolean', description: schemas[0].description };\n }\n const allStringConst = schemas.every((s) => s.type === 'string' && typeof s.const === 'string');\n if (allStringConst) {\n const values = schemas.map((s) => s.const as string);\n if (new Set(values).size === 1) return schemas[0];\n return { type: 'string', description: schemas[0].description };\n }\n return schemas[0];\n}\n\nfunction deriveDiscriminatedVariantName(schema: SchemaObject, fallbackName: string): string {\n // Walk through allOf wrappers so a variant of the form\n // `{ allOf: [{ properties: { type: const: 'oauth' } }, { oneOf: […] }] }`\n // still surfaces its discriminator const value for naming.\n const effective = getEffectiveProperties(schema);\n if (Object.keys(effective).length === 0) return fallbackName;\n\n const pickConst = (name: string): string | null => {\n const field = effective[name];\n if (!field) return null;\n if (typeof field.const === 'string') return field.const;\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return field.enum[0];\n }\n return null;\n };\n\n let constValue: string | null = null;\n for (const preferred of ['event', 'type', 'object']) {\n constValue = pickConst(preferred);\n if (constValue) break;\n }\n if (constValue === null) {\n for (const name of Object.keys(effective)) {\n constValue = pickConst(name);\n if (constValue) break;\n }\n }\n if (constValue === null) return fallbackName;\n\n const pascal = toPascalCase(constValue);\n if (!pascal) return fallbackName;\n\n // A single-word const like `oauth` or `m2m` is too generic to stand alone\n // as a top-level model name — it would collide with unrelated schemas. Pair\n // it with the parent name so the variant resolves to e.g. `ConnectApplicationOAuth`\n // / `ConnectApplicationM2M`. Multi-word consts like `action.authentication.denied`\n // are already specific enough on their own, matching the established\n // EventSchema variant naming.\n const wordCount = splitWords(constValue).length;\n if (wordCount >= 2) return pascal;\n if (pascal === fallbackName) return pascal;\n if (fallbackName.startsWith(pascal)) return fallbackName;\n if (pascal.endsWith(fallbackName)) return pascal;\n return `${fallbackName}${pascal}`;\n}\n\nfunction extractInlineModelDeep(name: string, schema: SchemaObject): Model[] {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n const properties = schema.properties ?? {};\n const nestedModels: Model[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n nestedModels.push(...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), fieldSchema));\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items?.properties) {\n nestedModels.push(...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), fieldSchema.items));\n }\n\n if (fieldSchema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of fieldSchema.allOf) {\n if (sub.properties) Object.assign(mergedProperties, sub.properties);\n if (sub.required) mergedRequired.push(...sub.required);\n }\n if (Object.keys(mergedProperties).length > 0) {\n nestedModels.push(\n ...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), {\n type: 'object',\n properties: mergedProperties,\n required: mergedRequired,\n }),\n );\n }\n }\n\n if (fieldSchema.oneOf) {\n const inlineObjectVariants = fieldSchema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n if (inlineObjectVariants.length > 0) {\n const baseQualified = qualifyNestedInlineName(name, fieldName);\n const namingDisc = deriveConstNamingDiscriminator(inlineObjectVariants);\n const emitted: Model[] = [];\n for (const variant of inlineObjectVariants) {\n const variantName = nameVariantModel(variant, baseQualified, emitted, namingDisc);\n emitted.push({ name: variantName, fields: [] });\n nestedModels.push(...extractInlineModelDeep(variantName, variant));\n }\n }\n }\n }\n\n return [{ name, description: schema.description, fields }, ...nestedModels];\n}\n\nfunction qualifyNestedInlineName(parentName: string, fieldName: string): string {\n const pascalField = toPascalCase(fieldName);\n if (pascalField.startsWith(parentName)) return pascalField;\n\n const cleanParent = stripListItemMarkers(parentName);\n const qualified = `${cleanParent}${pascalField}`;\n const match = qualified.match(/^(.+?)([A-Z][a-z]+s?)$/);\n if (match && match[2]) {\n return match[1] + singularize(match[2]);\n }\n return qualified;\n}\n\nexport function schemaToTypeRef(schema: SchemaObject, contextName?: string, parentModelName?: string): TypeRef {\n // Handle $ref → ModelRef or EnumRef.\n // A `$ref` to a top-level component schema needs to preserve whether the\n // target is a model or an enum, because emitters route imports differently\n // for the two kinds (e.g. com.workos.models.X vs com.workos.types.X). The\n // set of enum names is precomputed by extractSchemas() in a first pass so\n // it's available even when called recursively for nested $refs.\n if (schema.$ref) {\n const segments = schema.$ref.split('/');\n const rawName = segments[segments.length - 1];\n const resolved = resolveSchemaName(rawName);\n if (activeEnumSchemaNames.has(resolved)) {\n return { kind: 'enum', name: resolved };\n }\n return { kind: 'model', name: resolved };\n }\n\n // Handle OAS 3.1 nullable type arrays: type: [string, null]\n if (Array.isArray(schema.type)) {\n const nonNullTypes = schema.type.filter((t: string) => t !== 'null');\n // type: ['null'] — only null, no real type\n if (nonNullTypes.length === 0) {\n return { kind: 'nullable', inner: { kind: 'primitive', type: 'unknown' } };\n }\n if (schema.type.includes('null') && nonNullTypes.length === 1) {\n return {\n kind: 'nullable',\n inner: schemaToTypeRef({ ...schema, type: nonNullTypes[0], nullable: false }, contextName),\n };\n }\n // Multiple non-null types → union\n if (nonNullTypes.length > 1) {\n const variants = nonNullTypes.map((t: string) => schemaToTypeRef({ ...schema, type: t }, contextName));\n const ref: TypeRef = { kind: 'union', variants };\n if (schema.type.includes('null')) {\n return { kind: 'nullable', inner: ref };\n }\n return ref;\n }\n }\n\n // Handle OAS 3.0 nullable flag\n if (schema.nullable && schema.type) {\n return {\n kind: 'nullable',\n inner: schemaToTypeRef({ ...schema, nullable: false }, contextName),\n };\n }\n\n // Handle allOf — merge properties from all sub-schemas.\n // This handles patterns like: allOf: [{ type: object, properties: {...} }, { oneOf: [...] }]\n // which are valid OAS 3.1 but weren't handled for field-level schemas.\n if (schema.allOf) {\n // If allOf contains a $ref, prefer the ref (it's a named type)\n const refItem = schema.allOf.find((s: SchemaObject) => s.$ref);\n if (refItem) {\n // If allOf has $ref AND siblings with properties, return a merged model ref\n // to avoid losing the augmentation properties\n const hasAugmentation = schema.allOf.some((s: SchemaObject) => !s.$ref && (s.properties || s.type === 'object'));\n if (hasAugmentation) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return { kind: 'model', name: qualifyInlineModelName(baseName, parentModelName) };\n }\n return schemaToTypeRef(refItem, contextName, parentModelName);\n }\n // If allOf has a single item, unwrap it\n if (schema.allOf.length === 1) {\n return schemaToTypeRef(schema.allOf[0], contextName, parentModelName);\n }\n // If allOf items all have properties, treat as a merged model\n const hasProperties = schema.allOf.some((s: SchemaObject) => s.properties);\n if (hasProperties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n // Fall through to other checks\n }\n\n // Handle oneOf / anyOf → Union or Nullable\n // Valid OAS 3.1: properties can have { oneOf: [{ type: object }, { type: 'null' }] }\n // without a wrapping `type` field.\n if (schema.oneOf || schema.anyOf) {\n const compositionKind: 'oneOf' | 'anyOf' = schema.oneOf ? 'oneOf' : 'anyOf';\n const rawVariants: SchemaObject[] = schema.oneOf ?? schema.anyOf ?? [];\n\n // Check for nullable pattern: oneOf: [realType, { type: 'null' }]\n const nullVariant = rawVariants.find(\n (v: SchemaObject) => v.type === 'null' || (Array.isArray(v.type) && v.type.length === 1 && v.type[0] === 'null'),\n );\n const nonNullVariants = rawVariants.filter((v) => v !== nullVariant);\n\n if (nullVariant && nonNullVariants.length === 1) {\n // Nullable single type — unwrap as nullable\n return {\n kind: 'nullable',\n inner: schemaToTypeRef(nonNullVariants[0], contextName, parentModelName),\n };\n }\n\n // Collapse an oneOf/anyOf whose non-null variants are all string-const\n // schemas into a single enum. This turns patterns like\n // provider: { oneOf: [{ const: \"AppleOAuth\" }, { const: \"GitHubOAuth\" }, ...] }\n // into a proper enum type with one member per variant instead of a\n // structurally-opaque union of literal refs.\n const literalStrings = collectLiteralStringConsts(nonNullVariants);\n if (literalStrings !== null && literalStrings.length >= 2) {\n const enumRef = buildSyntheticEnumRef(literalStrings, contextName, parentModelName);\n return nullVariant ? { kind: 'nullable', inner: enumRef } : enumRef;\n }\n\n // Resolve the discriminator. Three sources, in order:\n // 1. Explicit `discriminator:` with explicit `mapping:` — trust the spec.\n // 2. Explicit `discriminator:` with no `mapping:` — derive mapping from\n // variants' const values on the discriminator property, pairing each\n // to its inline-extracted variant model name (built the same way\n // `extractNestedSchema` names them via `nameVariantModel`). This\n // covers `ApiKey.owner`-shaped schemas where the spec uses\n // `discriminator: { propertyName: type }` but lists inline anonymous\n // `oneOf` variants instead of `$ref` links.\n // 3. No explicit discriminator but every variant pins the same const-\n // valued property AND the variants are nameable via $ref/title —\n // `detectConstPropertyDiscriminator` covers this.\n // 4. As a last resort, when (3) doesn't apply because variants are\n // inline anonymous objects, derive the same const → variant-model-\n // name mapping using `nameVariantModel`. This covers\n // `ApiKeyCreatedData.owner`-shaped schemas (oneOf with inline\n // const-discriminating variants but no `discriminator:` keyword).\n let resolvedDiscriminator: { property: string; mapping: Record<string, string> } | undefined;\n if (schema.discriminator) {\n const property = schema.discriminator.propertyName;\n const explicitMapping = schema.discriminator.mapping ?? {};\n let mapping: Record<string, string> = Object.fromEntries(\n Object.entries(explicitMapping).map(([k, v]) => [k, v.replace(/^#\\/components\\/schemas\\//, '')]),\n );\n if (Object.keys(mapping).length === 0) {\n const inlineMapping = deriveInlineVariantMapping(nonNullVariants, property, contextName, parentModelName);\n if (inlineMapping) mapping = inlineMapping;\n }\n resolvedDiscriminator = { property, mapping };\n } else if (compositionKind === 'oneOf') {\n const synthetic = detectConstPropertyDiscriminator(nonNullVariants);\n if (synthetic) {\n resolvedDiscriminator = synthetic;\n } else {\n const namingDisc = deriveConstNamingDiscriminator(nonNullVariants);\n if (namingDisc) {\n const inlineMapping = deriveInlineVariantMapping(\n nonNullVariants,\n namingDisc.property,\n contextName,\n parentModelName,\n );\n if (inlineMapping) {\n resolvedDiscriminator = { property: namingDisc.property, mapping: inlineMapping };\n }\n }\n }\n }\n\n // Build variants. When we have a discriminator with a known mapping and\n // every non-null variant is an inline object that pins the discriminator\n // property to a const, route each variant's TypeRef through that mapping.\n // This avoids the degenerate case where `qualifyInlineModelName` would\n // assign the same parent-derived name (e.g. `ApiKeyOwner`) to every\n // inline variant, collapsing the union to a single repeated model ref.\n const variants: TypeRef[] = [];\n for (const v of rawVariants) {\n if (v === nullVariant) continue;\n const inlineMappingName =\n resolvedDiscriminator && !v.$ref && v.properties && (v.type === 'object' || !v.type)\n ? mapVariantToDiscriminatorEntry(v, resolvedDiscriminator)\n : null;\n if (inlineMappingName) {\n variants.push({ kind: 'model', name: inlineMappingName });\n } else {\n variants.push(schemaToTypeRef(v, contextName, parentModelName));\n }\n }\n const hasNull = !!nullVariant;\n\n const union: TypeRef = {\n kind: 'union',\n variants,\n compositionKind,\n ...(resolvedDiscriminator ? { discriminator: resolvedDiscriminator } : {}),\n };\n return hasNull ? { kind: 'nullable', inner: union } : union;\n }\n\n // Handle const → LiteralType (supports string, number, boolean)\n if (schema.const !== undefined) {\n if (typeof schema.const === 'string' || typeof schema.const === 'number' || typeof schema.const === 'boolean') {\n return { kind: 'literal', value: schema.const };\n }\n // null const → nullable unknown\n if (schema.const === null) {\n return { kind: 'nullable', inner: { kind: 'primitive', type: 'unknown' } };\n }\n // const of object/array → map or array with unknown values\n if (typeof schema.const === 'object') {\n if (Array.isArray(schema.const)) {\n return { kind: 'array', items: { kind: 'primitive', type: 'unknown' } };\n }\n return { kind: 'map', valueType: { kind: 'primitive', type: 'unknown' } };\n }\n }\n if (schema.enum && schema.enum.length === 1) {\n const v = schema.enum[0];\n return { kind: 'literal', value: typeof v === 'number' ? v : String(v) };\n }\n\n // Handle enum\n if (schema.enum) {\n const baseName = toPascalCase(contextName ?? 'UnknownEnum');\n // Strip ListItem/ByExternalId markers from parent name so enum names are clean:\n // e.g., DirectoryListItem + State → Directory + State = DirectoryState\n const cleanParent = parentModelName ? stripListItemMarkers(parentModelName) : undefined;\n // Avoid redundant prefix: Connection + ConnectionType → ConnectionType\n const qualifiedName = cleanParent && !baseName.startsWith(cleanParent) ? `${cleanParent}${baseName}` : baseName;\n // Run `schemaNameTransform` so project-level rename maps in\n // `oagen.config.ts` reach inline parameter/field enums too — without\n // this, `RadarAction` (built from path param `action` on the Radar\n // service) couldn't be redirected to `RadarListAction` from config.\n const finalName = activeSchemaNameTransform ? activeSchemaNameTransform(qualifiedName) : qualifiedName;\n return {\n kind: 'enum',\n name: finalName,\n values: schema.enum.map((v) => (typeof v === 'number' ? v : String(v))),\n };\n }\n\n // Handle array — pass parentModelName through to qualify inline items\n if (schema.type === 'array' && schema.items) {\n return {\n kind: 'array',\n items: schemaToTypeRef(schema.items, contextName, parentModelName),\n };\n }\n // Handle array without explicit type but with items (valid OAS 3.1)\n if (!schema.type && schema.items) {\n return {\n kind: 'array',\n items: schemaToTypeRef(schema.items, contextName, parentModelName),\n };\n }\n\n // Handle object → ModelRef (if it has properties, it's a named model reference)\n // When additionalProperties is also present, we still return a ModelRef so the\n // named properties are preserved. The extractModel path will pick up the extra\n // properties as a catch-all map field named `additionalProperties`.\n if (schema.type === 'object' && schema.properties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n\n // Handle freeform object with additionalProperties or patternProperties → Map<string, T>\n if (schema.type === 'object' && !schema.properties) {\n let valueType: TypeRef = { kind: 'primitive', type: 'unknown' };\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {\n // Empty additionalProperties ({}) means \"any value\" — keep as unknown\n const apKeys = Object.keys(schema.additionalProperties);\n if (apKeys.length > 0) {\n valueType = schemaToTypeRef(schema.additionalProperties as SchemaObject, contextName);\n }\n } else if (schema.patternProperties) {\n // patternProperties: { \"pattern\": schema } → use the first pattern's schema as value type\n const patterns = Object.values(schema.patternProperties);\n if (patterns.length > 0) {\n valueType = schemaToTypeRef(patterns[0], contextName);\n }\n }\n return {\n kind: 'map',\n valueType,\n };\n }\n\n // Handle primitives\n const primitiveMap: Record<string, 'string' | 'integer' | 'number' | 'boolean'> = {\n string: 'string',\n integer: 'integer',\n number: 'number',\n boolean: 'boolean',\n };\n\n const typeStr = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n if (typeStr && primitiveMap[typeStr]) {\n return {\n kind: 'primitive',\n type: primitiveMap[typeStr],\n ...(schema.format ? { format: schema.format } : {}),\n };\n }\n\n // Handle schemas with no type — if it has properties, treat as model\n if (!schema.type && schema.properties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n\n // Empty schema {} → unknown\n if (\n !schema.type &&\n !schema.$ref &&\n !schema.oneOf &&\n !schema.anyOf &&\n !schema.allOf &&\n !schema.enum &&\n !schema.properties &&\n !schema.items\n ) {\n return { kind: 'primitive', type: 'unknown' };\n }\n\n // Fallback: treat unknown schemas as unknown\n if (contextName) {\n console.warn(`[oagen] Warning: Unknown schema shape treated as unknown (context: ${contextName})`);\n }\n return { kind: 'primitive', type: 'unknown' };\n}\n\nimport { qualifyInlineModelName } from './inline-models.js';\n\nexport { qualifyInlineModelName, extractInlineModelsFromSchemas } from './inline-models.js';\n","import type { TypeRef, Parameter, PaginationMeta } from '../ir/types.js';\n\nconst CURSOR_PARAMS = ['cursor', 'after', 'before', 'starting_after', 'ending_before', 'page_token', 'next_token'];\n\nconst OFFSET_PARAMS = ['offset', 'page', 'page_number', 'skip'];\nconst LIMIT_PARAMS = ['limit', 'page_size', 'per_page', 'size', 'count'];\n\n/**\n * Detect if an operation uses pagination and return structured metadata\n * for auto-paging iterator generation.\n *\n * Supports two strategies:\n * 1. **Cursor-based**: query params include a cursor-like parameter\n * 2. **Offset-based**: query params include both an offset-like and limit-like parameter\n *\n * Returns null if no pagination pattern is detected.\n */\nexport function detectPagination(\n response: TypeRef,\n queryParams: Parameter[],\n dataPath?: string,\n): PaginationMeta | null {\n // Try cursor-based first (preferred). Scan in CURSOR_PARAMS priority order\n // rather than queryParams order so that an endpoint exposing both `before`\n // and `after` reports `after` (forward iteration) — matches the wire\n // convention where `after` advances through pages.\n const cursorParam = CURSOR_PARAMS.map((name) => queryParams.find((p) => p.name === name)).find(\n (p): p is Parameter => p !== undefined,\n );\n\n if (cursorParam) {\n const itemType: TypeRef = response.kind === 'array' ? response.items : response;\n return {\n strategy: 'cursor',\n param: cursorParam.name,\n dataPath: dataPath,\n itemType,\n };\n }\n\n // Try offset-based pagination\n const offsetParam = queryParams.find((p) => OFFSET_PARAMS.includes(p.name));\n const limitParam = queryParams.find((p) => LIMIT_PARAMS.includes(p.name));\n\n if (offsetParam && limitParam) {\n const itemType: TypeRef = response.kind === 'array' ? response.items : response;\n return {\n strategy: 'offset',\n param: offsetParam.name,\n limitParam: limitParam.name,\n dataPath: dataPath,\n itemType,\n };\n }\n\n return null;\n}\n","import type { TypeRef, Model, Field } from '../ir/types.js';\nimport { toPascalCase, singularize, stripListItemMarkers } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { schemaToTypeRef, buildFieldFromSchema } from './schemas.js';\n\nexport interface ResponseExtractionResult {\n /** The TypeRef to use as the operation's response type */\n response: TypeRef;\n /** Any inline models discovered during extraction (to merge into ir.models) */\n inlineModels: Model[];\n /** Whether this response indicates a paginated list */\n isPaginated: boolean;\n /** Path to the data array within the response envelope (e.g., 'data') */\n dataPath?: string;\n /** TypeRef of individual items in a paginated list */\n itemType?: TypeRef;\n}\n\nexport function classifyAndExtractResponse(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n // 1. If schema is a $ref, resolve to model name (Phase 1)\n if (schema.$ref) {\n return { response: schemaToTypeRef(schema, contextName), inlineModels: [], isPaginated: false };\n }\n\n // 2. Check for list envelope (structural detection: array prop + non-array companion)\n const envelope = detectListEnvelope(schema);\n if (envelope.isEnvelope) {\n return extractListResponse(schema, contextName, envelope.dataPath!);\n }\n\n // 3. Check for single-resource wrapper ({ resource_name: { object: \"...\", ... } })\n if (isSingleResourceWrapper(schema)) {\n return extractWrappedResource(schema, contextName);\n }\n\n // 4. Direct resource or plain inline object\n return extractDirectResource(schema, contextName);\n}\n\ninterface ListEnvelopeResult {\n isEnvelope: boolean;\n dataPath: string | null;\n}\n\nconst KNOWN_DATA_PATHS = new Set(['data', 'items', 'results', 'records', 'entries', 'values', 'nodes', 'edges']);\n\nconst PAGINATION_METADATA_PATTERNS = [\n 'meta',\n 'metadata',\n 'pagination',\n 'cursor',\n 'has_more',\n 'page_info',\n 'total',\n 'next_page',\n 'previous_page',\n 'offset',\n];\n\nfunction detectListEnvelope(schema: SchemaObject): ListEnvelopeResult {\n // Collect all property sources (allOf sub-schemas or flat schema)\n const propSources: Record<string, SchemaObject | undefined>[] = [];\n if (schema.allOf) {\n for (const sub of schema.allOf) {\n if (sub.properties) propSources.push(sub.properties);\n }\n }\n if (schema.properties) {\n propSources.push(schema.properties);\n }\n\n if (propSources.length === 0) return { isEnvelope: false, dataPath: null };\n\n // Merge all properties into a single view\n const mergedProps: Record<string, SchemaObject | undefined> = {};\n for (const source of propSources) {\n Object.assign(mergedProps, source);\n }\n\n // Find array-typed properties and non-array companion properties\n const arrayProps: string[] = [];\n const nonArrayKeys: string[] = [];\n\n for (const [key, propSchema] of Object.entries(mergedProps)) {\n if (!propSchema) continue;\n if (propSchema.type === 'array') {\n arrayProps.push(key);\n } else {\n nonArrayKeys.push(key);\n }\n }\n\n // List envelope heuristic: exactly one array property + at least one non-array companion\n // that looks like pagination metadata. A `data` array alone (e.g. with only an\n // `object` discriminant companion) is NOT sufficient — the companion must indicate\n // actual pagination (cursor, metadata, total, etc.).\n if (arrayProps.length === 1 && nonArrayKeys.length >= 1) {\n const arrayPropName = arrayProps[0];\n\n const hasPaginationCompanion = nonArrayKeys.some((key) =>\n PAGINATION_METADATA_PATTERNS.some((pattern) => key.toLowerCase().includes(pattern)),\n );\n\n if (KNOWN_DATA_PATHS.has(arrayPropName) && hasPaginationCompanion) {\n return { isEnvelope: true, dataPath: arrayPropName };\n }\n\n // Non-standard array property name — still treat as envelope if pagination companion exists\n if (hasPaginationCompanion) {\n return { isEnvelope: true, dataPath: arrayPropName };\n }\n }\n\n return { isEnvelope: false, dataPath: null };\n}\n\nfunction extractListResponse(schema: SchemaObject, contextName: string, dataPath: string): ResponseExtractionResult {\n let itemTypeRef: TypeRef = { kind: 'primitive', type: 'string' };\n const inlineModels: Model[] = [];\n\n // Collect all property sources (allOf sub-schemas or flat schema)\n const propSources: Record<string, SchemaObject | undefined>[] = [];\n if (schema.allOf) {\n for (const sub of schema.allOf) {\n if (sub.properties) propSources.push(sub.properties);\n }\n }\n if (schema.properties) {\n propSources.push(schema.properties);\n }\n\n for (const props of propSources) {\n const dataProp = props[dataPath];\n if (!dataProp) continue;\n\n if (dataProp.type === 'array' && dataProp.items) {\n const items = dataProp.items;\n if (items.$ref) {\n itemTypeRef = schemaToTypeRef(items, contextName);\n } else if (items.type === 'object' && items.properties) {\n const itemName = contextName.replace(/Response$/, '') + 'Item';\n itemTypeRef = { kind: 'model', name: itemName };\n inlineModels.push(...extractInlineModel(itemName, items));\n }\n }\n }\n\n return {\n response: { kind: 'array', items: itemTypeRef },\n inlineModels,\n isPaginated: true,\n dataPath,\n itemType: itemTypeRef,\n };\n}\n\nfunction hasDiscriminantConstField(schema: SchemaObject): { property: string; value: string } | null {\n if (!schema.properties) return null;\n\n // Prefer well-known discriminant properties for backward compatibility\n const preferred = ['object', 'type'];\n for (const name of preferred) {\n const field = schema.properties[name];\n if (!field) continue;\n if (field.const !== undefined && typeof field.const === 'string') {\n return { property: name, value: field.const };\n }\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return { property: name, value: field.enum[0] };\n }\n }\n\n // Fall back to any property with a const or single-value enum\n for (const [name, field] of Object.entries(schema.properties)) {\n if (!field) continue;\n if (field.const !== undefined && typeof field.const === 'string') {\n return { property: name, value: field.const };\n }\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return { property: name, value: field.enum[0] };\n }\n }\n\n return null;\n}\n\nfunction isSingleResourceWrapper(schema: SchemaObject): boolean {\n if (schema.type !== 'object') return false;\n if (!schema.properties) return false;\n\n // Find the wrapper property: use required[0] if available, or the single property key\n let wrapperKey: string | undefined;\n if (schema.required && schema.required.length === 1) {\n wrapperKey = schema.required[0];\n } else {\n const propKeys = Object.keys(schema.properties);\n if (propKeys.length === 1) {\n wrapperKey = propKeys[0];\n }\n }\n if (!wrapperKey) return false;\n\n const propSchema = schema.properties[wrapperKey];\n if (!propSchema) return false;\n\n // Direct object with a discriminant const field\n if (propSchema.type === 'object' && hasDiscriminantConstField(propSchema) !== null) return true;\n\n // oneOf with object + null (nullable resource)\n if (propSchema.oneOf) {\n return propSchema.oneOf.some((v) => v.type === 'object' && hasDiscriminantConstField(v) !== null);\n }\n\n return false;\n}\n\nfunction extractWrappedResource(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n const props = schema.properties!;\n const wrapperKey = schema.required && schema.required.length === 1 ? schema.required[0] : Object.keys(props)[0];\n const propSchema = props[wrapperKey]!;\n const inlineModels: Model[] = [];\n\n // Derive model name from the object const value or wrapper property name\n const resourceName = contextName.replace(/Response$/, '');\n\n if (propSchema.oneOf) {\n const objectVariant = propSchema.oneOf.find((v) => v.type === 'object' && hasDiscriminantConstField(v) !== null);\n\n if (objectVariant) {\n const modelName = deriveModelName(objectVariant, resourceName);\n inlineModels.push(...extractInlineModel(modelName, objectVariant));\n\n const hasNullVariant = propSchema.oneOf.some(\n (v) => v.type === 'null' || (Array.isArray(v.type) && v.type.includes('null')),\n );\n\n const modelRef: TypeRef = { kind: 'model', name: modelName };\n return {\n response: hasNullVariant ? { kind: 'nullable', inner: modelRef } : modelRef,\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // Direct object\n const modelName = deriveModelName(propSchema, resourceName);\n inlineModels.push(...extractInlineModel(modelName, propSchema));\n\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n}\n\nfunction extractDirectResource(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n const inlineModels: Model[] = [];\n\n // Direct object with properties (with or without explicit type: 'object')\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const modelName = deriveModelName(schema, contextName);\n inlineModels.push(...extractInlineModel(modelName, schema));\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n }\n\n // allOf with properties — merge into a single model\n if (schema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of schema.allOf) {\n if (sub.properties) {\n Object.assign(mergedProperties, sub.properties);\n }\n if (sub.required) {\n mergedRequired.push(...sub.required);\n }\n }\n if (Object.keys(mergedProperties).length > 0) {\n const merged: SchemaObject = { type: 'object', properties: mergedProperties, required: mergedRequired };\n const modelName = deriveModelName(merged, contextName);\n inlineModels.push(...extractInlineModel(modelName, merged));\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // oneOf — delegate to schemaToTypeRef (returns union) but also extract inline models\n // from object variants so the model refs resolve\n if (schema.oneOf) {\n for (const variant of schema.oneOf) {\n if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const modelName = deriveModelName(variant, contextName);\n const existingNames = new Set(inlineModels.map((m) => m.name));\n if (!existingNames.has(modelName)) {\n inlineModels.push(...extractInlineModel(modelName, variant));\n }\n }\n }\n }\n\n // Array with inline object items — extract the item model\n if (schema.type === 'array' && schema.items) {\n const items = schema.items;\n if (items.$ref) {\n return {\n response: { kind: 'array', items: schemaToTypeRef(items, contextName) },\n inlineModels,\n isPaginated: false,\n };\n }\n if (items.properties && (items.type === 'object' || !items.type)) {\n const itemName = contextName.replace(/Response$/, '') + 'Item';\n inlineModels.push(...extractInlineModel(itemName, items));\n return {\n response: { kind: 'array', items: { kind: 'model', name: itemName } },\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // Non-object schema (primitive, union, etc.) — delegate to schemaToTypeRef\n return {\n response: schemaToTypeRef(schema, contextName),\n inlineModels,\n isPaginated: false,\n };\n}\n\nfunction deriveModelName(schema: SchemaObject, fallback: string): string {\n if (!schema.properties) return toPascalCase(fallback);\n\n // Prefer well-known discriminant properties for backward compatibility\n const preferred = ['object', 'type'];\n for (const name of preferred) {\n const field = schema.properties[name];\n if (field && field.const && typeof field.const === 'string') {\n return toPascalCase(field.const);\n }\n }\n\n // Fall back to any property with a const string value\n for (const [, field] of Object.entries(schema.properties)) {\n if (field && field.const && typeof field.const === 'string') {\n return toPascalCase(field.const);\n }\n }\n\n return toPascalCase(fallback);\n}\n\n/**\n * Qualify a nested inline model name with its parent to avoid generic names.\n * e.g., parent=\"Connection\" + field=\"domains\" → \"ConnectionDomain\" (singularized)\n * Only qualifies when the field name alone would be too generic.\n */\nfunction qualifyNestedName(parentName: string, fieldName: string): string {\n const pascalField = toPascalCase(fieldName);\n // If the field name already starts with the parent name, don't double-prefix\n if (pascalField.startsWith(parentName)) return pascalField;\n // Qualify with parent and singularize:\n // Connection + Domains → ConnectionDomains → singularize lead word → ConnectionDomain\n const cleanParent = stripListItemMarkers(parentName);\n const qualified = `${cleanParent}${pascalField}`;\n // Singularize the trailing word: ConnectionDomains → ConnectionDomain\n const match = qualified.match(/^(.+?)([A-Z][a-z]+s?)$/);\n if (match && match[2]) {\n const trailing = singularize(match[2]);\n return match[1] + trailing;\n }\n return qualified;\n}\n\nfunction extractInlineModel(name: string, schema: SchemaObject): Model[] {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n const properties = schema.properties ?? {};\n const nestedModels: Model[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n\n // Recursively extract nested inline objects — qualify with parent name\n // to avoid generic names like \"Domains\" when multiple parents have a \"domains\" field\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n const nestedName = qualifyNestedName(name, fieldName);\n nestedModels.push(...extractInlineModel(nestedName, fieldSchema));\n }\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n const items = fieldSchema.items;\n if (items.type === 'object' && items.properties) {\n const nestedName = qualifyNestedName(name, fieldName);\n nestedModels.push(...extractInlineModel(nestedName, items));\n }\n }\n // Handle allOf with inline object properties — merge into a single nested model\n if (fieldSchema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of fieldSchema.allOf) {\n if (sub.properties) Object.assign(mergedProperties, sub.properties);\n if (sub.required) mergedRequired.push(...sub.required);\n }\n if (Object.keys(mergedProperties).length > 0) {\n const nestedName = qualifyNestedName(name, fieldName);\n const merged: SchemaObject = { type: 'object', properties: mergedProperties, required: mergedRequired };\n const existingNames = new Set(nestedModels.map((m) => m.name));\n if (!existingNames.has(nestedName)) {\n nestedModels.push(...extractInlineModel(nestedName, merged));\n }\n }\n }\n // Handle oneOf containing inline objects — extract the first non-null object variant\n if (fieldSchema.oneOf) {\n const objectVariant = fieldSchema.oneOf.find((v) => v.properties && (v.type === 'object' || !v.type));\n if (objectVariant) {\n const nestedName = qualifyNestedName(name, fieldName);\n const existingNames = new Set(nestedModels.map((m) => m.name));\n if (!existingNames.has(nestedName)) {\n nestedModels.push(...extractInlineModel(nestedName, objectVariant));\n }\n }\n }\n }\n\n return [{ name, description: schema.description, fields }, ...nestedModels];\n}\n","import type {\n Service,\n Operation,\n HttpMethod,\n Parameter,\n ParameterGroup,\n TypeRef,\n ErrorResponse,\n SuccessResponse,\n SecurityRequirement,\n Model,\n Field,\n PaginationMeta,\n} from '../ir/types.js';\nimport { toPascalCase, toCamelCase, cleanSchemaName } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { schemaToTypeRef, buildFieldFromSchema } from './schemas.js';\nimport { detectPagination } from './pagination.js';\nimport { classifyAndExtractResponse } from './responses.js';\n\ninterface PathItem {\n get?: OperationObject;\n post?: OperationObject;\n put?: OperationObject;\n patch?: OperationObject;\n delete?: OperationObject;\n head?: OperationObject;\n options?: OperationObject;\n trace?: OperationObject;\n parameters?: ParameterObject[];\n}\n\ninterface ParameterGroupExtension {\n optional: boolean;\n variants: Record<string, string[]>;\n}\n\ninterface OperationObject {\n operationId?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n parameters?: ParameterObject[];\n requestBody?: RequestBodyObject;\n responses?: Record<string, ResponseObject>;\n deprecated?: boolean;\n 'x-oagen-async'?: boolean;\n security?: Array<Record<string, string[]>>;\n 'x-mutually-exclusive-parameter-groups'?: Record<string, ParameterGroupExtension>;\n 'x-mutually-exclusive-body-groups'?: Record<string, ParameterGroupExtension>;\n}\n\ninterface ParameterObject {\n name: string;\n in: 'path' | 'query' | 'header' | 'cookie';\n required?: boolean;\n description?: string;\n schema?: SchemaObject;\n deprecated?: boolean;\n example?: unknown;\n style?: string;\n explode?: boolean;\n}\n\ninterface RequestBodyObject {\n required?: boolean;\n content?: Record<string, { schema?: SchemaObject }>;\n}\n\ninterface ResponseObject {\n description?: string;\n content?: Record<string, { schema?: SchemaObject }>;\n}\n\nconst HTTP_METHODS: HttpMethod[] = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];\n\nexport interface OperationExtractionResult {\n services: Service[];\n inlineModels: Model[];\n}\n\nexport function extractOperations(\n paths: Record<string, PathItem> | undefined,\n operationIdTransform?: (id: string) => string,\n componentSchemas?: Record<string, SchemaObject>,\n): OperationExtractionResult {\n if (!paths) return { services: [], inlineModels: [] };\n\n const serviceMap = new Map<string, Operation[]>();\n const inlineModels: Model[] = [];\n\n for (const [path, pathItem] of Object.entries(paths)) {\n const pathLevelParams = pathItem.parameters ?? [];\n\n for (const method of HTTP_METHODS) {\n const op = pathItem[method];\n if (!op) continue;\n\n const serviceName = inferServiceName(path, op.tags?.[0]);\n\n const { operation, inlineModels: opModels } = buildOperation(\n method,\n path,\n op,\n pathLevelParams,\n operationIdTransform,\n serviceName,\n componentSchemas,\n );\n inlineModels.push(...opModels);\n const ops = serviceMap.get(serviceName) ?? [];\n ops.push(operation);\n serviceMap.set(serviceName, ops);\n }\n }\n\n // Split services when a single tag groups operations from multiple path prefixes.\n // Example: /organizations and /organization_domains both tagged \"organizations\"\n // should become separate services based on their first path segment.\n for (const [serviceName, operations] of serviceMap) {\n const pathGroups = new Map<string, Operation[]>();\n for (const op of operations) {\n const firstSeg = op.path.split('/').filter(Boolean)[0] ?? '';\n const groupKey = firstSeg.startsWith('{') ? serviceName : toPascalCase(firstSeg);\n const group = pathGroups.get(groupKey) ?? [];\n group.push(op);\n pathGroups.set(groupKey, group);\n }\n // Only split if there are multiple distinct path-prefix groups AND\n // at least one group name differs from the current service name\n if (pathGroups.size > 1) {\n const needsSplit = [...pathGroups.keys()].some((k) => k !== serviceName);\n if (needsSplit) {\n serviceMap.delete(serviceName);\n for (const [groupName, groupOps] of pathGroups) {\n const existing = serviceMap.get(groupName) ?? [];\n existing.push(...groupOps);\n serviceMap.set(groupName, existing);\n }\n }\n }\n }\n\n // Disambiguate operation names within each service.\n // Multiple operations can get the same name (e.g., several \"list\" endpoints\n // in UserManagement for users, invitations, auth factors, etc.).\n for (const [, operations] of serviceMap) {\n disambiguateOperationNames(operations);\n }\n\n const services = Array.from(serviceMap.entries()).map(([name, operations]) => ({\n name,\n operations,\n }));\n\n return { services, inlineModels };\n}\n\nfunction inferServiceName(path: string, tag?: string): string {\n // Prefer OpenAPI tag when available — tags represent the logical grouping\n // (e.g., \"multi-factor-auth\" for /auth/factors/* endpoints).\n if (tag) {\n return toPascalCase(tag);\n }\n // Fallback: extract first meaningful path segment: /widgets/{id}/sub → \"Widgets\"\n const segments = path.split('/').filter(Boolean);\n const first = segments[0] ?? 'Default';\n // Skip path params\n if (first.startsWith('{')) return 'Default';\n return toPascalCase(first);\n}\n\n/**\n * Strip overload indices (e.g. NestJS emits `Foo_bar[0]` when a controller\n * method handles multiple routes) from an operationId so derived names never\n * leak the bracketed digit. Without this, `authenticate[0]` would surface as\n * `authenticate0` in method names and `Authenticate0Request` in body model\n * names. Brackets at the end (or with trailing whitespace) are common in\n * NestJS-style backends; this regex is intentionally narrow to avoid eating\n * legitimate digits like `oauth2`.\n */\nfunction normalizeOperationIdForNaming(operationId: string): string {\n return operationId.replace(/\\[\\d+\\]\\s*$/, '');\n}\n\nfunction inferOperationName(\n method: HttpMethod,\n path: string,\n operationId?: string,\n operationIdTransform?: (id: string) => string,\n): string {\n if (operationId) {\n const normalized = normalizeOperationIdForNaming(operationId);\n if (operationIdTransform) {\n return operationIdTransform(normalized);\n }\n return toCamelCase(normalized);\n }\n\n // Fallback when no operationId is available — use method + path to build\n // a descriptive name like \"listUsers\", \"getOrganization\", \"deleteAuthFactor\"\n const verb = inferVerb(method, path);\n const resource = inferResourceFromPath(path);\n return resource ? toCamelCase(`${verb}_${resource}`) : verb;\n}\n\n/**\n * Infer the CRUD verb from HTTP method and path shape.\n */\nfunction inferVerb(method: HttpMethod, path: string): string {\n const segments = path.split('/').filter(Boolean);\n const hasTrailingParam = segments.length > 0 && segments[segments.length - 1].startsWith('{');\n\n switch (method) {\n case 'get':\n return hasTrailingParam ? 'get' : 'list';\n case 'post':\n return 'create';\n case 'put':\n case 'patch':\n return 'update';\n case 'delete':\n return 'delete';\n case 'head':\n return 'check';\n case 'options':\n return 'options';\n case 'trace':\n return 'trace';\n default:\n return method;\n }\n}\n\n/**\n * Extract a resource noun from the path for operation naming.\n * Uses the last non-param segment (the resource being operated on).\n *\n * Examples:\n * /user_management/users → \"Users\"\n * /user_management/users/{id} → \"User\" (singular for item operations)\n * /user_management/users/{id}/auth_factors → \"AuthFactors\"\n * /organizations/{id}/api_keys → \"ApiKeys\"\n * /sso/authorize → \"Authorize\" (action endpoint)\n */\nfunction inferResourceFromPath(path: string): string | null {\n const segments = path.split('/').filter(Boolean);\n if (segments.length <= 1) return null;\n\n // Find the last meaningful (non-param) segment\n let resourceSegment: string | null = null;\n for (let i = segments.length - 1; i >= 0; i--) {\n if (!segments[i].startsWith('{')) {\n resourceSegment = segments[i];\n break;\n }\n }\n\n if (!resourceSegment) return null;\n // Skip the service name (first segment) — it would be redundant\n if (resourceSegment === segments[0]) return null;\n\n return toPascalCase(resourceSegment);\n}\n\n/**\n * Detect and resolve name collisions within a service's operations.\n *\n * When multiple operations share the same name (e.g., several \"list\" from\n * different sub-resources), disambiguate by appending the resource noun\n * from the path. Only renames operations on DIFFERENT paths — same-name\n * operations on the same path (e.g., PUT + PATCH both \"update\") are left as-is\n * since they represent the same logical resource.\n */\nfunction disambiguateOperationNames(operations: Operation[]): void {\n // Group by name\n const byName = new Map<string, Operation[]>();\n for (const op of operations) {\n const group = byName.get(op.name) ?? [];\n group.push(op);\n byName.set(op.name, group);\n }\n\n for (const [name, group] of byName) {\n if (group.length <= 1) continue;\n\n // Check if these are genuinely different resources (different paths)\n // vs the same resource with different methods (PUT + PATCH)\n const uniquePaths = new Set(group.map((op) => op.path));\n if (uniquePaths.size <= 1) continue; // same path, different methods — no disambiguation needed\n\n for (const op of group) {\n const resource = inferResourceFromPath(op.path);\n if (resource) {\n const newName = toCamelCase(`${name}_${resource}`);\n (op as { name: string }).name = newName;\n }\n }\n\n // If disambiguation still left collisions (same sub-resource),\n // use the full distinguishing path segment chain\n const renamed = new Map<string, Operation[]>();\n for (const op of group) {\n const rGroup = renamed.get(op.name) ?? [];\n rGroup.push(op);\n renamed.set(op.name, rGroup);\n }\n for (const [, rGroup] of renamed) {\n if (rGroup.length <= 1) continue;\n // Still colliding — different paths map to same resource name.\n // Use deeper path context to disambiguate.\n for (const op of rGroup) {\n const deeper = inferDeeperContext(op.path);\n if (deeper) {\n (op as { name: string }).name = toCamelCase(`${op.name}_${deeper}`);\n }\n }\n }\n }\n}\n\n/**\n * Extract a deeper disambiguation context from the path when the last\n * segment isn't unique enough. Uses the second-to-last non-param segment.\n *\n * /users/{id}/auth_factors → already captured as \"AuthFactors\"\n * /users/external_id/{external_id} → \"ExternalId\" (special path, not a sub-resource)\n */\nfunction inferDeeperContext(path: string): string | null {\n const segments = path.split('/').filter(Boolean);\n const nonParams = segments.filter((s) => !s.startsWith('{'));\n // Skip first (service) and last (already used) — use the middle ones\n if (nonParams.length >= 3) {\n return toPascalCase(nonParams.slice(1, -1).join('_'));\n }\n return null;\n}\n\n/**\n * Extract mutually-exclusive parameter groups from the `x-mutually-exclusive-parameter-groups`\n * operation extension. Cross-references grouped parameter names against the already-extracted\n * IR parameter arrays so emitters get object-identity references.\n */\nfunction extractParameterGroups(\n op: OperationObject,\n allIRParams: Parameter[],\n operationContext: string,\n): ParameterGroup[] | undefined {\n const raw = op['x-mutually-exclusive-parameter-groups'];\n if (!raw || typeof raw !== 'object') return undefined;\n\n const paramByName = new Map<string, Parameter>();\n for (const p of allIRParams) {\n paramByName.set(p.name, p);\n }\n\n const groups: ParameterGroup[] = [];\n\n for (const [groupName, groupDef] of Object.entries(raw)) {\n if (!groupDef || typeof groupDef !== 'object') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: expected an object with \"optional\" and \"variants\".`,\n );\n }\n\n if (typeof groupDef.optional !== 'boolean') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.optional in ${operationContext}: expected a boolean.`,\n );\n }\n\n if (!groupDef.variants || typeof groupDef.variants !== 'object') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants in ${operationContext}: expected an object mapping variant names to parameter name arrays.`,\n );\n }\n\n if (Object.keys(groupDef.variants).length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: group has zero variants.`,\n );\n }\n\n const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {\n if (!Array.isArray(paramNames) || paramNames.length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`,\n );\n }\n const parameters: Parameter[] = paramNames.map((pName) => {\n const irParam = paramByName.get(pName);\n if (!irParam) {\n throw new Error(\n `x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} references parameter \"${pName}\" which does not exist in the operation's parameters[] (${operationContext}).`,\n );\n }\n return irParam;\n });\n return { name: variantName, parameters };\n });\n\n groups.push({\n name: groupName,\n optional: groupDef.optional,\n variants,\n });\n }\n\n return groups.length > 0 ? groups : undefined;\n}\n\n/**\n * Extract mutually-exclusive body parameter groups from the\n * `x-mutually-exclusive-body-groups` operation extension. Unlike query\n * parameter groups (whose parameters live in operation.queryParams), body\n * group parameters are synthetic — built from the oneOf variant schemas in\n * the request body. Emitters use the group's presence to generate sum-type\n * interfaces and custom JSON marshalling instead of flat optional fields.\n */\nfunction extractBodyParameterGroups(op: OperationObject, operationContext: string): ParameterGroup[] | undefined {\n const raw = op['x-mutually-exclusive-body-groups'];\n if (!raw || typeof raw !== 'object') return undefined;\n\n // Collect the body schema's oneOf variant fields so we can resolve types.\n // The body schema has been structurally rewritten to allOf: [base, { oneOf: [...] }]\n // by the spec generator; the variant properties live inside oneOf branches.\n const bodySchema = op.requestBody?.content?.['application/json']?.schema;\n const variantFieldSchemas = new Map<string, SchemaObject>();\n\n if (bodySchema) {\n // Walk allOf → oneOf → variant.properties to find all variant fields\n for (const sub of bodySchema.allOf ?? []) {\n for (const variant of sub.oneOf ?? []) {\n if (variant.properties) {\n for (const [name, fieldSchema] of Object.entries(variant.properties)) {\n if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);\n }\n }\n }\n }\n // Also check top-level oneOf (for inline schemas that aren't wrapped in allOf)\n for (const variant of bodySchema.oneOf ?? []) {\n if (variant.properties) {\n for (const [name, fieldSchema] of Object.entries(variant.properties)) {\n if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);\n }\n }\n }\n }\n\n const groups: ParameterGroup[] = [];\n\n for (const [groupName, groupDef] of Object.entries(raw)) {\n if (!groupDef || typeof groupDef !== 'object') continue;\n if (typeof groupDef.optional !== 'boolean') continue;\n if (!groupDef.variants || typeof groupDef.variants !== 'object') continue;\n if (Object.keys(groupDef.variants).length === 0) continue;\n\n const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {\n if (!Array.isArray(paramNames) || paramNames.length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-body-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`,\n );\n }\n const parameters: Parameter[] = paramNames.map((pName) => {\n const fieldSchema = variantFieldSchemas.get(pName);\n const fieldType: TypeRef = fieldSchema\n ? schemaToTypeRef(fieldSchema, toPascalCase(pName))\n : { kind: 'primitive', type: 'string' };\n return {\n name: pName,\n type: fieldType,\n required: false, // group variant fields are always optional at the struct level\n description: fieldSchema?.description,\n };\n });\n return { name: variantName, parameters };\n });\n\n groups.push({\n name: groupName,\n optional: groupDef.optional,\n variants,\n });\n }\n\n return groups.length > 0 ? groups : undefined;\n}\n\nfunction buildOperation(\n method: HttpMethod,\n path: string,\n op: OperationObject,\n pathLevelParams: ParameterObject[],\n operationIdTransform?: (id: string) => string,\n serviceName?: string,\n componentSchemas?: Record<string, SchemaObject>,\n): { operation: Operation; inlineModels: Model[] } {\n const allParams = [...pathLevelParams, ...(op.parameters ?? [])];\n\n const hasIdempotencyHeader = allParams.some((p) => p.in === 'header' && p.name.toLowerCase() === 'idempotency-key');\n\n // Use the service name as context so inline parameter enums get qualified\n // names. e.g., service \"SSO\" + param \"provider\" → \"SSOProvider\".\n const opContext = serviceName;\n const pathParams = extractParams(allParams, 'path', opContext, componentSchemas);\n const queryParams = extractParams(allParams, 'query', opContext, componentSchemas);\n const headerParams = extractParams(allParams, 'header', opContext, componentSchemas).filter(\n (p) => p.name.toLowerCase() !== 'idempotency-key',\n );\n const cookieParams = extractParams(allParams, 'cookie', opContext, componentSchemas);\n\n const reqBodyModels: Model[] = [];\n const { body: requestBody, encoding: requestBodyEncoding } = extractRequestBody(op.requestBody, op, reqBodyModels);\n const {\n response,\n successResponses,\n errors,\n inlineModels,\n isPaginated,\n dataPath: responseDataPath,\n itemType: responseItemType,\n } = extractResponses(op.responses, op, path, method);\n inlineModels.push(...reqBodyModels);\n\n // Build structured pagination metadata from response classification and query param detection\n const paginationFromParams = detectPagination(response, queryParams, responseDataPath);\n let pagination: PaginationMeta | undefined;\n if (isPaginated) {\n const itemType = responseItemType ?? (response.kind === 'array' ? response.items : response);\n pagination = {\n strategy: paginationFromParams?.strategy ?? 'cursor',\n param: paginationFromParams?.param ?? 'after',\n limitParam: paginationFromParams?.limitParam,\n dataPath: responseDataPath ?? paginationFromParams?.dataPath,\n itemType,\n };\n } else if (paginationFromParams) {\n pagination = paginationFromParams;\n }\n\n // Extract per-operation security overrides\n const security = extractOperationSecurity(op.security);\n\n // Extract mutually-exclusive parameter groups (query/path/header/cookie)\n const allIRParams = [...pathParams, ...queryParams, ...headerParams, ...cookieParams];\n const opLabel = op.operationId ?? `${method.toUpperCase()} ${path}`;\n const queryParamGroups = extractParameterGroups(op, allIRParams, opLabel);\n\n // Extract mutually-exclusive body parameter groups\n const bodyParamGroups = extractBodyParameterGroups(op, opLabel);\n\n // Merge both sources into a single parameterGroups array\n const parameterGroups =\n queryParamGroups || bodyParamGroups ? [...(queryParamGroups ?? []), ...(bodyParamGroups ?? [])] : undefined;\n\n return {\n operation: {\n name: inferOperationName(method, path, op.operationId, operationIdTransform),\n description: buildDescription(op.summary, op.description),\n httpMethod: method,\n path,\n pathParams,\n queryParams,\n headerParams,\n cookieParams: cookieParams.length > 0 ? cookieParams : undefined,\n requestBody,\n requestBodyEncoding,\n response,\n successResponses,\n errors,\n pagination,\n injectIdempotencyKey: hasIdempotencyHeader,\n deprecated: op.deprecated || undefined,\n async: op['x-oagen-async'],\n security,\n parameterGroups,\n },\n inlineModels,\n };\n}\n\n/**\n * Extract per-operation security requirements from an OpenAPI security directive.\n * Returns undefined when the operation uses the spec-level default security.\n *\n * OpenAPI security format: `security: [{ schemeName: [scope1, scope2] }]`\n */\nfunction extractOperationSecurity(\n security: Array<Record<string, string[]>> | undefined,\n): SecurityRequirement[] | undefined {\n if (!security || security.length === 0) return undefined;\n\n const requirements: SecurityRequirement[] = [];\n for (const entry of security) {\n for (const [schemeName, scopes] of Object.entries(entry)) {\n requirements.push({ schemeName, scopes: scopes ?? [] });\n }\n }\n return requirements.length > 0 ? requirements : undefined;\n}\n\nfunction buildDescription(summary: string | undefined, description: string | undefined): string | undefined {\n if (summary && description && summary !== description) {\n return `${summary}\\n\\n${description}`;\n }\n return description ?? summary;\n}\n\nfunction extractParams(\n params: ParameterObject[],\n location: 'path' | 'query' | 'header' | 'cookie',\n operationContext?: string,\n componentSchemas?: Record<string, SchemaObject>,\n): Parameter[] {\n return params\n .filter((p) => p.in === location)\n .map((p) => {\n const refTarget = resolveParamSchemaRef(p.schema, componentSchemas);\n return {\n name: p.name,\n type: p.schema\n ? schemaToTypeRef(p.schema, p.name, operationContext ? toPascalCase(operationContext) : undefined)\n : ({ kind: 'primitive', type: 'string' } as TypeRef),\n required: p.required ?? false,\n description: p.description,\n deprecated: p.deprecated || p.schema?.deprecated || refTarget?.deprecated || undefined,\n default: p.schema?.default ?? refTarget?.default,\n example: p.example ?? p.schema?.example ?? refTarget?.example,\n style: p.style as Parameter['style'],\n explode: p.explode,\n };\n });\n}\n\n/**\n * If a parameter's schema is a `$ref` to `#/components/schemas/X`, return the\n * referenced component schema. Used to surface schema-level metadata (default,\n * example, deprecated) that wouldn't otherwise be visible at the param level.\n *\n * Refs are not pre-resolved by the bundler (`dereference: false` in refs.ts),\n * so without this, a param like `schema: { $ref: '.../PaginationOrder' }`\n * silently loses the target's `default: desc` and the SDK stops emitting the\n * spec-mandated default value in generated method signatures.\n */\nfunction resolveParamSchemaRef(\n schema: SchemaObject | undefined,\n componentSchemas: Record<string, SchemaObject> | undefined,\n): SchemaObject | undefined {\n if (!schema || !componentSchemas) return undefined;\n const ref = (schema as { $ref?: string }).$ref;\n if (!ref) return undefined;\n const match = /^#\\/components\\/schemas\\/(.+)$/.exec(ref);\n if (!match) return undefined;\n return componentSchemas[match[1]];\n}\n\nfunction extractRequestBody(\n body: RequestBodyObject | undefined,\n op: OperationObject | undefined,\n inlineModels: Model[],\n): { body?: TypeRef; encoding?: 'json' | 'form-data' | 'form-urlencoded' | 'binary' | 'text' } {\n if (!body?.content) return {};\n\n // Detect encoding and find schema from content type in priority order\n let encoding: 'json' | 'form-data' | 'form-urlencoded' | 'binary' | 'text' = 'json';\n let schema: SchemaObject | undefined;\n\n if (body.content['application/json']?.schema) {\n encoding = 'json';\n schema = body.content['application/json']!.schema;\n } else if (body.content['multipart/form-data']?.schema) {\n encoding = 'form-data';\n schema = body.content['multipart/form-data']!.schema;\n } else if (body.content['application/x-www-form-urlencoded']?.schema) {\n encoding = 'form-urlencoded';\n schema = body.content['application/x-www-form-urlencoded']!.schema;\n } else if (body.content['application/octet-stream']) {\n encoding = 'binary';\n schema = body.content['application/octet-stream']!.schema;\n } else if (body.content['text/plain']) {\n encoding = 'text';\n schema = body.content['text/plain']!.schema;\n }\n\n if (!schema) {\n // For binary/text, a schema is optional — produce a primitive TypeRef\n if (encoding === 'binary') {\n return { body: { kind: 'primitive', type: 'string', format: 'binary' }, encoding };\n }\n if (encoding === 'text') {\n return { body: { kind: 'primitive', type: 'string' }, encoding };\n }\n return {};\n }\n\n const rawName = op?.operationId\n ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + 'Request'\n : 'RequestBody';\n const contextName = cleanSchemaName(rawName);\n\n // If the request body is an inline object with properties, extract it as a model\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, contextName, requiredSet));\n }\n inlineModels.push({ name: contextName, description: undefined, fields });\n return { body: { kind: 'model', name: contextName }, encoding };\n }\n\n // If the request body is a oneOf, extract each variant as an inline model\n // and build a union type pointing to them by name.\n if (schema.oneOf) {\n const variants: TypeRef[] = [];\n\n for (const variant of schema.oneOf) {\n if (variant.$ref) {\n const ref = schemaToTypeRef(variant, contextName);\n variants.push(ref);\n } else if (variant.type === 'null') {\n // skip null variant in union, handle separately\n } else if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const variantName = deriveOneOfVariantName(variant, contextName, inlineModels);\n const requiredSet = new Set(variant.required ?? []);\n const fields: Field[] = [];\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, variantName, requiredSet));\n }\n inlineModels.push({ name: variantName, description: variant.description, fields });\n variants.push({ kind: 'model', name: variantName });\n } else {\n variants.push(schemaToTypeRef(variant, contextName));\n }\n }\n\n const hasNull = schema.oneOf.some(\n (v: SchemaObject) => v.type === 'null' || (Array.isArray(v.type) && v.type.includes('null')),\n );\n const union: TypeRef = {\n kind: 'union',\n variants,\n ...(schema.discriminator\n ? {\n discriminator: { property: schema.discriminator.propertyName, mapping: schema.discriminator.mapping ?? {} },\n }\n : {}),\n };\n const body = hasNull ? ({ kind: 'nullable', inner: union } as TypeRef) : union;\n return { body, encoding };\n }\n\n return { body: schemaToTypeRef(schema, contextName), encoding };\n}\n\n/** Derive a unique variant name for a oneOf inline model. */\nfunction deriveOneOfVariantName(variant: SchemaObject, baseName: string, existingModels: Model[]): string {\n // Try to use a distinguishing property (e.g., \"grant_type\" field's const/enum value)\n if (variant.properties) {\n for (const [, propSchema] of Object.entries(variant.properties)) {\n if (propSchema?.const && typeof propSchema.const === 'string') {\n return toPascalCase(propSchema.const) + baseName.replace(/Request$/, '') + 'Request';\n }\n }\n }\n // Fallback: append a numeric suffix\n const existingNames = new Set(existingModels.map((m) => m.name));\n let name = baseName;\n let suffix = 2;\n while (existingNames.has(name)) {\n name = `${baseName}${suffix}`;\n suffix++;\n }\n return name;\n}\n\nfunction deriveResponseName(op: OperationObject | undefined, path: string, method: HttpMethod): string {\n if (op?.operationId) {\n return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + 'Response');\n }\n const segments = path.split('/').filter(Boolean);\n const resource = segments[0] ?? 'Unknown';\n return toPascalCase(resource) + toPascalCase(method) + 'Response';\n}\n\nfunction extractResponses(\n responses?: Record<string, ResponseObject>,\n op?: OperationObject,\n path?: string,\n method?: HttpMethod,\n): {\n response: TypeRef;\n successResponses?: SuccessResponse[];\n errors: ErrorResponse[];\n inlineModels: Model[];\n isPaginated: boolean;\n dataPath?: string;\n itemType?: TypeRef;\n} {\n const errors: ErrorResponse[] = [];\n let response: TypeRef = { kind: 'primitive', type: 'string' };\n let inlineModels: Model[] = [];\n let isPaginated = false;\n let dataPath: string | undefined;\n let itemType: TypeRef | undefined;\n\n if (!responses) return { response, errors, inlineModels, isPaginated };\n\n const allSuccessResponses: SuccessResponse[] = [];\n\n for (const [statusCode, resp] of Object.entries(responses)) {\n const code = parseInt(statusCode, 10);\n\n if (code >= 200 && code < 300) {\n let extractedType: TypeRef = { kind: 'primitive', type: 'unknown' };\n const jsonContent = resp.content?.['application/json'];\n if (jsonContent?.schema) {\n const contextName = deriveResponseName(op, path ?? '/', method ?? 'get');\n const result = classifyAndExtractResponse(jsonContent.schema, contextName);\n extractedType = result.response;\n // Keep track of inline models and pagination from the latest 2xx with a schema\n inlineModels = result.inlineModels;\n isPaginated = result.isPaginated;\n dataPath = result.dataPath;\n itemType = result.itemType;\n } else if (resp.content) {\n // Handle non-JSON response content types (text/plain, binary, XML, etc.)\n if (resp.content['application/octet-stream'] || resp.content['application/pdf']) {\n extractedType = { kind: 'primitive', type: 'string', format: 'binary' };\n } else if (\n resp.content['text/plain'] ||\n resp.content['text/html'] ||\n resp.content['text/xml'] ||\n resp.content['application/xml']\n ) {\n extractedType = { kind: 'primitive', type: 'string' };\n } else {\n // Try the first available content type's schema\n const firstKey = Object.keys(resp.content)[0];\n if (firstKey) {\n const firstContent = resp.content[firstKey];\n if (firstContent?.schema) {\n extractedType = schemaToTypeRef(\n firstContent.schema,\n deriveResponseName(op, path ?? '/', method ?? 'get'),\n );\n }\n }\n }\n }\n allSuccessResponses.push({ statusCode: code, type: extractedType });\n } else if (code >= 300 && code < 400) {\n // 3xx redirects — include so emitter can detect redirect endpoints\n allSuccessResponses.push({ statusCode: code, type: { kind: 'primitive', type: 'unknown' } });\n } else if (code >= 400) {\n const jsonContent = resp.content?.['application/json'];\n const type = jsonContent?.schema ? schemaToTypeRef(jsonContent.schema, `Error${code}`) : undefined;\n errors.push({ statusCode: code, type });\n }\n }\n\n // Primary response = lowest 2xx with a body schema, falling back to first 2xx\n if (allSuccessResponses.length > 0) {\n const sorted = [...allSuccessResponses].sort((a, b) => a.statusCode - b.statusCode);\n const primary =\n sorted.find((r) => r.type.kind !== 'primitive' || (r.type as { type: string }).type !== 'unknown') ?? sorted[0];\n response = primary.type;\n }\n\n const successResponses = allSuccessResponses.length > 1 ? allSuccessResponses : undefined;\n\n return { response, successResponses, errors, inlineModels, isPaginated, dataPath, itemType };\n}\n","import type { Model, Service, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\n\nfunction keepLargestByName(models: Model[]): Model[] {\n const byName = new Map<string, Model>();\n for (const model of models) {\n const existing = byName.get(model.name);\n if (!existing || model.fields.length > existing.fields.length) {\n byName.set(model.name, model);\n }\n }\n return [...byName.values()];\n}\n\nfunction rewriteModelRef(ref: TypeRef, oldName: string, newName: string): void {\n walkTypeRef(ref, {\n model: (r) => {\n if (r.name === oldName) (r as { name: string }).name = newName;\n },\n });\n}\n\nfunction rewriteModelRefs(models: Model[], services: Service[], oldName: string, newName: string): void {\n for (const model of models) {\n for (const field of model.fields) {\n rewriteModelRef(field.type, oldName, newName);\n }\n }\n for (const service of services) {\n for (const op of service.operations) {\n rewriteModelRef(op.response, oldName, newName);\n if (op.requestBody) {\n rewriteModelRef(op.requestBody, oldName, newName);\n }\n }\n }\n}\n\nexport function mergeInlineResponseModels(schemaModels: Model[], inlineModels: Model[]): Model[] {\n const mergedSchemaModels = [...schemaModels];\n const schemaModelNames = new Set(mergedSchemaModels.map((m) => m.name));\n const schemaModelsByName = new Map(mergedSchemaModels.map((m) => [m.name, m]));\n\n const deduplicatedInlineModels = inlineModels.filter((model) => {\n if (!schemaModelNames.has(model.name)) return true;\n\n const existing = schemaModelsByName.get(model.name)!;\n const existingFieldNames = new Set(existing.fields.map((f) => f.name));\n const inlineFieldNames = new Set(model.fields.map((f) => f.name));\n const hasDifference =\n model.fields.some((f) => !existingFieldNames.has(f.name)) ||\n existing.fields.some((f) => !inlineFieldNames.has(f.name));\n\n if (hasDifference && model.fields.length > existing.fields.length) {\n const idx = mergedSchemaModels.indexOf(existing);\n if (idx !== -1) mergedSchemaModels[idx] = model;\n schemaModelsByName.set(model.name, model);\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has more fields than component schema (${model.fields.length} vs ${existing.fields.length}) — using inline response model`,\n );\n } else if (hasDifference) {\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has different fields than component schema — using component schema`,\n );\n }\n\n return false;\n });\n\n return [...mergedSchemaModels, ...keepLargestByName(deduplicatedInlineModels)];\n}\n\nexport function mergeFieldInlineModels(existingModels: Model[], fieldInlineModels: Model[]): Model[] {\n const modelNames = new Set(existingModels.map((m) => m.name));\n const modelsByName = new Map(existingModels.map((m) => [m.name, m]));\n\n const deduplicatedFieldModels = fieldInlineModels.filter((model) => {\n if (!modelNames.has(model.name)) return true;\n\n const existing = modelsByName.get(model.name)!;\n const existingFieldNames = new Set(existing.fields.map((f) => f.name));\n const inlineFieldNames = new Set(model.fields.map((f) => f.name));\n const hasDifference =\n model.fields.some((f) => !existingFieldNames.has(f.name)) ||\n existing.fields.some((f) => !inlineFieldNames.has(f.name));\n\n if (hasDifference) {\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has different fields than component schema — using component schema`,\n );\n }\n\n return false;\n });\n\n return [...existingModels, ...keepLargestByName(deduplicatedFieldModels)];\n}\n\nfunction hasModelConstDiscriminant(model: Model): boolean {\n return model.fields.some(\n (f) => (f.name === 'object' || f.name === 'type') && f.type.kind === 'literal' && typeof f.type.value === 'string',\n );\n}\n\nfunction isModelReferencedByOthers(name: string, models: Model[], excludeNames: Set<string>): boolean {\n for (const model of models) {\n if (excludeNames.has(model.name)) continue;\n for (const field of model.fields) {\n let found = false;\n walkTypeRef(field.type, {\n model: (r) => {\n if (r.name === name) found = true;\n },\n });\n if (found) return true;\n }\n }\n return false;\n}\n\nexport function collapseJsonSuffixModels(models: Model[], services: Service[]): Model[] {\n const normalizedModels = [...models];\n const byName = new Map(normalizedModels.map((m) => [m.name, m]));\n\n // Pass 1: collect merge candidates\n const mergeCandidates: Array<{ jsonModel: Model; baseModel: Model }> = [];\n for (const model of normalizedModels) {\n if (!model.name.endsWith('Json')) continue;\n\n const baseName = model.name.slice(0, -4);\n const baseModel = byName.get(baseName);\n if (!baseModel || model.fields.length <= baseModel.fields.length) continue;\n\n const isSuperset = baseModel.fields.every((f) => model.fields.some((mf) => mf.name === f.name));\n if (!isSuperset) continue;\n\n // Guard: both models have a const discriminant — they are distinct entities\n if (hasModelConstDiscriminant(model) && hasModelConstDiscriminant(baseModel)) continue;\n\n // Guard: a third model explicitly references the Json-suffix model\n if (isModelReferencedByOthers(model.name, normalizedModels, new Set([model.name, baseName]))) continue;\n\n mergeCandidates.push({ jsonModel: model, baseModel });\n }\n\n // Pass 2: apply merges\n const toRemove = new Set<string>();\n for (const { jsonModel, baseModel } of mergeCandidates) {\n baseModel.fields = jsonModel.fields;\n toRemove.add(jsonModel.name);\n rewriteModelRefs(normalizedModels, services, jsonModel.name, baseModel.name);\n console.warn(\n `[oagen] Merged \"${jsonModel.name}\" into \"${baseModel.name}\" (${jsonModel.fields.length} fields, superset)`,\n );\n }\n\n // Pass 3: cascade renames to inline children of collapsed Json-suffix models.\n // e.g. when AuditLogSchemaJson → AuditLogSchema, also rename\n // AuditLogSchemaJsonTarget → AuditLogSchemaTarget.\n for (const { jsonModel, baseModel } of mergeCandidates) {\n const jsonPrefix = jsonModel.name;\n const basePrefix = baseModel.name;\n\n for (const model of normalizedModels) {\n if (toRemove.has(model.name)) continue;\n if (model.name.length <= jsonPrefix.length) continue;\n if (!model.name.startsWith(jsonPrefix)) continue;\n\n const newName = basePrefix + model.name.slice(jsonPrefix.length);\n const existing = byName.get(newName);\n\n if (existing && !toRemove.has(existing.name)) {\n toRemove.add(model.name);\n rewriteModelRefs(normalizedModels, services, model.name, newName);\n console.warn(`[oagen] Collapsed child \"${model.name}\" into existing \"${newName}\"`);\n } else {\n rewriteModelRefs(normalizedModels, services, model.name, newName);\n model.name = newName;\n byName.set(newName, model);\n console.warn(`[oagen] Renamed child \"${jsonPrefix}…\" → \"${newName}\"`);\n }\n }\n }\n\n return normalizedModels.filter((m) => !toRemove.has(m.name));\n}\n","import type { Enum, Model, Service } from '../ir/types.js';\nimport { collectInlineEnumFromRef } from './schemas.js';\n\nexport function collectInlineEnumsFromModels(models: Model[], enums: Enum[]): void {\n const enumNames = new Set(enums.map((e) => e.name));\n for (const model of models) {\n for (const field of model.fields) {\n collectInlineEnumFromRef(field.type, enums, enumNames);\n }\n }\n}\n\n/**\n * Collect inline enum definitions from operation parameters (query, path, header)\n * and promote them to top-level enums so emitters can generate typed enum files.\n */\nexport function collectInlineEnumsFromOperations(services: Service[], enums: Enum[]): void {\n const enumNames = new Set(enums.map((e) => e.name));\n for (const service of services) {\n for (const op of service.operations) {\n for (const param of [...op.pathParams, ...op.queryParams, ...op.headerParams, ...(op.cookieParams ?? [])]) {\n collectInlineEnumFromRef(param.type, enums, enumNames);\n }\n }\n }\n}\n","import type { ApiSpec, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\n\nexport function validateModelRefs(spec: ApiSpec): void {\n const knownNames = new Set<string>();\n for (const m of spec.models) knownNames.add(m.name);\n for (const e of spec.enums) knownNames.add(e.name);\n\n function walkRef(ref: TypeRef, context: string): void {\n walkTypeRef(ref, {\n model: (r) => {\n if (!knownNames.has(r.name)) {\n console.warn(`[oagen] Warning: Unresolved model reference \"${r.name}\" (context: ${context})`);\n }\n },\n });\n }\n\n for (const model of spec.models) {\n for (const field of model.fields) {\n walkRef(field.type, `${model.name}.${field.name}`);\n }\n }\n\n for (const service of spec.services) {\n for (const op of service.operations) {\n for (const p of [...op.pathParams, ...op.queryParams, ...op.headerParams]) {\n walkRef(p.type, `${service.name}.${op.name}.${p.name}`);\n }\n if (op.requestBody) walkRef(op.requestBody, `${service.name}.${op.name}.requestBody`);\n walkRef(op.response, `${service.name}.${op.name}.response`);\n }\n }\n}\n","import type { ApiSpec, AuthScheme, ServerEntry } from '../ir/types.js';\nimport { defaultSdkBehavior } from '../ir/sdk-behavior.js';\nimport { SpecParseError } from '../errors.js';\nimport { loadAndBundleSpec } from './refs.js';\nimport { extractSchemas, extractInlineModelsFromSchemas, clearSchemaNameTransform } from './schemas.js';\nimport { extractOperations } from './operations.js';\nimport {\n mergeInlineResponseModels,\n collapseJsonSuffixModels,\n mergeFieldInlineModels,\n} from './normalize-inline-models.js';\nimport { collectInlineEnumsFromModels, collectInlineEnumsFromOperations } from './collect-inline-enums.js';\nimport { validateModelRefs } from './normalize-model-refs.js';\n\n/**\n * A bundled OpenAPI document, post-`$ref` resolution but pre-IR extraction.\n *\n * This is the shape the spec author wrote, with external refs inlined and\n * internal refs left intact. It is intentionally loose (`Record<string,\n * unknown>`) so `transformSpec` can reach arbitrary spec extensions without\n * fighting types — narrow with `as` at use sites.\n */\nexport type OpenApiDocument = Record<string, unknown>;\n\nexport interface ParseOptions {\n operationIdTransform?: (id: string) => string;\n schemaNameTransform?: (name: string) => string;\n /**\n * Pre-IR overlay applied to the bundled OpenAPI document before any IR\n * extraction runs. Use this when the upstream spec can't be changed but you\n * need to patch around a spec quirk that would otherwise emit a breaking SDK\n * change — e.g. rewriting a path's response `$ref` back to its prior schema,\n * merging the new fields onto the prior schema, and dropping the fork.\n *\n * The function may mutate the document in place and return it, or return a\n * new object; the returned value is what the rest of oagen sees.\n *\n * Runs once, after `$ref` bundling and before schema/operation extraction.\n * If you need to inspect the resulting IR instead, post-process the\n * `ApiSpec` returned by `parseSpec`.\n */\n transformSpec?: (spec: OpenApiDocument) => OpenApiDocument;\n}\n\nexport async function parseSpec(specPath: string, options?: ParseOptions): Promise<ApiSpec> {\n const { parsed } = await loadAndBundleSpec(specPath);\n const transformed = options?.transformSpec ? options.transformSpec(parsed) : parsed;\n\n const spec = transformed as {\n openapi?: string;\n info?: { title?: string; version?: string; description?: string };\n servers?: Array<{ url?: string; description?: string }>;\n paths?: Record<string, unknown>;\n components?: {\n schemas?: Record<string, unknown>;\n securitySchemes?: Record<\n string,\n { type: string; scheme?: string; in?: string; name?: string; flows?: Record<string, unknown> }\n >;\n };\n };\n\n // Validate OpenAPI version\n const version = spec.openapi ?? '';\n if (!version.startsWith('3.')) {\n throw new SpecParseError(\n `Unsupported OpenAPI version: ${version}. oagen requires OpenAPI 3.x`,\n `Update the spec to OpenAPI 3.0 or 3.1. If you are using Swagger 2.x, convert it first with \\`npx swagger2openapi ${specPath}\\`.`,\n );\n }\n\n const { models, enums } = extractSchemas(\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n { schemaNameTransform: options?.schemaNameTransform },\n );\n\n const { services, inlineModels } = extractOperations(\n spec.paths as Record<string, Record<string, unknown>> | undefined,\n options?.operationIdTransform,\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n );\n\n const responseNormalizedModels = mergeInlineResponseModels(models, inlineModels);\n\n // Extract inline models from model field definitions (objects/arrays with properties).\n // schemaNameTransform is kept active so inline child names use the\n // transformed parent name (e.g. AuditLogSchemaJson→AuditLogSchema yields\n // AuditLogSchemaTarget, not AuditLogSchemaJsonTarget).\n const fieldInlineModels = extractInlineModelsFromSchemas(\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n );\n clearSchemaNameTransform();\n const fieldMergedModels = mergeFieldInlineModels(responseNormalizedModels, fieldInlineModels);\n const finalModels = collapseJsonSuffixModels(fieldMergedModels, services);\n collectInlineEnumsFromModels(finalModels, enums);\n collectInlineEnumsFromOperations(services, enums);\n\n const auth = extractAuthSchemes(spec.components?.securitySchemes);\n\n const serverEntries: ServerEntry[] = (spec.servers ?? [])\n .map((s) => ({ url: s.url ?? '', description: s.description }))\n .filter((s) => s.url);\n\n const result: ApiSpec = {\n name: spec.info?.title ?? 'Unknown API',\n version: spec.info?.version ?? '0.0.0',\n description: spec.info?.description,\n baseUrl: serverEntries[0]?.url ?? '',\n servers: serverEntries.length > 0 ? serverEntries : undefined,\n services,\n models: finalModels,\n enums,\n auth,\n sdk: defaultSdkBehavior(),\n };\n\n validateModelRefs(result);\n\n return result;\n}\n/** Extract authentication schemes from OpenAPI securitySchemes. */\nfunction extractAuthSchemes(\n securitySchemes?: Record<\n string,\n { type: string; scheme?: string; in?: string; name?: string; flows?: Record<string, unknown> }\n >,\n): AuthScheme[] | undefined {\n if (!securitySchemes) return undefined;\n const schemes: AuthScheme[] = [];\n for (const [, scheme] of Object.entries(securitySchemes)) {\n if (scheme.type === 'http' && scheme.scheme === 'bearer') {\n schemes.push({ kind: 'bearer' });\n } else if (scheme.type === 'apiKey' && scheme.in && scheme.name) {\n schemes.push({ kind: 'apiKey', in: scheme.in as 'header' | 'query' | 'cookie', name: scheme.name });\n } else if (scheme.type === 'oauth2' && scheme.flows) {\n schemes.push({ kind: 'oauth2', flows: scheme.flows });\n }\n }\n return schemes.length > 0 ? schemes : undefined;\n}\n","import type { Operation, TypeRef } from '../ir/types.js';\nimport { assertNever } from '../ir/types.js';\n\nexport interface OperationPlan {\n operation: Operation;\n isDelete: boolean;\n hasBody: boolean;\n isIdempotentPost: boolean;\n pathParamsInOptions: boolean;\n isPaginated: boolean;\n responseModelName: string | null;\n /** For paginated operations, the model name of individual list items\n * (unwrapped from the list wrapper). Null for non-paginated. */\n paginatedItemModelName: string | null;\n isModelResponse: boolean;\n /** True when the response is an unpaginated `type: array` of models.\n * Emitters should use this to return `Model[]` (or the language's list\n * equivalent) and map the deserializer over each element. */\n isArrayResponse: boolean;\n hasQueryParams: boolean;\n isAsync: boolean;\n}\n\nexport function planOperation(op: Operation): OperationPlan {\n const isDelete = op.httpMethod === 'delete';\n const hasBody = !!op.requestBody;\n const isIdempotentPost = op.injectIdempotencyKey && op.httpMethod === 'post';\n const hasQueryParams = op.queryParams.length > 0;\n const pathParamsInOptions = op.pathParams.length > 1 || (op.pathParams.length > 0 && (hasBody || hasQueryParams));\n const isPaginated = op.pagination !== undefined;\n const responseModelName = resolveResponseModelName(op);\n const paginatedItemModelName =\n isPaginated && op.pagination?.itemType.kind === 'model' ? op.pagination.itemType.name : null;\n const isModelResponse = responseModelName !== null;\n // Unpaginated `type: array` of models — needs `Model[]` return + elementwise\n // deserialization. Paginated operations use the pagination wrapper instead.\n const isArrayResponse = !isPaginated && op.response.kind === 'array' && op.response.items.kind === 'model';\n const isAsync = op.async ?? true;\n\n return {\n operation: op,\n isDelete,\n hasBody,\n isIdempotentPost,\n pathParamsInOptions,\n isPaginated,\n responseModelName,\n paginatedItemModelName,\n isModelResponse,\n isArrayResponse,\n hasQueryParams,\n isAsync,\n };\n}\n\nexport function resolveResponseModelName(op: Operation): string | null {\n if (op.httpMethod === 'delete') return null;\n return extractModelName(op.response);\n}\n\nfunction extractModelName(ref: TypeRef): string | null {\n switch (ref.kind) {\n case 'model':\n return ref.name;\n case 'array':\n return ref.items.kind === 'model' ? ref.items.name : null;\n case 'nullable':\n return extractModelName(ref.inner);\n case 'union': {\n const firstModel = ref.variants.find((v) => v.kind === 'model');\n return firstModel && firstModel.kind === 'model' ? firstModel.name : null;\n }\n case 'map':\n case 'enum':\n case 'primitive':\n case 'literal':\n return null;\n default:\n return assertNever(ref);\n }\n}\n","import type { ApiSpec, Enum, Field, Model, TypeRef } from '../ir/types.js';\n\n/**\n * Builds illustrative example values for IR types. Used by snippet emitters\n * to produce realistic argument values in call-site samples.\n *\n * Values prefer, in order:\n * 1. An explicit `example` carried on the field/param.\n * 2. The `default` from the schema.\n * 3. The first enum value, when the type is an enum.\n * 4. A type-driven default (e.g. `\"string_example\"`, `1`, `true`).\n *\n * Recursion through models/arrays/maps is depth-limited; cyclic models\n * collapse to a placeholder object rather than blowing the stack.\n */\nexport interface ExampleBuilder {\n /** Build an example value for a single type reference (no field metadata). */\n forType(type: TypeRef): unknown;\n /** Build an example value for a field, honoring its `example`/`default`. */\n forField(field: Field): unknown;\n /** Build an example object from a model, keyed by field wire name. */\n forModel(model: Model | string): Record<string, unknown>;\n}\n\nconst MAX_DEPTH = 6;\n\nexport function createExampleBuilder(spec: ApiSpec): ExampleBuilder {\n const modelsByName = new Map<string, Model>();\n for (const m of spec.models) modelsByName.set(m.name, m);\n const enumsByName = new Map<string, Enum>();\n for (const e of spec.enums) enumsByName.set(e.name, e);\n\n function buildForType(type: TypeRef, depth: number): unknown {\n if (depth > MAX_DEPTH) return null;\n\n switch (type.kind) {\n case 'primitive':\n return primitiveExample(type.type, type.format);\n case 'literal':\n return type.value;\n case 'enum': {\n if (type.values && type.values.length > 0) return type.values[0];\n const e = enumsByName.get(type.name);\n return e?.values[0]?.value ?? null;\n }\n case 'array':\n return [buildForType(type.items, depth + 1)];\n case 'nullable':\n return buildForType(type.inner, depth);\n case 'union': {\n const first = type.variants[0];\n return first ? buildForType(first, depth) : null;\n }\n case 'map': {\n const key = 'key';\n const value = buildForType(type.valueType, depth + 1);\n return { [key]: value };\n }\n case 'model':\n return buildForModel(type.name, depth + 1);\n default:\n return null;\n }\n }\n\n function buildForModel(nameOrModel: string | Model, depth: number): Record<string, unknown> {\n if (depth > MAX_DEPTH) return {};\n const model = typeof nameOrModel === 'string' ? modelsByName.get(nameOrModel) : nameOrModel;\n if (!model) return {};\n\n const result: Record<string, unknown> = {};\n for (const field of model.fields) {\n if (field.deprecated || field.readOnly) continue;\n result[field.name] = buildForField(field, depth);\n }\n return result;\n }\n\n function buildForField(field: Field, depth: number): unknown {\n if (field.example !== undefined) return field.example;\n if (field.default !== undefined) return field.default;\n return buildForType(field.type, depth);\n }\n\n return {\n forType: (type) => buildForType(type, 0),\n forField: (field) => buildForField(field, 0),\n forModel: (model) => buildForModel(model, 0),\n };\n}\n\nfunction primitiveExample(type: string, format?: string): unknown {\n switch (type) {\n case 'string':\n if (format === 'date-time') return '2026-01-15T12:00:00.000Z';\n if (format === 'date') return '2026-01-15';\n if (format === 'email') return 'user@example.com';\n if (format === 'uri' || format === 'url') return 'https://example.com';\n if (format === 'uuid') return '00000000-0000-0000-0000-000000000000';\n return 'string_example';\n case 'integer':\n case 'number':\n return 1;\n case 'boolean':\n return true;\n case 'unknown':\n default:\n return null;\n }\n}\n","import type { GeneratedFile, EmitterContext } from '../engine/types.js';\nimport type { ResolvedOperation } from '../ir/operation-hints.js';\nimport { createExampleBuilder } from './example-builder.js';\nimport type { SnippetEmitter, SnippetResult } from './types.js';\n\n/**\n * Run one or more snippet emitters over every resolved operation in the spec.\n *\n * Iteration order matches `ctx.resolvedOperations`. For each operation the\n * runner asks every emitter to render once; emitters that return `null`\n * contribute nothing for that op (the URL-builder / unsupported case).\n *\n * Returns a flat list of {@link SnippetResult}. Consumers map these to\n * file paths according to their own layout — see\n * {@link snippetResultsToFiles} for a convenience that writes\n * `<outputDir>/<language>/<methodName>-request.<ext>`.\n */\nexport function runSnippetEmitters(emitters: SnippetEmitter[], ctx: EmitterContext): SnippetResult[] {\n const resolved = ctx.resolvedOperations;\n if (!resolved || resolved.length === 0) return [];\n\n const examples = createExampleBuilder(ctx.spec);\n const results: SnippetResult[] = [];\n\n for (const op of resolved) {\n for (const emitter of emitters) {\n const content = emitter.renderOperation(op, ctx, examples);\n if (content === null) continue;\n results.push({\n language: emitter.language,\n fileExtension: emitter.fileExtension,\n operationId: operationIdFor(op),\n mountTarget: op.mountOn,\n methodName: op.methodName,\n content: ensureTrailingNewline(content),\n });\n }\n }\n\n return results;\n}\n\n/**\n * Convenience: turn snippet results into oagen-style {@link GeneratedFile}s\n * under `<outputDir>/<language>/<methodName>-request.<extension>`.\n *\n * Useful for consumers wired into the standard oagen file-writing pipeline.\n * Docs builds that already have their own per-tag file layout (e.g.\n * `content/reference/{tag}/_code/...`) typically skip this helper and route\n * `SnippetResult.operationId` / `mountTarget` through their own mapping.\n */\nexport function snippetResultsToFiles(results: SnippetResult[], outputDir = 'snippets'): GeneratedFile[] {\n return results.map((r) => ({\n path: `${outputDir}/${r.language}/${r.methodName}-request.${r.fileExtension}`,\n content: r.content,\n overwriteExisting: true,\n integrateTarget: false,\n }));\n}\n\nfunction operationIdFor(op: ResolvedOperation): string {\n return `${op.mountOn}.${op.methodName}`;\n}\n\nfunction ensureTrailingNewline(s: string): string {\n return s.endsWith('\\n') ? s : `${s}\\n`;\n}\n","import type { EmitterContext } from '../engine/types.js';\nimport type { ResolvedOperation, ResolvedWrapper } from '../ir/operation-hints.js';\nimport type { Field, Model, Parameter } from '../ir/types.js';\nimport { toSnakeCase } from '../utils/naming.js';\nimport type { ExampleBuilder } from './example-builder.js';\n\n/**\n * One argument resolved for a call-site snippet. The {@link wireName} stays\n * in the spec's casing so each language emitter can apply its own\n * field/param casing rules (snake_case for Python/Ruby/PHP, PascalCase for\n * Go/.NET, etc.).\n *\n * Path and query params carry their {@link Parameter} so emitters can pick\n * language-specific safe names; body args carry their {@link Field} so\n * emitters can read field-level metadata (deprecated, type details).\n */\nexport interface SnippetArg {\n /** 'path' | 'body' | 'query' — used by emitters to pick a casing rule. */\n source: 'path' | 'body' | 'query';\n /** Spec wire name (e.g. `domain_data`, `client_id`). */\n wireName: string;\n /** Pre-computed illustrative value (string, number, array, object, ...). */\n value: unknown;\n /** Original parameter for path/query args, null for body fields. */\n parameter: Parameter | null;\n /** Original field for body args, null for path/query params. */\n field: Field | null;\n}\n\n/**\n * Resolve the set of required arguments for a snippet. Body fields are\n * expanded from the request body model; defaults / inferFromClient fields\n * are filtered out (they're injected by the SDK, not the caller).\n *\n * Iteration order: path params, then required body fields, then required\n * query params. Wire-name collisions between body and path are reported in\n * {@link collisionNames} so the emitter can rename whichever side it\n * prefers (e.g. prefix body field with `body_`).\n */\nexport interface CollectedArgs {\n args: SnippetArg[];\n /** Body field wire names that also appear as path params. */\n collisionNames: Set<string>;\n}\n\nexport function collectSnippetArgs(\n resolved: ResolvedOperation,\n ctx: EmitterContext,\n examples: ExampleBuilder,\n): CollectedArgs {\n const op = resolved.operation;\n const hidden = hiddenParamSet(resolved);\n const args: SnippetArg[] = [];\n const pathWireNames = new Set<string>();\n\n for (const p of op.pathParams) {\n if (!p.required) continue;\n if (hidden.has(p.name)) continue;\n pathWireNames.add(p.name);\n args.push({\n source: 'path',\n wireName: p.name,\n value: exampleForParam(p, examples),\n parameter: p,\n field: null,\n });\n }\n\n const collisionNames = new Set<string>();\n if (op.requestBody?.kind === 'model') {\n const bodyModel = findModel(ctx, op.requestBody.name);\n if (bodyModel) {\n for (const f of bodyModel.fields) {\n if (!f.required || f.deprecated) continue;\n if (hidden.has(f.name)) continue;\n if (pathWireNames.has(f.name)) collisionNames.add(f.name);\n args.push({\n source: 'body',\n wireName: f.name,\n value: exampleForField(f, examples),\n parameter: null,\n field: f,\n });\n }\n }\n }\n\n for (const q of op.queryParams) {\n if (!q.required) continue;\n if (hidden.has(q.name)) continue;\n args.push({\n source: 'query',\n wireName: q.name,\n value: exampleForParam(q, examples),\n parameter: q,\n field: null,\n });\n }\n\n return { args, collisionNames };\n}\n\n/**\n * Build the arg list for a single split (wrapper) variant. The wrapper's\n * `exposedParams` is the contract; fields are looked up on the variant model\n * by exact name and then snake-case-normalized name. Optional status comes\n * from `wrapper.optionalParams` first, then from the field's `required` flag.\n */\nexport function collectWrapperArgs(\n wrapper: ResolvedWrapper,\n ctx: EmitterContext,\n examples: ExampleBuilder,\n): SnippetArg[] {\n const variantModel = ctx.spec.models.find((m) => m.name === wrapper.targetVariant);\n const variantFields = variantModel?.fields ?? [];\n const optionalSet = new Set(wrapper.optionalParams);\n const args: SnippetArg[] = [];\n\n for (const paramName of wrapper.exposedParams) {\n const field =\n variantFields.find((f) => f.name === paramName || toSnakeCase(f.name) === toSnakeCase(paramName)) ?? null;\n const isOptional = optionalSet.has(paramName) ? true : field ? !field.required : false;\n if (isOptional) continue;\n args.push({\n source: 'body',\n wireName: paramName,\n value: field ? examples.forField(field) : 'string_example',\n parameter: null,\n field,\n });\n }\n\n return args;\n}\n\nexport function hiddenParamSet(resolved: ResolvedOperation): Set<string> {\n const hidden = new Set<string>();\n for (const k of Object.keys(resolved.defaults)) hidden.add(k);\n for (const k of resolved.inferFromClient) hidden.add(k);\n return hidden;\n}\n\nfunction findModel(ctx: EmitterContext, name: string): Model | undefined {\n return ctx.spec.models.find((m) => m.name === name);\n}\n\nfunction exampleForParam(p: Parameter, examples: ExampleBuilder): unknown {\n if (p.example !== undefined) return p.example;\n if (p.default !== undefined) return p.default;\n return examples.forType(p.type);\n}\n\nfunction exampleForField(f: Field, examples: ExampleBuilder): unknown {\n return examples.forField(f);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuLA,SAAgB,qBAAkC;AAChD,QAAO;EACL,OAAO;GACL,sBAAsB;IAAC;IAAK;IAAK;IAAK;IAAK;IAAI;GAC/C,YAAY;GACZ,wBAAwB;GACxB,gBAAgB;GAChB,SAAS;IACP,cAAc;IACd,YAAY;IACZ,UAAU;IACV,cAAc;IACf;GACF;EACD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C,MAAM,WAAW,MACjE;AAChB,OAAK,KAAK;GACR,QAAQ;GACR,UAAU;GACV,OAAO,QAAQ,SAAS,SAAS,MAAM,GAAG;GAC1C,WAAW;GACX;GACD,CAAC;;AAGJ,QAAO;;AAGT,SAAgB,eAAe,UAA0C;CACvE,MAAM,yBAAS,IAAI,KAAa;AAChC,MAAK,MAAM,KAAK,OAAO,KAAK,SAAS,SAAS,CAAE,QAAO,IAAI,EAAE;AAC7D,MAAK,MAAM,KAAK,SAAS,gBAAiB,QAAO,IAAI,EAAE;AACvD,QAAO;;AAGT,SAAS,UAAU,KAAqB,MAAiC;AACvE,QAAO,IAAI,KAAK,OAAO,MAAM,MAAM,EAAE,SAAS,KAAK;;AAGrD,SAAS,gBAAgB,GAAc,UAAmC;AACxE,KAAI,EAAE,YAAY,KAAA,EAAW,QAAO,EAAE;AACtC,KAAI,EAAE,YAAY,KAAA,EAAW,QAAO,EAAE;AACtC,QAAO,SAAS,QAAQ,EAAE,KAAK;;AAGjC,SAAS,gBAAgB,GAAU,UAAmC;AACpE,QAAO,SAAS,SAAS,EAAE"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/ir/sdk-behavior.ts","../src/parser/refs.ts","../src/parser/inline-models.ts","../src/parser/schemas.ts","../src/parser/pagination.ts","../src/parser/responses.ts","../src/parser/operations.ts","../src/parser/normalize-inline-models.ts","../src/parser/collect-inline-enums.ts","../src/parser/normalize-model-refs.ts","../src/parser/parse.ts","../src/engine/operation-plan.ts","../src/snippets/example-builder.ts","../src/snippets/runner.ts","../src/snippets/shared.ts"],"sourcesContent":["/**\n * SDK Behavior IR — language-agnostic runtime policies for generated SDKs.\n *\n * These types capture the \"what\" of SDK behavior (retry, telemetry, errors, etc.)\n * while emitters provide the \"how\" (language-specific mechanism).\n *\n * Emitters access these via `ctx.spec.sdk` — always populated, never undefined.\n */\n\n// ── Retry ──────────────────────────────────────────────────────────\n\n/** Retry policy — when and how to retry failed requests. */\nexport interface RetryPolicy {\n /** HTTP status codes that trigger a retry. */\n retryableStatusCodes: number[];\n /** Maximum number of retry attempts (0 = no retries). */\n maxRetries: number;\n /** Whether to retry on connection errors (DNS failure, TCP reset). */\n retryOnConnectionError: boolean;\n /** Whether to retry on timeout errors. */\n retryOnTimeout: boolean;\n /** Backoff strategy between retries. */\n backoff: BackoffStrategy;\n}\n\n/** Exponential backoff configuration.\n *\n * Formula: `delay = min(initialDelay * multiplier^attempt, maxDelay)`\n * With jitter: `delay += delay * jitterFactor * random(0, 1)`\n */\nexport interface BackoffStrategy {\n /** Initial delay in seconds before the first retry. */\n initialDelay: number;\n /** Multiplier applied to the delay on each subsequent retry. */\n multiplier: number;\n /** Maximum delay in seconds (cap). */\n maxDelay: number;\n /** Jitter factor (0..1). 0.5 means up to 50% random jitter added. */\n jitterFactor: number;\n}\n\n// ── Errors ─────────────────────────────────────────────────────────\n\n/** Error mapping — status codes to named exception kinds. */\nexport interface ErrorPolicy {\n /** Map from HTTP status code to a logical error kind name (e.g. 400 → 'BadRequest').\n * Emitters append language-specific suffixes (e.g. 'BadRequestException'). */\n statusCodeMap: Record<number, string>;\n /** Catch-all error kind for 5xx status codes not in the map. */\n serverErrorKind: string;\n /** Catch-all error kind for unrecognized status codes. */\n clientErrorKind: string;\n /** URL template for error documentation. Use {code} as placeholder for the API error code.\n * Example: 'https://workos.com/docs/errors/{code}' */\n errorDocUrlTemplate?: string;\n}\n\n// ── Telemetry ──────────────────────────────────────────────────────\n\n/** Telemetry — what request metrics to track and send. */\nexport interface TelemetryPolicy {\n /** Whether telemetry is enabled by default. Users can opt out via constructor param. */\n enabledByDefault: boolean;\n /** Header name for client telemetry data (previous request's ID + latency). */\n headerName: string;\n /** Response header name for the request ID. */\n requestIdHeader: string;\n}\n\n// ── Pagination ─────────────────────────────────────────────────────\n\n/** Pagination behavior defaults. */\nexport interface PaginationPolicy {\n /** Delay in milliseconds between pages during auto-pagination. 0 = no delay. */\n autoPageDelayMs: number;\n}\n\n// ── Idempotency ────────────────────────────────────────────────────\n\n/** Idempotency auto-generation rules. */\nexport interface IdempotencyPolicy {\n /** Header name for the idempotency key. */\n headerName: string;\n /** Whether to auto-generate a UUID v4 idempotency key for POST requests when retries > 0. */\n autoGenerateForPost: boolean;\n}\n\n// ── Logging ────────────────────────────────────────────────────────\n\n/** Logging contract — what to log at which level. */\nexport interface LoggingPolicy {\n /** Whether structured logging hooks are generated. */\n enabled: boolean;\n /** Log events that the generated client emits. */\n events: LogEvent[];\n}\n\n/** A discrete loggable event in the request lifecycle. */\nexport type LogEvent =\n | 'request.start'\n | 'request.success'\n | 'request.retry'\n | 'request.rate_limited'\n | 'request.error'\n | 'request.connection_error';\n\n// ── User-Agent ─────────────────────────────────────────────────────\n\n/** User-Agent construction rules. */\nexport interface UserAgentPolicy {\n /** Template for the SDK identifier string.\n * Placeholders: {name} = spec name, {lang} = emitter language, {version} = SDK version.\n * Each emitter interpolates with its own language string and casing conventions.\n * Example: '{name} {lang}/{version}' → 'WorkOS PHP/4.32.0' */\n sdkIdentifierTemplate: string;\n /** Whether to append the runtime/language version (e.g. PHP 8.2, Python 3.12). */\n includeRuntimeVersion: boolean;\n /** Whether to allow app info enrichment via setAppInfo(name, version, url). */\n allowAppInfo: boolean;\n /** AI agent environment variable detection entries. */\n aiAgentEnvVars: AiAgentEnvVar[];\n}\n\n/** Maps an environment variable to an AI agent slug for User-Agent enrichment. */\nexport interface AiAgentEnvVar {\n /** Environment variable to check (e.g. 'CLAUDE_CODE'). */\n envVar: string;\n /** Agent name to append to User-Agent (e.g. 'ClaudeCode'). */\n agentName: string;\n}\n\n// ── Request Guards ─────────────────────────────────────────────────\n\n/** Guards that validate request params before sending. */\nexport interface RequestGuardPolicy {\n /** Keys that should be in RequestOptions, not in params.\n * If detected in the body or query params, the SDK throws an error. */\n optionKeys: string[];\n}\n\n// ── Timeouts ───────────────────────────────────────────────────────\n\n/** Timeout configuration. */\nexport interface TimeoutPolicy {\n /** Default HTTP request timeout in seconds. */\n defaultTimeoutSeconds: number;\n /** Environment variable name to override the timeout (e.g. 'WORKOS_REQUEST_TIMEOUT'). */\n timeoutEnvVar?: string;\n}\n\n// ── Root ───────────────────────────────────────────────────────────\n\n/** Language-agnostic runtime policies for generated SDKs.\n * Attached to `ApiSpec.sdk` and consumed by emitters via `ctx.spec.sdk`. */\nexport interface SdkBehavior {\n retry: RetryPolicy;\n errors: ErrorPolicy;\n telemetry: TelemetryPolicy;\n pagination: PaginationPolicy;\n idempotency: IdempotencyPolicy;\n logging: LoggingPolicy;\n userAgent: UserAgentPolicy;\n requestGuard: RequestGuardPolicy;\n timeout: TimeoutPolicy;\n}\n\n// ── Defaults ───────────────────────────────────────────────────────\n\n/**\n * Canonical SDK behavior defaults. These match the PHP emitter's current\n * implementation (the most complete). Per-language overrides can be applied\n * via `mergeSdkBehavior()` in each SDK's `oagen.config.ts`.\n *\n * - Retry: exponential backoff with jitter, retries on 429/5xx\n * - Errors: standard HTTP status → exception kind mapping\n * - Telemetry: enabled by default, tracks request ID + latency\n * - Pagination: no inter-page delay (Node overrides to 350ms)\n * - Idempotency: auto-generate UUID v4 for retryable POSTs\n * - Logging: all lifecycle events enabled\n * - User-Agent: SDK identifier + runtime version + app info + AI agent detection\n * - Request guards: detect misplaced RequestOptions keys in params\n * - Timeout: 60s default (Python overrides to 30s)\n */\nexport function defaultSdkBehavior(): SdkBehavior {\n return {\n retry: {\n retryableStatusCodes: [429, 500, 502, 503, 504],\n maxRetries: 3,\n retryOnConnectionError: true,\n retryOnTimeout: true,\n backoff: {\n initialDelay: 1.0,\n multiplier: 2.0,\n maxDelay: 30.0,\n jitterFactor: 0.5,\n },\n },\n errors: {\n statusCodeMap: {\n 400: 'BadRequest',\n 401: 'Authentication',\n 403: 'Authorization',\n 404: 'NotFound',\n 409: 'Conflict',\n 422: 'UnprocessableEntity',\n 429: 'RateLimitExceeded',\n },\n serverErrorKind: 'Server',\n clientErrorKind: 'Api',\n errorDocUrlTemplate: 'https://workos.com/docs/errors/{code}',\n },\n telemetry: {\n enabledByDefault: true,\n headerName: 'X-WorkOS-Client-Telemetry',\n requestIdHeader: 'X-Request-ID',\n },\n pagination: {\n autoPageDelayMs: 0,\n },\n idempotency: {\n headerName: 'Idempotency-Key',\n autoGenerateForPost: true,\n },\n logging: {\n enabled: true,\n events: [\n 'request.start',\n 'request.success',\n 'request.retry',\n 'request.rate_limited',\n 'request.error',\n 'request.connection_error',\n ],\n },\n userAgent: {\n sdkIdentifierTemplate: '{name} {lang}/{version}',\n includeRuntimeVersion: true,\n allowAppInfo: true,\n aiAgentEnvVars: [\n { envVar: 'CLAUDE_CODE', agentName: 'ClaudeCode' },\n { envVar: 'CURSOR_AGENT', agentName: 'Cursor' },\n { envVar: 'CLINE_ACTIVE', agentName: 'Cline' },\n { envVar: 'WINDSURF_ACTIVE', agentName: 'Windsurf' },\n { envVar: 'COPILOT_AGENT', agentName: 'Copilot' },\n ],\n },\n requestGuard: {\n optionKeys: [\n 'api_key',\n 'apiKey',\n 'idempotency_key',\n 'idempotencyKey',\n 'extra_headers',\n 'extraHeaders',\n 'max_retries',\n 'maxRetries',\n 'base_url',\n 'baseUrl',\n ],\n },\n timeout: {\n defaultTimeoutSeconds: 60,\n },\n };\n}\n\n// ── Merge ──────────────────────────────────────────────────────────\n\n/** Recursive partial type for deep overrides. */\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends (infer U)[]\n ? U[] // Arrays replace entirely (don't concat)\n : T[K] extends object\n ? DeepPartial<T[K]>\n : T[K];\n};\n\n/**\n * Deep-merge partial overrides into the canonical defaults.\n * Arrays replace entirely (so `retryableStatusCodes: [429]` replaces the full list,\n * rather than appending). Object properties are merged recursively.\n */\nexport function mergeSdkBehavior(overrides: DeepPartial<SdkBehavior>): SdkBehavior {\n return deepMerge(\n defaultSdkBehavior() as unknown as Record<string, unknown>,\n overrides as unknown as Record<string, unknown>,\n ) as unknown as SdkBehavior;\n}\n\n/**\n * Self-contained deep merge (no external imports — ir/ is layer 0).\n * Arrays and primitives from `source` replace those in `target`.\n * Objects are merged recursively.\n */\nfunction deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = { ...target };\n for (const key of Object.keys(source)) {\n const sourceVal = source[key];\n const targetVal = target[key];\n if (sourceVal === undefined) continue;\n if (\n sourceVal !== null &&\n typeof sourceVal === 'object' &&\n !Array.isArray(sourceVal) &&\n targetVal !== null &&\n typeof targetVal === 'object' &&\n !Array.isArray(targetVal)\n ) {\n result[key] = deepMerge(targetVal as Record<string, unknown>, sourceVal as Record<string, unknown>);\n } else {\n result[key] = sourceVal;\n }\n }\n return result;\n}\n","import { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { makeDocumentFromString, bundleDocument, createConfig, BaseResolver, Oas3_1Types } from '@redocly/openapi-core';\nimport { SpecParseError } from '../errors.js';\n\nexport interface BundledSpec {\n parsed: Record<string, unknown>;\n specPath: string;\n}\n\nexport async function loadAndBundleSpec(specPath: string): Promise<BundledSpec> {\n const absolutePath = resolve(specPath);\n const content = await readFile(absolutePath, 'utf-8');\n const document = makeDocumentFromString(content, pathToFileURL(absolutePath).href);\n\n const config = await createConfig({});\n const resolver = new BaseResolver();\n\n const result = await bundleDocument({\n document,\n config,\n types: Oas3_1Types,\n externalRefResolver: resolver,\n dereference: false,\n });\n\n if (result.problems.some((p) => p.severity === 'error')) {\n const errors = result.problems\n .filter((p) => p.severity === 'error')\n .map((p) => p.message)\n .join('\\n');\n throw new SpecParseError(\n `Failed to parse spec: ${errors}`,\n `Check the OpenAPI spec at \"${absolutePath}\" for syntax errors. Run a linter such as \\`npx @redocly/cli lint ${specPath}\\` to identify issues.`,\n );\n }\n\n return {\n parsed: result.bundle.parsed as Record<string, unknown>,\n specPath: absolutePath,\n };\n}\n","import type { Model, Field } from '../ir/types.js';\nimport { toPascalCase, stripListItemMarkers, singularize } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { buildFieldFromSchema, resolveSchemaName } from './schemas.js';\n\n/**\n * Qualify an inline model name with the parent schema name.\n * If `parentName` is provided and the field name doesn't already start with\n * the parent, the result is `${parentName}${PascalField}` with the trailing\n * word singularized (e.g., Connection + Domains → ConnectionDomain).\n */\nexport function qualifyInlineModelName(baseName: string, parentName?: string): string {\n if (!parentName) return baseName;\n // Strip ListItem/ByExternalId markers from parent name so inline model names\n // are clean and match the names produced by qualifyNestedName() in responses.ts.\n // e.g., ConnectionListItem + Domains → Connection + Domain = ConnectionDomain\n const cleanParent = stripListItemMarkers(parentName);\n if (baseName.startsWith(cleanParent)) return baseName;\n // Singularize the trailing PascalCase word of the combined name.\n // Split baseName into leading words + trailing word, singularize trailing.\n const trailingMatch = baseName.match(/^(.*?)([A-Z][a-z]*)$/);\n if (trailingMatch) {\n const [, prefix, trailingWord] = trailingMatch;\n const singular = singularize(trailingWord);\n return `${cleanParent}${prefix}${singular}`;\n }\n return `${cleanParent}${baseName}`;\n}\n\n/**\n * Walk all component schemas and extract inline Model definitions for fields\n * that are objects with properties (or arrays of such objects).\n * These correspond to the ModelRef entries created by schemaToTypeRef.\n */\nexport function extractInlineModelsFromSchemas(schemas: Record<string, SchemaObject> | undefined): Model[] {\n if (!schemas) return [];\n\n const inlineModels: Model[] = [];\n\n for (const [schemaName, schema] of Object.entries(schemas)) {\n const parentName = resolveSchemaName(schemaName);\n extractInlineModelsFromProperties(schema, inlineModels, parentName);\n }\n\n return inlineModels;\n}\n\nfunction extractInlineModelsFromProperties(schema: SchemaObject, results: Model[], parentName?: string): void {\n const properties = schema.properties ?? {};\n const allOfSchemas = schema.allOf ?? [];\n\n for (const sub of allOfSchemas) {\n if (sub.properties) {\n extractInlineModelsFromProperties(sub, results, parentName);\n }\n }\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n // Direct inline object with properties (with or without explicit type: 'object')\n if (fieldSchema.properties && (fieldSchema.type === 'object' || !fieldSchema.type)) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n results.push(buildInlineModel(modelName, fieldSchema));\n extractInlineModelsFromProperties(fieldSchema, results, modelName);\n }\n\n // Array of inline objects\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n const items = fieldSchema.items;\n if (items.properties && (items.type === 'object' || !items.type)) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n results.push(buildInlineModel(modelName, items));\n extractInlineModelsFromProperties(items, results, modelName);\n }\n }\n\n // oneOf containing objects — extract every inline object variant as a\n // model so each gets its own typed class. Variant 0 keeps the bare\n // qualified inline name (e.g. `ApiKeyCreatedDataOwner`); subsequent\n // variants are prefixed by their const-discriminator value via\n // `nameOneOfVariant` (e.g. `UserApiKeyCreatedDataOwner`). When the\n // oneOf doesn't have a const-discriminator (single object variant + null\n // for nullable, or single object variant only), only variant 0 is\n // extracted and the bare name pattern preserves backward compat.\n if (fieldSchema.oneOf) {\n const inlineObjectVariants = fieldSchema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n if (inlineObjectVariants.length > 0) {\n const baseName = toPascalCase(fieldName);\n const modelName = qualifyInlineModelName(baseName, parentName);\n const existingNames = new Set(results.map((r) => r.name));\n const namingDiscProp = deriveOneOfNamingDiscriminator(inlineObjectVariants);\n const emittedNames: string[] = [];\n for (const variant of inlineObjectVariants) {\n const variantName = nameOneOfVariant(variant, modelName, emittedNames, namingDiscProp);\n emittedNames.push(variantName);\n if (!existingNames.has(variantName)) {\n existingNames.add(variantName);\n results.push(buildInlineModel(variantName, variant));\n extractInlineModelsFromProperties(variant, results, variantName);\n }\n }\n }\n }\n }\n}\n\n/** Find a single string-const-valued property shared by every variant whose\n * values are all distinct — the implicit discriminator. Returns null when no\n * such property exists. Mirrors `deriveConstNamingDiscriminator` in schemas.ts. */\nfunction deriveOneOfNamingDiscriminator(variants: SchemaObject[]): string | null {\n if (variants.length < 2) return null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n const values = variants.map((v) => readConstString(v.properties?.[propName]));\n if (values.some((v) => v === null)) continue;\n if (new Set(values).size !== values.length) continue;\n return propName;\n }\n return null;\n}\n\nfunction readConstString(prop: SchemaObject | undefined): string | null {\n if (!prop) return null;\n if (typeof prop.const === 'string') return prop.const;\n if (Array.isArray(prop.enum) && prop.enum.length === 1 && typeof prop.enum[0] === 'string') {\n return prop.enum[0];\n }\n return null;\n}\n\n/** Produce a per-variant model name. Variant 0 keeps the bare parent name;\n * later variants are prefixed by the const-derived label. Mirrors\n * `nameVariantModel` in schemas.ts. Falls back to a numeric suffix when no\n * discriminator is available, the const value PascalCases to nothing, or\n * the derived candidate collides with the parent or an already-emitted name. */\nfunction nameOneOfVariant(\n variant: SchemaObject,\n parentName: string,\n alreadyEmitted: string[],\n discriminatorProperty: string | null,\n): string {\n if (alreadyEmitted.length === 0) return parentName;\n if (discriminatorProperty) {\n const constValue = readConstString(variant.properties?.[discriminatorProperty]);\n if (constValue) {\n const prefix = toPascalCase(constValue);\n if (prefix) {\n const candidate = parentName.startsWith(prefix) ? parentName : `${prefix}${parentName}`;\n const collision = candidate === parentName || alreadyEmitted.includes(candidate);\n if (!collision) return candidate;\n }\n }\n }\n return `${parentName}${alreadyEmitted.length + 1}`;\n}\n\nfunction buildInlineModel(name: string, schema: SchemaObject): Model {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties ?? {})) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n }\n\n return { name, description: schema.description, fields };\n}\n","import type { Model, Enum, EnumValue, Field, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\nimport {\n toPascalCase,\n toUpperSnakeCase,\n cleanSchemaName,\n singularize,\n stripListItemMarkers,\n splitWords,\n} from '../utils/naming.js';\n\n/**\n * Module-level transform set during extractSchemas(). Used by schemaToTypeRef()\n * to apply the same name transform to $ref model/enum references.\n */\nlet activeSchemaNameTransform: ((name: string) => string) | null = null;\n\n/**\n * Module-level set of resolved schema names whose components/schemas entry is\n * an enum (i.e. has `enum:`). Populated by extractSchemas() so schemaToTypeRef()\n * can classify a `$ref` to a top-level enum schema as `kind: 'enum'` instead of\n * `kind: 'model'`. Without this, every `$ref` was naively returned as a model\n * ref, even when the target was a shared enum like `PaginationOrder`.\n */\nlet activeEnumSchemaNames: Set<string> = new Set();\n\n/** Apply cleanSchemaName + the active transform (if any) to a raw schema name. */\nexport function resolveSchemaName(rawName: string): string {\n let name = cleanSchemaName(toPascalCase(rawName));\n if (activeSchemaNameTransform) name = activeSchemaNameTransform(name);\n return name;\n}\n\nexport interface SchemaExtractionOptions {\n schemaNameTransform?: (name: string) => string;\n}\n\nexport interface SchemaObject {\n type?: string | string[];\n format?: string;\n description?: string;\n properties?: Record<string, SchemaObject | undefined>;\n required?: string[];\n items?: SchemaObject;\n enum?: (string | number)[];\n allOf?: SchemaObject[];\n oneOf?: SchemaObject[];\n anyOf?: SchemaObject[];\n discriminator?: { propertyName: string; mapping?: Record<string, string> };\n readOnly?: boolean;\n writeOnly?: boolean;\n nullable?: boolean;\n $ref?: string;\n additionalProperties?: boolean | SchemaObject;\n const?: unknown;\n patternProperties?: Record<string, SchemaObject>;\n deprecated?: boolean;\n default?: unknown;\n example?: unknown;\n [key: string]: unknown;\n}\n\nexport interface ExtractedSchemas {\n models: Model[];\n enums: Enum[];\n}\n\nexport function extractSchemas(\n schemas: Record<string, SchemaObject> | undefined,\n options?: SchemaExtractionOptions,\n): ExtractedSchemas {\n const enums: Enum[] = [];\n\n if (!schemas) return { models: [], enums };\n\n // Build collision-safe transform if provided\n if (options?.schemaNameTransform) {\n const transform = options.schemaNameTransform;\n const rawNames = Object.keys(schemas);\n const cleanedNames = rawNames.map((n) => cleanSchemaName(toPascalCase(n)));\n const transformedToOriginals = new Map<string, string[]>();\n for (const cleaned of cleanedNames) {\n const transformed = transform(cleaned);\n if (!transformedToOriginals.has(transformed)) transformedToOriginals.set(transformed, []);\n transformedToOriginals.get(transformed)!.push(cleaned);\n }\n const unsafeToTransform = new Set<string>();\n for (const [, originals] of transformedToOriginals) {\n if (originals.length > 1) {\n for (const n of originals) unsafeToTransform.add(n);\n }\n }\n activeSchemaNameTransform = (name: string) => (unsafeToTransform.has(name) ? name : transform(name));\n } else {\n activeSchemaNameTransform = null;\n }\n\n // Pre-compute the set of resolved names whose component schema is an enum so\n // schemaToTypeRef() can classify `$ref` targets correctly. Built in a separate\n // pass because the per-schema loop mutates models/enums and we want this map\n // available before any TypeRef is resolved (operations + nested fields both\n // call schemaToTypeRef during extraction).\n activeEnumSchemaNames = new Set();\n for (const [name, schema] of Object.entries(schemas)) {\n if (schema.enum) activeEnumSchemaNames.add(resolveSchemaName(name));\n }\n\n const modelsByCleanName = new Map<string, Model>();\n\n for (const [name, schema] of Object.entries(schemas)) {\n const pascalName = resolveSchemaName(name);\n\n if (schema.enum) {\n enums.push(extractEnum(pascalName, schema));\n } else {\n const model = extractModel(pascalName, schema, schemas);\n const existing = modelsByCleanName.get(pascalName);\n if (existing) {\n // Keep the model with more fields when names collide after cleaning\n if (model.fields.length > existing.fields.length) {\n modelsByCleanName.set(pascalName, model);\n }\n } else {\n modelsByCleanName.set(pascalName, model);\n }\n\n for (const inlineModel of extractDiscriminatedAllOfVariantModels(schema, pascalName)) {\n const existingInline = modelsByCleanName.get(inlineModel.name);\n if (existingInline) {\n if (inlineModel.fields.length > existingInline.fields.length) {\n modelsByCleanName.set(inlineModel.name, inlineModel);\n }\n } else {\n modelsByCleanName.set(inlineModel.name, inlineModel);\n }\n }\n }\n }\n\n const models = [...modelsByCleanName.values()];\n\n // Collect inline models from nested object/oneOf properties\n // that schemaToTypeRef created model refs for but weren't extracted\n const modelNames = new Set(models.map((m) => m.name));\n const inlineQueue: Model[] = [...models];\n while (inlineQueue.length > 0) {\n const model = inlineQueue.pop()!;\n for (const field of model.fields) {\n collectNestedInlineModels(field.type, field.name, model.name, schemas ?? {}, models, modelNames, inlineQueue);\n }\n }\n\n // Collect inline enums from model fields\n for (const model of models) {\n collectInlineEnums(model.fields, enums);\n }\n\n // NOTE: activeSchemaNameTransform is intentionally NOT cleared here.\n // extractOperations() calls schemaToTypeRef() for $ref resolution and\n // needs the same transform active. parseSpec() calls clearSchemaNameTransform()\n // after all extraction is complete.\n return { models, enums };\n}\n\n/** Clear the module-level schemaNameTransform. Called by parseSpec() after all extraction phases. */\nexport function clearSchemaNameTransform(): void {\n activeSchemaNameTransform = null;\n activeEnumSchemaNames = new Set();\n}\n\n/**\n * Walk a single TypeRef and extract inline enum refs as top-level enum definitions.\n * Shared by both schemas.ts (field-level) and parse.ts (model-level) collection passes.\n */\nexport function collectInlineEnumFromRef(ref: TypeRef, enums: Enum[], seen: Set<string>): void {\n walkTypeRef(ref, {\n enum: (r) => {\n if (r.values && !seen.has(r.name)) {\n seen.add(r.name);\n enums.push({\n name: r.name,\n values: r.values.map((v) => ({\n name: toUpperSnakeCase(String(v)),\n value: v,\n description: undefined,\n })),\n });\n }\n },\n });\n}\n\n/**\n * Walk model fields and extract inline enum refs as top-level enum definitions.\n * This ensures type alias files are generated for inline enums.\n */\nfunction collectInlineEnums(fields: Field[], enums: Enum[]): void {\n const seen = new Set(enums.map((e) => e.name));\n for (const field of fields) {\n collectInlineEnumFromRef(field.type, enums, seen);\n }\n}\n\n/**\n * Walk a TypeRef tree and extract inline models for any model refs that point\n * to schemas with inline object properties (not in components/schemas).\n * This handles nested objects like `totp: { oneOf: [{ type: object, properties: {...} }] }`\n * that schemaToTypeRef turns into model refs but aren't extracted from components.\n */\nfunction collectNestedInlineModels(\n ref: TypeRef,\n fieldName: string,\n parentModelName: string,\n schemas: Record<string, SchemaObject>,\n models: Model[],\n modelNames: Set<string>,\n queue: Model[],\n): void {\n walkTypeRef(ref, {\n model: (modelRef) => {\n if (modelNames.has(modelRef.name)) return; // already extracted\n // Check if this model name corresponds to a component schema\n // by checking all possible original names that would map to this PascalCase name\n const isComponent = Object.keys(schemas).some((k) => resolveSchemaName(k) === modelRef.name);\n if (isComponent) return; // will be extracted from components\n\n // This is a reference to a nested inline model that wasn't extracted.\n // Look up the field schema in the parent model's component schema to extract it.\n const parentSchema = findSchemaByName(parentModelName, schemas);\n if (!parentSchema) return;\n\n const fieldSchema = findNestedFieldSchema(fieldName, parentSchema, schemas);\n if (!fieldSchema) return;\n\n // Extract inline models from the field schema\n const extracted = extractNestedSchema(modelRef.name, fieldSchema);\n for (const m of extracted) {\n if (!modelNames.has(m.name)) {\n models.push(m);\n modelNames.add(m.name);\n queue.push(m); // re-scan for deeper nesting\n }\n }\n },\n });\n}\n\n/** Find a component schema by PascalCase name. */\nfunction findSchemaByName(pascalName: string, schemas: Record<string, SchemaObject>): SchemaObject | null {\n for (const [k, v] of Object.entries(schemas)) {\n if (resolveSchemaName(k) === pascalName) return v;\n }\n return null;\n}\n\n/** Walk into a schema to find a field's sub-schema, resolving allOf and oneOf/anyOf. */\nfunction findNestedFieldSchema(\n fieldName: string,\n parentSchema: SchemaObject,\n schemas: Record<string, SchemaObject>,\n): SchemaObject | null {\n if (parentSchema.properties?.[fieldName]) {\n return parentSchema.properties[fieldName]!;\n }\n if (parentSchema.allOf) {\n for (const sub of parentSchema.allOf) {\n let resolved = sub;\n if (sub.$ref) {\n const segments = sub.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) resolved = schemas[refName];\n }\n if (resolved.properties?.[fieldName]) {\n return resolved.properties[fieldName]!;\n }\n }\n }\n // Also check inside oneOf/anyOf variants (pure oneOf schemas flatten variant\n // properties into the model, so the field may live inside a variant).\n for (const variant of [...(parentSchema.oneOf ?? []), ...(parentSchema.anyOf ?? [])]) {\n let resolved = variant;\n if (variant.$ref) {\n const segments = variant.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) resolved = schemas[refName];\n }\n if (resolved.properties?.[fieldName]) {\n return resolved.properties[fieldName]!;\n }\n }\n return null;\n}\n\n/** Extract a model (and nested models) from an inline field schema. */\nfunction extractNestedSchema(name: string, schema: SchemaObject): Model[] {\n // Handle oneOf: extract each object variant as its own model\n if (schema.oneOf) {\n const models: Model[] = [];\n\n // Collect the inline object variants up front. When every variant pins\n // the same property to a const value, we can derive meaningful names\n // from the const (e.g. `UserApiKeyOwner` instead of `ApiKeyOwner2`)\n // — much friendlier for SDK consumers than numeric suffixes.\n const inlineObjectVariants: SchemaObject[] = schema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n const constNamingDiscriminator = deriveConstNamingDiscriminator(inlineObjectVariants);\n\n for (const variant of schema.oneOf) {\n if (variant.$ref) continue;\n if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const requiredSet = new Set(variant.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(variant.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n const variantName = nameVariantModel(variant, name, models, constNamingDiscriminator);\n models.push({ name: variantName, description: variant.description, fields });\n }\n }\n return models;\n }\n\n // Handle direct object\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(schema.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n return [{ name, description: schema.description, fields }];\n }\n\n // Handle array with inline items\n if (schema.type === 'array' && schema.items?.properties) {\n const requiredSet = new Set(schema.items.required ?? []);\n const fields: Field[] = [];\n for (const [fn, fs] of Object.entries(schema.items.properties)) {\n if (!fs) continue;\n fields.push(buildFieldFromSchema(fn, fs, name, requiredSet));\n }\n return [{ name, description: schema.items.description, fields }];\n }\n\n return [];\n}\n\n/**\n * Derive a meaningful name for a oneOf object variant past the first,\n * falling back to the numeric-suffix scheme (`Foo2`, `Foo3`) when no\n * better signal is available. The \"better signal\" is a const-valued\n * discriminator property that distinguishes one variant from the others.\n *\n * For a schema like `ApiKey.owner` whose oneOf has two variants — one\n * with `type: { const: \"organization\" }` and one with `type: { const:\n * \"user\" }` — this returns `ApiKeyOwner` for the first variant (the\n * baseline name that the union TypeRef will reference, so consumer-\n * visible typed fields stay backward-compatible) and `UserApiKeyOwner`\n * for the second instead of `ApiKeyOwner2`. SDK consumers reading the\n * generated types can tell the variants apart at a glance.\n *\n * The first variant always keeps the bare parent name because\n * `schemaToTypeRef` builds union variants whose model refs collapse to\n * `qualifyInlineModelName(field, parent)` — so the first model name\n * must match for the union's degenerate-collapse to land on a valid\n * type. Renaming variant 0 would orphan it.\n *\n * Falls back to numeric suffix when:\n * - The variant has no discriminator property (no shared const\n * property across all object variants), OR\n * - The const value PascalCases to an empty/whitespace name, OR\n * - The derived name collides with the parent name or an already-\n * emitted variant name (numeric keeps uniqueness).\n */\nfunction nameVariantModel(\n variant: SchemaObject,\n parentName: string,\n alreadyEmitted: Model[],\n discriminator: { property: string } | null,\n): string {\n // Variant 0 keeps the bare parent name so the union TypeRef's degenerate\n // collapse target exists in the model registry.\n if (alreadyEmitted.length === 0) return parentName;\n\n if (discriminator) {\n const constValue = getConstPropertyValue(variant, discriminator.property);\n if (constValue) {\n const prefix = toPascalCase(constValue);\n if (prefix) {\n const candidate = parentName.startsWith(prefix) ? parentName : `${prefix}${parentName}`;\n const collision = candidate === parentName || alreadyEmitted.some((m) => m.name === candidate);\n if (!collision) return candidate;\n }\n }\n }\n return `${parentName}${alreadyEmitted.length + 1}`;\n}\n\n/**\n * Returns a discriminator descriptor when every inline object variant in a\n * oneOf has a string-const value on the same property — the signature of a\n * discriminated union without an explicit `discriminator:` keyword. Used by\n * `nameVariantModel` to derive variant names from the const values.\n *\n * Distinct from `detectConstPropertyDiscriminator` (which requires every\n * variant to carry a `$ref` or `title` so a name mapping can be built):\n * this pass operates on inline anonymous variants, where naming is exactly\n * what we're trying to derive.\n */\nfunction deriveConstNamingDiscriminator(variants: SchemaObject[]): { property: string } | null {\n if (variants.length < 2) return null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n const values = variants.map((v) => getConstPropertyValue(v, propName));\n if (values.some((v) => v === null)) continue;\n if (new Set(values).size !== values.length) continue; // collisions = no signal\n return { property: propName };\n }\n return null;\n}\n\n/** Build a single Field from a schema property entry. Shared across all extraction sites. */\nexport function buildFieldFromSchema(\n fieldName: string,\n fieldSchema: SchemaObject,\n contextName: string,\n requiredSet: Set<string>,\n): Field {\n return {\n name: fieldName,\n type: schemaToTypeRef(fieldSchema, fieldName, contextName),\n required: requiredSet.has(fieldName),\n description: fieldSchema.description,\n readOnly: fieldSchema.readOnly || undefined,\n writeOnly: fieldSchema.writeOnly || undefined,\n deprecated: fieldSchema.deprecated || undefined,\n default: fieldSchema.default,\n example: fieldSchema.example,\n };\n}\n\n/**\n * If every non-null oneOf/anyOf variant is a string-valued const, return the\n * list of those const values so the union can collapse into a single enum.\n * Returns null when any variant isn't a pure string-const (model ref,\n * number const, nullable, etc.).\n */\nfunction collectLiteralStringConsts(variants: SchemaObject[]): string[] | null {\n if (variants.length === 0) return null;\n const values: string[] = [];\n for (const v of variants) {\n // A single-element enum is semantically identical to const.\n if (typeof v.const === 'string') {\n values.push(v.const);\n continue;\n }\n if (Array.isArray(v.enum) && v.enum.length === 1 && typeof v.enum[0] === 'string') {\n values.push(v.enum[0]);\n continue;\n }\n return null;\n }\n return values;\n}\n\n/** Build an EnumRef the same way the regular enum path does for naming. */\nfunction buildSyntheticEnumRef(\n values: string[],\n contextName: string | undefined,\n parentModelName: string | undefined,\n): TypeRef {\n const baseName = toPascalCase(contextName ?? 'UnknownEnum');\n const cleanParent = parentModelName ? stripListItemMarkers(parentModelName) : undefined;\n const qualifiedName = cleanParent && !baseName.startsWith(cleanParent) ? `${cleanParent}${baseName}` : baseName;\n // Run the same `schemaNameTransform` we apply to component-schema names so\n // a project-level rename map (e.g. `RadarAction` → `RadarListAction` in\n // `oagen.config.ts`) catches inline parameter enums too.\n const finalName = activeSchemaNameTransform ? activeSchemaNameTransform(qualifiedName) : qualifiedName;\n return { kind: 'enum', name: finalName, values };\n}\n\n/**\n * Detect an implicit discriminator on an oneOf where every variant is an\n * object schema that pins the same property to a const value. Returns\n * { property, mapping } so the IR can represent the union as discriminated\n * without needing an explicit `discriminator:` key in the spec.\n *\n * Both shapes are supported:\n * { properties: { event: { const: \"x\" } }, required: [\"event\"] }\n * { properties: { event: { type: \"string\", enum: [\"x\"] } } }\n *\n * Returns null when any variant doesn't fit the pattern or when variants\n * disagree on which property carries the discriminator.\n */\nfunction detectConstPropertyDiscriminator(\n variants: SchemaObject[],\n): { property: string; mapping: Record<string, string> } | null {\n if (variants.length < 2) return null;\n\n // Find properties whose const value is present on every variant.\n let candidateProperty: string | null = null;\n const candidates = Object.keys(variants[0]?.properties ?? {});\n for (const propName of candidates) {\n if (variants.every((v) => getConstPropertyValue(v, propName) !== null)) {\n candidateProperty = propName;\n break;\n }\n }\n\n if (!candidateProperty) return null;\n\n const mapping: Record<string, string> = {};\n for (const v of variants) {\n const value = getConstPropertyValue(v, candidateProperty);\n if (value === null) return null;\n // Require a $ref or title so we have a concrete model name to map to.\n const variantName = resolveVariantModelName(v);\n if (!variantName) return null;\n mapping[value] = variantName;\n }\n\n return { property: candidateProperty, mapping };\n}\n\nfunction getConstPropertyValue(schema: SchemaObject, property: string): string | null {\n const prop = schema.properties?.[property];\n if (!prop) return null;\n if (typeof prop.const === 'string') return prop.const;\n if (Array.isArray(prop.enum) && prop.enum.length === 1 && typeof prop.enum[0] === 'string') {\n return prop.enum[0];\n }\n return null;\n}\n\nfunction resolveVariantModelName(schema: SchemaObject): string | null {\n if (schema.$ref) {\n return resolveSchemaName(schema.$ref.replace(/^#\\/components\\/schemas\\//, ''));\n }\n const title = typeof schema['title'] === 'string' ? (schema['title'] as string) : null;\n if (title) return resolveSchemaName(title);\n return null;\n}\n\n/** Look up the discriminator's mapped variant name for an inline object\n * variant by reading its const-valued discriminator property. Returns null\n * when the variant doesn't pin the property to a string const, or when\n * the value isn't in the mapping. */\nfunction mapVariantToDiscriminatorEntry(\n variant: SchemaObject,\n discriminator: { property: string; mapping: Record<string, string> },\n): string | null {\n const value = getConstPropertyValue(variant, discriminator.property);\n if (value === null) return null;\n return discriminator.mapping[value] ?? null;\n}\n\n/**\n * Derive a discriminator value → variant model name mapping for an inline-\n * variant `oneOf` whose explicit `discriminator:` has no `mapping:` clause.\n *\n * Each variant model name is reproduced via `nameVariantModel` so it matches\n * what `extractNestedSchema` registered when it walked the same `oneOf` to\n * pull variants out as named models. Variant 0 keeps the bare parent name\n * (e.g. `ApiKeyOwner`); subsequent variants get a const-derived prefix\n * (e.g. `UserApiKeyOwner` for the `type: const: user` variant).\n *\n * The \"parent name\" used here mirrors the one `collectNestedInlineModels`\n * passes to `extractNestedSchema`: it's the qualified inline model name\n * built from `contextName` (the field name) plus `parentModelName` (the\n * containing model). Returns null when any non-object variant is present\n * or when a variant lacks a const value on the discriminator property.\n */\nfunction deriveInlineVariantMapping(\n variants: SchemaObject[],\n discriminatorProperty: string,\n contextName: string | undefined,\n parentModelName: string | undefined,\n): Record<string, string> | null {\n if (variants.length === 0 || !contextName) return null;\n const inlineObjectVariants = variants.filter((v) => !v.$ref && v.properties && (v.type === 'object' || !v.type));\n if (inlineObjectVariants.length !== variants.length) return null;\n\n const baseInlineName = qualifyInlineModelName(toPascalCase(contextName), parentModelName);\n const namingDiscriminator = { property: discriminatorProperty };\n const mapping: Record<string, string> = {};\n const emittedSoFar: Model[] = [];\n for (const variant of inlineObjectVariants) {\n const constValue = getConstPropertyValue(variant, discriminatorProperty);\n if (constValue === null) return null;\n const variantName = nameVariantModel(variant, baseInlineName, emittedSoFar, namingDiscriminator);\n mapping[constValue] = variantName;\n emittedSoFar.push({ name: variantName, fields: [] });\n }\n return mapping;\n}\n\nfunction extractEnum(name: string, schema: SchemaObject): Enum {\n const values: EnumValue[] = (schema.enum ?? []).map((v) => ({\n name: toUpperSnakeCase(String(v)),\n value: typeof v === 'number' ? v : String(v),\n description: undefined,\n }));\n\n const rawDefault = schema.default;\n const def =\n rawDefault !== undefined && values.some((v) => v.value === rawDefault)\n ? (rawDefault as string | number)\n : undefined;\n\n return { name, values, default: def };\n}\nfunction extractModel(name: string, schema: SchemaObject, schemas?: Record<string, SchemaObject>): Model {\n if (schema.allOf) {\n return extractAllOfModel(name, schema, schemas);\n }\n\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties ?? {})) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n }\n\n // Pure oneOf/anyOf schemas (no allOf, no properties): merge variant fields\n // as optional. This handles schemas like UpdateOrganizationMembership which\n // is a oneOf with mutually exclusive field groups (role_slug vs role_slugs).\n if (fields.length === 0 && (schema.oneOf || schema.anyOf)) {\n const variants = schema.oneOf ?? schema.anyOf ?? [];\n const emptyRequired = new Set<string>();\n const seenFieldNames = new Set<string>();\n for (const variant of variants) {\n if (!variant.properties) continue;\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema || seenFieldNames.has(fieldName)) continue;\n seenFieldNames.add(fieldName);\n fields.push(buildFieldFromSchema(fieldName, fieldSchema as SchemaObject, name, emptyRequired));\n }\n }\n }\n\n // When additionalProperties is an object schema alongside properties,\n // surface it as a catch-all map field so emitters can generate Map<string, T>.\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object' && schema.properties) {\n const apKeys = Object.keys(schema.additionalProperties);\n if (apKeys.length > 0) {\n const valueType = schemaToTypeRef(schema.additionalProperties as SchemaObject, 'additionalProperties', name);\n fields.push({\n name: 'additionalProperties',\n type: { kind: 'map', valueType },\n required: false,\n description: 'Additional properties not captured by named fields',\n });\n }\n }\n\n return { name, description: schema.description, fields };\n}\n\nfunction extractAllOfModel(name: string, schema: SchemaObject, schemas?: Record<string, SchemaObject>): Model {\n const fields: Field[] = [];\n const requiredSet = new Set<string>();\n let resultDiscriminator: { property: string; mapping: Record<string, string> } | undefined;\n\n for (const subSchema of schema.allOf ?? []) {\n // Resolve $ref sub-schemas by looking up the referenced component schema\n let resolved = subSchema;\n if (subSchema.$ref && schemas) {\n const segments = subSchema.$ref.split('/');\n const refName = segments[segments.length - 1];\n if (refName && schemas[refName]) {\n resolved = schemas[refName];\n }\n }\n\n // If the resolved schema is itself an allOf, recursively extract its fields\n if (resolved.allOf) {\n const nested = extractAllOfModel(name, resolved, schemas);\n for (const f of nested.fields) {\n fields.push({ ...f, required: false }); // will be re-set below\n if (f.required) requiredSet.add(f.name);\n }\n } else if (resolved.oneOf || resolved.anyOf) {\n const variants = resolved.oneOf ?? resolved.anyOf ?? [];\n // Detect discriminated union: every variant pins the same property to a\n // distinct const value (e.g. EventSchema where each variant has event: const).\n // When detected, store the discriminator instead of flattening variant fields —\n // the base allOf schema already captures the common fields.\n const discriminatorInfo = detectAllOfVariantDiscriminator(variants, name);\n if (discriminatorInfo) {\n resultDiscriminator = discriminatorInfo;\n } else {\n // Flatten oneOf/anyOf variant fields into the parent model as optional\n // fields. This handles the common allOf + oneOf pattern where the spec\n // uses mutually exclusive variant groups (e.g. password vs password_hash).\n const emptyRequired = new Set<string>();\n const seenFieldNames = new Set(fields.map((f) => f.name));\n for (const variant of variants) {\n if (!variant.properties) continue;\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema || seenFieldNames.has(fieldName)) continue;\n seenFieldNames.add(fieldName);\n fields.push(buildFieldFromSchema(fieldName, fieldSchema as SchemaObject, name, emptyRequired));\n }\n }\n // Do NOT add variant-level required to the requiredSet — these fields\n // are optional at the parent level because they come from mutually\n // exclusive branches.\n }\n } else {\n if (resolved.required) {\n for (const r of resolved.required) requiredSet.add(r);\n }\n if (resolved.properties) {\n // Use an empty requiredSet — required flags are set in the final pass below\n const emptyRequired = new Set<string>();\n for (const [fieldName, fieldSchema] of Object.entries(resolved.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, emptyRequired));\n }\n }\n }\n }\n\n // Also collect required from the outer schema\n if (schema.required) {\n for (const r of schema.required) requiredSet.add(r);\n }\n\n // Set required flags\n for (const f of fields) {\n f.required = requiredSet.has(f.name);\n }\n\n return {\n name,\n description: schema.description,\n fields,\n ...(resultDiscriminator ? { discriminator: resultDiscriminator } : {}),\n };\n}\n\n/**\n * Walk through `allOf` wrappers to collect the effective top-level properties\n * of a schema. Stops at `oneOf` / `anyOf` boundaries — those are different\n * variant axes, not part of the same flat object.\n *\n * Used by `detectAllOfVariantDiscriminator` and `deriveDiscriminatedVariantName`\n * so a oneOf variant of the form `{ allOf: [{ properties: { … } }, { oneOf: […] }] }`\n * still surfaces its top-level `properties` (in particular its discriminator\n * `const`) instead of being treated as having none.\n */\nfunction getEffectiveProperties(schema: SchemaObject): Record<string, SchemaObject> {\n const props: Record<string, SchemaObject> = {};\n const visit = (s: SchemaObject): void => {\n if (s.properties) {\n for (const [k, v] of Object.entries(s.properties)) {\n if (!(k in props) && v) props[k] = v;\n }\n }\n if (s.allOf) {\n for (const sub of s.allOf) visit(sub);\n }\n // Do NOT walk into oneOf / anyOf — those are alternatives, not\n // simultaneously-present properties.\n };\n visit(schema);\n return props;\n}\n\nfunction getEffectiveConstPropertyValue(schema: SchemaObject, property: string): string | null {\n const direct = getConstPropertyValue(schema, property);\n if (direct !== null) return direct;\n const effective = getEffectiveProperties(schema)[property];\n if (!effective) return null;\n if (typeof effective.const === 'string') return effective.const;\n if (Array.isArray(effective.enum) && effective.enum.length === 1 && typeof effective.enum[0] === 'string') {\n return effective.enum[0];\n }\n return null;\n}\n\n/**\n * Detect an implicit discriminator on an allOf+oneOf where every variant is an\n * object that pins the same property to a distinct const value. Unlike\n * detectConstPropertyDiscriminator (which requires $ref or title for variant\n * model names), this version derives model names from the const value itself\n * using deriveDiscriminatedVariantName — matching how extractDiscriminatedAllOfVariantModels\n * names those models.\n *\n * Walks through allOf wrappers on each variant so a oneOf branch like\n * { allOf: [{ properties: { type: { const: 'oauth' } } }, { oneOf: […] }] }\n * still surfaces `type` as a candidate discriminator.\n *\n * Returns null when no discriminator can be reliably detected.\n */\nfunction detectAllOfVariantDiscriminator(\n variants: SchemaObject[],\n fallbackName: string,\n): { property: string; mapping: Record<string, string> } | null {\n if (variants.length < 2) return null;\n\n // Find a property whose const value is present on every variant\n // (looking through allOf wrappers on each variant).\n const firstProps = getEffectiveProperties(variants[0] ?? {});\n let candidateProperty: string | null = null;\n for (const propName of Object.keys(firstProps)) {\n if (variants.every((v) => getEffectiveConstPropertyValue(v, propName) !== null)) {\n candidateProperty = propName;\n break;\n }\n }\n if (!candidateProperty) return null;\n\n const mapping: Record<string, string> = {};\n const seenModelNames = new Set<string>();\n for (const v of variants) {\n const value = getEffectiveConstPropertyValue(v, candidateProperty);\n if (value === null) return null;\n const modelName = deriveDiscriminatedVariantName(v, fallbackName);\n // If two variants map to the same model name, the discriminator is ambiguous\n if (seenModelNames.has(modelName)) return null;\n seenModelNames.add(modelName);\n mapping[value] = modelName;\n }\n\n return { property: candidateProperty, mapping };\n}\n\nfunction extractDiscriminatedAllOfVariantModels(schema: SchemaObject, fallbackName: string): Model[] {\n const models: Model[] = [];\n const seenNames = new Set<string>();\n\n // Collect base-object properties + required from the allOf wrapper so each\n // variant can be emitted as a complete, self-contained type. Schemas like\n // `EventSchema` repeat the base fields inside every variant in the spec\n // (so this merge is a no-op there), but `ConnectApplication`'s OAuth /\n // M2M variants don't — without this, dispatcher consumers would get a\n // variant that's missing the shared `id` / `name` / `object` etc.\n const baseProperties: Record<string, SchemaObject> = {};\n const baseRequired = new Set<string>();\n for (const subSchema of schema.allOf ?? []) {\n if (subSchema.oneOf) continue; // the variant axis, handled below\n const flat = subSchema.allOf ? flattenVariantForExtraction(subSchema) : subSchema;\n if (flat.properties) {\n for (const [k, v] of Object.entries(flat.properties)) {\n if (!(k in baseProperties) && v) baseProperties[k] = v;\n }\n }\n if (flat.required) for (const r of flat.required) baseRequired.add(r);\n }\n\n for (const subSchema of schema.allOf ?? []) {\n for (const variant of subSchema.oneOf ?? []) {\n // Flatten any allOf wrapper on the variant (e.g. `ConnectApplication`'s\n // OAuth branch is `allOf: [{ properties: {…} }, { oneOf: [first-party\n // sub-variants] }]`). The flattened object has merged properties and\n // an inlined sub-variant `oneOf` so `extractInlineModelDeep` can pull\n // out a complete variant model.\n const flat = flattenVariantForExtraction(variant);\n if (!flat.properties || (flat.type !== undefined && flat.type !== 'object')) continue;\n\n // Merge base fields into the variant. Variant-specific properties win\n // on name collisions because the spec may pin a base field to a more\n // specific shape inside a variant.\n const mergedProperties: Record<string, SchemaObject> = { ...baseProperties };\n for (const [k, v] of Object.entries(flat.properties)) {\n if (v) mergedProperties[k] = v;\n }\n const mergedRequired = new Set<string>([...baseRequired, ...(flat.required ?? [])]);\n const merged: SchemaObject = {\n type: 'object',\n properties: mergedProperties,\n required: [...mergedRequired],\n };\n\n const variantName = deriveDiscriminatedVariantName(variant, fallbackName);\n for (const model of extractInlineModelDeep(variantName, merged)) {\n if (seenNames.has(model.name)) continue;\n seenNames.add(model.name);\n models.push(model);\n }\n }\n }\n\n return models;\n}\n\n/**\n * Flatten a oneOf variant schema into a single object-shaped schema for\n * variant-model extraction. Recursively merges `allOf` members and folds\n * any nested `oneOf` into an inline-oneOf field group whose properties are\n * the union across sub-branches (required only when present in every\n * sub-branch). Returns the schema unchanged when no flattening is needed.\n */\nfunction flattenVariantForExtraction(variant: SchemaObject): SchemaObject {\n if (!variant.allOf) return variant;\n\n const mergedProperties: Record<string, SchemaObject> = {};\n const mergedRequired = new Set<string>();\n const nestedOneOfs: SchemaObject[][] = [];\n\n const collect = (s: SchemaObject): void => {\n if (s.properties) {\n for (const [k, v] of Object.entries(s.properties)) {\n if (!(k in mergedProperties) && v) mergedProperties[k] = v;\n }\n }\n if (s.required) {\n for (const r of s.required) mergedRequired.add(r);\n }\n if (s.allOf) {\n for (const sub of s.allOf) collect(sub);\n }\n if (s.oneOf) nestedOneOfs.push(s.oneOf);\n };\n collect(variant);\n\n // Fold each nested oneOf into the merged shape: any field appearing in any\n // sub-branch is included as optional (or required iff present-and-required\n // in every sub-branch). Conflicting literal types widen to their primitive\n // base. This handles the `is_first_party: true | false` widening on the\n // OAuth variant's first-party sub-oneOf.\n for (const branches of nestedOneOfs) {\n const flatBranches = branches.map(flattenVariantForExtraction);\n const branchKeys = new Set<string>();\n for (const b of flatBranches) {\n for (const k of Object.keys(b.properties ?? {})) branchKeys.add(k);\n }\n for (const key of branchKeys) {\n const schemas: SchemaObject[] = [];\n for (const b of flatBranches) {\n const s = b.properties?.[key];\n if (s) schemas.push(s);\n }\n const merged = mergeBranchPropertySchemas(schemas);\n if (!(key in mergedProperties)) mergedProperties[key] = merged;\n const inAllBranches = flatBranches.every((b) => b.properties && key in b.properties);\n const requiredInAll = inAllBranches && flatBranches.every((b) => (b.required ?? []).includes(key));\n if (requiredInAll) mergedRequired.add(key);\n }\n }\n\n return {\n type: 'object',\n properties: mergedProperties,\n required: [...mergedRequired],\n };\n}\n\n/**\n * Merge same-named property schemas from across sub-variants. If every\n * occurrence is a boolean const, widen to plain boolean; if every occurrence\n * is a distinct string const, widen to plain string. Otherwise return the\n * first occurrence — emitters that build their own widened types (e.g. the\n * Node discriminated-models module) re-derive from the raw spec.\n */\nfunction mergeBranchPropertySchemas(schemas: SchemaObject[]): SchemaObject {\n if (schemas.length === 0) return {};\n if (schemas.length === 1) return schemas[0];\n\n const allBoolConst = schemas.every((s) => s.type === 'boolean' && typeof s.const === 'boolean');\n if (allBoolConst) {\n return { type: 'boolean', description: schemas[0].description };\n }\n const allStringConst = schemas.every((s) => s.type === 'string' && typeof s.const === 'string');\n if (allStringConst) {\n const values = schemas.map((s) => s.const as string);\n if (new Set(values).size === 1) return schemas[0];\n return { type: 'string', description: schemas[0].description };\n }\n return schemas[0];\n}\n\nfunction deriveDiscriminatedVariantName(schema: SchemaObject, fallbackName: string): string {\n // Walk through allOf wrappers so a variant of the form\n // `{ allOf: [{ properties: { type: const: 'oauth' } }, { oneOf: […] }] }`\n // still surfaces its discriminator const value for naming.\n const effective = getEffectiveProperties(schema);\n if (Object.keys(effective).length === 0) return fallbackName;\n\n const pickConst = (name: string): string | null => {\n const field = effective[name];\n if (!field) return null;\n if (typeof field.const === 'string') return field.const;\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return field.enum[0];\n }\n return null;\n };\n\n let constValue: string | null = null;\n for (const preferred of ['event', 'type', 'object']) {\n constValue = pickConst(preferred);\n if (constValue) break;\n }\n if (constValue === null) {\n for (const name of Object.keys(effective)) {\n constValue = pickConst(name);\n if (constValue) break;\n }\n }\n if (constValue === null) return fallbackName;\n\n const pascal = toPascalCase(constValue);\n if (!pascal) return fallbackName;\n\n // A single-word const like `oauth` or `m2m` is too generic to stand alone\n // as a top-level model name — it would collide with unrelated schemas. Pair\n // it with the parent name so the variant resolves to e.g. `ConnectApplicationOAuth`\n // / `ConnectApplicationM2M`. Multi-word consts like `action.authentication.denied`\n // are already specific enough on their own, matching the established\n // EventSchema variant naming.\n const wordCount = splitWords(constValue).length;\n if (wordCount >= 2) return pascal;\n if (pascal === fallbackName) return pascal;\n if (fallbackName.startsWith(pascal)) return fallbackName;\n if (pascal.endsWith(fallbackName)) return pascal;\n return `${fallbackName}${pascal}`;\n}\n\nfunction extractInlineModelDeep(name: string, schema: SchemaObject): Model[] {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n const properties = schema.properties ?? {};\n const nestedModels: Model[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n nestedModels.push(...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), fieldSchema));\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items?.properties) {\n nestedModels.push(...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), fieldSchema.items));\n }\n\n if (fieldSchema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of fieldSchema.allOf) {\n if (sub.properties) Object.assign(mergedProperties, sub.properties);\n if (sub.required) mergedRequired.push(...sub.required);\n }\n if (Object.keys(mergedProperties).length > 0) {\n nestedModels.push(\n ...extractInlineModelDeep(qualifyNestedInlineName(name, fieldName), {\n type: 'object',\n properties: mergedProperties,\n required: mergedRequired,\n }),\n );\n }\n }\n\n if (fieldSchema.oneOf) {\n const inlineObjectVariants = fieldSchema.oneOf.filter(\n (v) => !v.$ref && v.properties && (v.type === 'object' || !v.type),\n );\n if (inlineObjectVariants.length > 0) {\n const baseQualified = qualifyNestedInlineName(name, fieldName);\n const namingDisc = deriveConstNamingDiscriminator(inlineObjectVariants);\n const emitted: Model[] = [];\n for (const variant of inlineObjectVariants) {\n const variantName = nameVariantModel(variant, baseQualified, emitted, namingDisc);\n emitted.push({ name: variantName, fields: [] });\n nestedModels.push(...extractInlineModelDeep(variantName, variant));\n }\n }\n }\n }\n\n return [{ name, description: schema.description, fields }, ...nestedModels];\n}\n\nfunction qualifyNestedInlineName(parentName: string, fieldName: string): string {\n const pascalField = toPascalCase(fieldName);\n if (pascalField.startsWith(parentName)) return pascalField;\n\n const cleanParent = stripListItemMarkers(parentName);\n const qualified = `${cleanParent}${pascalField}`;\n const match = qualified.match(/^(.+?)([A-Z][a-z]+s?)$/);\n if (match && match[2]) {\n return match[1] + singularize(match[2]);\n }\n return qualified;\n}\n\nexport function schemaToTypeRef(schema: SchemaObject, contextName?: string, parentModelName?: string): TypeRef {\n // Handle $ref → ModelRef or EnumRef.\n // A `$ref` to a top-level component schema needs to preserve whether the\n // target is a model or an enum, because emitters route imports differently\n // for the two kinds (e.g. com.workos.models.X vs com.workos.types.X). The\n // set of enum names is precomputed by extractSchemas() in a first pass so\n // it's available even when called recursively for nested $refs.\n if (schema.$ref) {\n const segments = schema.$ref.split('/');\n const rawName = segments[segments.length - 1];\n const resolved = resolveSchemaName(rawName);\n if (activeEnumSchemaNames.has(resolved)) {\n return { kind: 'enum', name: resolved };\n }\n return { kind: 'model', name: resolved };\n }\n\n // Handle OAS 3.1 nullable type arrays: type: [string, null]\n if (Array.isArray(schema.type)) {\n const nonNullTypes = schema.type.filter((t: string) => t !== 'null');\n // type: ['null'] — only null, no real type\n if (nonNullTypes.length === 0) {\n return { kind: 'nullable', inner: { kind: 'primitive', type: 'unknown' } };\n }\n if (schema.type.includes('null') && nonNullTypes.length === 1) {\n return {\n kind: 'nullable',\n inner: schemaToTypeRef({ ...schema, type: nonNullTypes[0], nullable: false }, contextName),\n };\n }\n // Multiple non-null types → union\n if (nonNullTypes.length > 1) {\n const variants = nonNullTypes.map((t: string) => schemaToTypeRef({ ...schema, type: t }, contextName));\n const ref: TypeRef = { kind: 'union', variants };\n if (schema.type.includes('null')) {\n return { kind: 'nullable', inner: ref };\n }\n return ref;\n }\n }\n\n // Handle OAS 3.0 nullable flag\n if (schema.nullable && schema.type) {\n return {\n kind: 'nullable',\n inner: schemaToTypeRef({ ...schema, nullable: false }, contextName),\n };\n }\n\n // Handle allOf — merge properties from all sub-schemas.\n // This handles patterns like: allOf: [{ type: object, properties: {...} }, { oneOf: [...] }]\n // which are valid OAS 3.1 but weren't handled for field-level schemas.\n if (schema.allOf) {\n // If allOf contains a $ref, prefer the ref (it's a named type)\n const refItem = schema.allOf.find((s: SchemaObject) => s.$ref);\n if (refItem) {\n // If allOf has $ref AND siblings with properties, return a merged model ref\n // to avoid losing the augmentation properties\n const hasAugmentation = schema.allOf.some((s: SchemaObject) => !s.$ref && (s.properties || s.type === 'object'));\n if (hasAugmentation) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return { kind: 'model', name: qualifyInlineModelName(baseName, parentModelName) };\n }\n return schemaToTypeRef(refItem, contextName, parentModelName);\n }\n // If allOf has a single item, unwrap it\n if (schema.allOf.length === 1) {\n return schemaToTypeRef(schema.allOf[0], contextName, parentModelName);\n }\n // If allOf items all have properties, treat as a merged model\n const hasProperties = schema.allOf.some((s: SchemaObject) => s.properties);\n if (hasProperties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n // Fall through to other checks\n }\n\n // Handle oneOf / anyOf → Union or Nullable\n // Valid OAS 3.1: properties can have { oneOf: [{ type: object }, { type: 'null' }] }\n // without a wrapping `type` field.\n if (schema.oneOf || schema.anyOf) {\n const compositionKind: 'oneOf' | 'anyOf' = schema.oneOf ? 'oneOf' : 'anyOf';\n const rawVariants: SchemaObject[] = schema.oneOf ?? schema.anyOf ?? [];\n\n // Check for nullable pattern: oneOf: [realType, { type: 'null' }]\n const nullVariant = rawVariants.find(\n (v: SchemaObject) => v.type === 'null' || (Array.isArray(v.type) && v.type.length === 1 && v.type[0] === 'null'),\n );\n const nonNullVariants = rawVariants.filter((v) => v !== nullVariant);\n\n if (nullVariant && nonNullVariants.length === 1) {\n // Nullable single type — unwrap as nullable\n return {\n kind: 'nullable',\n inner: schemaToTypeRef(nonNullVariants[0], contextName, parentModelName),\n };\n }\n\n // Collapse an oneOf/anyOf whose non-null variants are all string-const\n // schemas into a single enum. This turns patterns like\n // provider: { oneOf: [{ const: \"AppleOAuth\" }, { const: \"GitHubOAuth\" }, ...] }\n // into a proper enum type with one member per variant instead of a\n // structurally-opaque union of literal refs.\n const literalStrings = collectLiteralStringConsts(nonNullVariants);\n if (literalStrings !== null && literalStrings.length >= 2) {\n const enumRef = buildSyntheticEnumRef(literalStrings, contextName, parentModelName);\n return nullVariant ? { kind: 'nullable', inner: enumRef } : enumRef;\n }\n\n // Resolve the discriminator. Three sources, in order:\n // 1. Explicit `discriminator:` with explicit `mapping:` — trust the spec.\n // 2. Explicit `discriminator:` with no `mapping:` — derive mapping from\n // variants' const values on the discriminator property, pairing each\n // to its inline-extracted variant model name (built the same way\n // `extractNestedSchema` names them via `nameVariantModel`). This\n // covers `ApiKey.owner`-shaped schemas where the spec uses\n // `discriminator: { propertyName: type }` but lists inline anonymous\n // `oneOf` variants instead of `$ref` links.\n // 3. No explicit discriminator but every variant pins the same const-\n // valued property AND the variants are nameable via $ref/title —\n // `detectConstPropertyDiscriminator` covers this.\n // 4. As a last resort, when (3) doesn't apply because variants are\n // inline anonymous objects, derive the same const → variant-model-\n // name mapping using `nameVariantModel`. This covers\n // `ApiKeyCreatedData.owner`-shaped schemas (oneOf with inline\n // const-discriminating variants but no `discriminator:` keyword).\n let resolvedDiscriminator: { property: string; mapping: Record<string, string> } | undefined;\n if (schema.discriminator) {\n const property = schema.discriminator.propertyName;\n const explicitMapping = schema.discriminator.mapping ?? {};\n let mapping: Record<string, string> = Object.fromEntries(\n Object.entries(explicitMapping).map(([k, v]) => [k, v.replace(/^#\\/components\\/schemas\\//, '')]),\n );\n if (Object.keys(mapping).length === 0) {\n const inlineMapping = deriveInlineVariantMapping(nonNullVariants, property, contextName, parentModelName);\n if (inlineMapping) mapping = inlineMapping;\n }\n resolvedDiscriminator = { property, mapping };\n } else if (compositionKind === 'oneOf') {\n const synthetic = detectConstPropertyDiscriminator(nonNullVariants);\n if (synthetic) {\n resolvedDiscriminator = synthetic;\n } else {\n const namingDisc = deriveConstNamingDiscriminator(nonNullVariants);\n if (namingDisc) {\n const inlineMapping = deriveInlineVariantMapping(\n nonNullVariants,\n namingDisc.property,\n contextName,\n parentModelName,\n );\n if (inlineMapping) {\n resolvedDiscriminator = { property: namingDisc.property, mapping: inlineMapping };\n }\n }\n }\n }\n\n // Build variants. When we have a discriminator with a known mapping and\n // every non-null variant is an inline object that pins the discriminator\n // property to a const, route each variant's TypeRef through that mapping.\n // This avoids the degenerate case where `qualifyInlineModelName` would\n // assign the same parent-derived name (e.g. `ApiKeyOwner`) to every\n // inline variant, collapsing the union to a single repeated model ref.\n const variants: TypeRef[] = [];\n for (const v of rawVariants) {\n if (v === nullVariant) continue;\n const inlineMappingName =\n resolvedDiscriminator && !v.$ref && v.properties && (v.type === 'object' || !v.type)\n ? mapVariantToDiscriminatorEntry(v, resolvedDiscriminator)\n : null;\n if (inlineMappingName) {\n variants.push({ kind: 'model', name: inlineMappingName });\n } else {\n variants.push(schemaToTypeRef(v, contextName, parentModelName));\n }\n }\n const hasNull = !!nullVariant;\n\n const union: TypeRef = {\n kind: 'union',\n variants,\n compositionKind,\n ...(resolvedDiscriminator ? { discriminator: resolvedDiscriminator } : {}),\n };\n return hasNull ? { kind: 'nullable', inner: union } : union;\n }\n\n // Handle const → LiteralType (supports string, number, boolean)\n if (schema.const !== undefined) {\n if (typeof schema.const === 'string' || typeof schema.const === 'number' || typeof schema.const === 'boolean') {\n return { kind: 'literal', value: schema.const };\n }\n // null const → nullable unknown\n if (schema.const === null) {\n return { kind: 'nullable', inner: { kind: 'primitive', type: 'unknown' } };\n }\n // const of object/array → map or array with unknown values\n if (typeof schema.const === 'object') {\n if (Array.isArray(schema.const)) {\n return { kind: 'array', items: { kind: 'primitive', type: 'unknown' } };\n }\n return { kind: 'map', valueType: { kind: 'primitive', type: 'unknown' } };\n }\n }\n if (schema.enum && schema.enum.length === 1) {\n const v = schema.enum[0];\n return { kind: 'literal', value: typeof v === 'number' ? v : String(v) };\n }\n\n // Handle enum\n if (schema.enum) {\n const baseName = toPascalCase(contextName ?? 'UnknownEnum');\n // Strip ListItem/ByExternalId markers from parent name so enum names are clean:\n // e.g., DirectoryListItem + State → Directory + State = DirectoryState\n const cleanParent = parentModelName ? stripListItemMarkers(parentModelName) : undefined;\n // Avoid redundant prefix: Connection + ConnectionType → ConnectionType\n const qualifiedName = cleanParent && !baseName.startsWith(cleanParent) ? `${cleanParent}${baseName}` : baseName;\n // Run `schemaNameTransform` so project-level rename maps in\n // `oagen.config.ts` reach inline parameter/field enums too — without\n // this, `RadarAction` (built from path param `action` on the Radar\n // service) couldn't be redirected to `RadarListAction` from config.\n const finalName = activeSchemaNameTransform ? activeSchemaNameTransform(qualifiedName) : qualifiedName;\n return {\n kind: 'enum',\n name: finalName,\n values: schema.enum.map((v) => (typeof v === 'number' ? v : String(v))),\n };\n }\n\n // Handle array — pass parentModelName through to qualify inline items\n if (schema.type === 'array' && schema.items) {\n return {\n kind: 'array',\n items: schemaToTypeRef(schema.items, contextName, parentModelName),\n };\n }\n // Handle array without explicit type but with items (valid OAS 3.1)\n if (!schema.type && schema.items) {\n return {\n kind: 'array',\n items: schemaToTypeRef(schema.items, contextName, parentModelName),\n };\n }\n\n // Handle object → ModelRef (if it has properties, it's a named model reference)\n // When additionalProperties is also present, we still return a ModelRef so the\n // named properties are preserved. The extractModel path will pick up the extra\n // properties as a catch-all map field named `additionalProperties`.\n if (schema.type === 'object' && schema.properties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n\n // Handle freeform object with additionalProperties or patternProperties → Map<string, T>\n if (schema.type === 'object' && !schema.properties) {\n let valueType: TypeRef = { kind: 'primitive', type: 'unknown' };\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {\n // Empty additionalProperties ({}) means \"any value\" — keep as unknown\n const apKeys = Object.keys(schema.additionalProperties);\n if (apKeys.length > 0) {\n valueType = schemaToTypeRef(schema.additionalProperties as SchemaObject, contextName);\n }\n } else if (schema.patternProperties) {\n // patternProperties: { \"pattern\": schema } → use the first pattern's schema as value type\n const patterns = Object.values(schema.patternProperties);\n if (patterns.length > 0) {\n valueType = schemaToTypeRef(patterns[0], contextName);\n }\n }\n return {\n kind: 'map',\n valueType,\n };\n }\n\n // Handle primitives\n const primitiveMap: Record<string, 'string' | 'integer' | 'number' | 'boolean'> = {\n string: 'string',\n integer: 'integer',\n number: 'number',\n boolean: 'boolean',\n };\n\n const typeStr = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n if (typeStr && primitiveMap[typeStr]) {\n return {\n kind: 'primitive',\n type: primitiveMap[typeStr],\n ...(schema.format ? { format: schema.format } : {}),\n };\n }\n\n // Handle schemas with no type — if it has properties, treat as model\n if (!schema.type && schema.properties) {\n const baseName = toPascalCase(contextName ?? 'UnknownModel');\n return {\n kind: 'model',\n name: qualifyInlineModelName(baseName, parentModelName),\n };\n }\n\n // Empty schema {} → unknown\n if (\n !schema.type &&\n !schema.$ref &&\n !schema.oneOf &&\n !schema.anyOf &&\n !schema.allOf &&\n !schema.enum &&\n !schema.properties &&\n !schema.items\n ) {\n return { kind: 'primitive', type: 'unknown' };\n }\n\n // Fallback: treat unknown schemas as unknown\n if (contextName) {\n console.warn(`[oagen] Warning: Unknown schema shape treated as unknown (context: ${contextName})`);\n }\n return { kind: 'primitive', type: 'unknown' };\n}\n\nimport { qualifyInlineModelName } from './inline-models.js';\n\nexport { qualifyInlineModelName, extractInlineModelsFromSchemas } from './inline-models.js';\n","import type { TypeRef, Parameter, PaginationMeta } from '../ir/types.js';\n\nconst CURSOR_PARAMS = ['cursor', 'after', 'before', 'starting_after', 'ending_before', 'page_token', 'next_token'];\n\nconst OFFSET_PARAMS = ['offset', 'page', 'page_number', 'skip'];\nconst LIMIT_PARAMS = ['limit', 'page_size', 'per_page', 'size', 'count'];\n\n/**\n * Detect if an operation uses pagination and return structured metadata\n * for auto-paging iterator generation.\n *\n * Supports two strategies:\n * 1. **Cursor-based**: query params include a cursor-like parameter\n * 2. **Offset-based**: query params include both an offset-like and limit-like parameter\n *\n * Returns null if no pagination pattern is detected.\n */\nexport function detectPagination(\n response: TypeRef,\n queryParams: Parameter[],\n dataPath?: string,\n): PaginationMeta | null {\n // Try cursor-based first (preferred). Scan in CURSOR_PARAMS priority order\n // rather than queryParams order so that an endpoint exposing both `before`\n // and `after` reports `after` (forward iteration) — matches the wire\n // convention where `after` advances through pages.\n const cursorParam = CURSOR_PARAMS.map((name) => queryParams.find((p) => p.name === name)).find(\n (p): p is Parameter => p !== undefined,\n );\n\n if (cursorParam) {\n const itemType: TypeRef = response.kind === 'array' ? response.items : response;\n return {\n strategy: 'cursor',\n param: cursorParam.name,\n dataPath: dataPath,\n itemType,\n };\n }\n\n // Try offset-based pagination\n const offsetParam = queryParams.find((p) => OFFSET_PARAMS.includes(p.name));\n const limitParam = queryParams.find((p) => LIMIT_PARAMS.includes(p.name));\n\n if (offsetParam && limitParam) {\n const itemType: TypeRef = response.kind === 'array' ? response.items : response;\n return {\n strategy: 'offset',\n param: offsetParam.name,\n limitParam: limitParam.name,\n dataPath: dataPath,\n itemType,\n };\n }\n\n return null;\n}\n","import type { TypeRef, Model, Field } from '../ir/types.js';\nimport { toPascalCase, singularize, stripListItemMarkers } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { schemaToTypeRef, buildFieldFromSchema } from './schemas.js';\n\nexport interface ResponseExtractionResult {\n /** The TypeRef to use as the operation's response type */\n response: TypeRef;\n /** Any inline models discovered during extraction (to merge into ir.models) */\n inlineModels: Model[];\n /** Whether this response indicates a paginated list */\n isPaginated: boolean;\n /** Path to the data array within the response envelope (e.g., 'data') */\n dataPath?: string;\n /** TypeRef of individual items in a paginated list */\n itemType?: TypeRef;\n}\n\nexport function classifyAndExtractResponse(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n // 1. If schema is a $ref, resolve to model name (Phase 1)\n if (schema.$ref) {\n return { response: schemaToTypeRef(schema, contextName), inlineModels: [], isPaginated: false };\n }\n\n // 2. Check for list envelope (structural detection: array prop + non-array companion)\n const envelope = detectListEnvelope(schema);\n if (envelope.isEnvelope) {\n return extractListResponse(schema, contextName, envelope.dataPath!);\n }\n\n // 3. Check for single-resource wrapper ({ resource_name: { object: \"...\", ... } })\n if (isSingleResourceWrapper(schema)) {\n return extractWrappedResource(schema, contextName);\n }\n\n // 4. Direct resource or plain inline object\n return extractDirectResource(schema, contextName);\n}\n\ninterface ListEnvelopeResult {\n isEnvelope: boolean;\n dataPath: string | null;\n}\n\nconst KNOWN_DATA_PATHS = new Set(['data', 'items', 'results', 'records', 'entries', 'values', 'nodes', 'edges']);\n\nconst PAGINATION_METADATA_PATTERNS = [\n 'meta',\n 'metadata',\n 'pagination',\n 'cursor',\n 'has_more',\n 'page_info',\n 'total',\n 'next_page',\n 'previous_page',\n 'offset',\n];\n\nfunction detectListEnvelope(schema: SchemaObject): ListEnvelopeResult {\n // Collect all property sources (allOf sub-schemas or flat schema)\n const propSources: Record<string, SchemaObject | undefined>[] = [];\n if (schema.allOf) {\n for (const sub of schema.allOf) {\n if (sub.properties) propSources.push(sub.properties);\n }\n }\n if (schema.properties) {\n propSources.push(schema.properties);\n }\n\n if (propSources.length === 0) return { isEnvelope: false, dataPath: null };\n\n // Merge all properties into a single view\n const mergedProps: Record<string, SchemaObject | undefined> = {};\n for (const source of propSources) {\n Object.assign(mergedProps, source);\n }\n\n // Find array-typed properties and non-array companion properties\n const arrayProps: string[] = [];\n const nonArrayKeys: string[] = [];\n\n for (const [key, propSchema] of Object.entries(mergedProps)) {\n if (!propSchema) continue;\n if (propSchema.type === 'array') {\n arrayProps.push(key);\n } else {\n nonArrayKeys.push(key);\n }\n }\n\n // List envelope heuristic: exactly one array property + at least one non-array companion\n // that looks like pagination metadata. A `data` array alone (e.g. with only an\n // `object` discriminant companion) is NOT sufficient — the companion must indicate\n // actual pagination (cursor, metadata, total, etc.).\n if (arrayProps.length === 1 && nonArrayKeys.length >= 1) {\n const arrayPropName = arrayProps[0];\n\n const hasPaginationCompanion = nonArrayKeys.some((key) =>\n PAGINATION_METADATA_PATTERNS.some((pattern) => key.toLowerCase().includes(pattern)),\n );\n\n if (KNOWN_DATA_PATHS.has(arrayPropName) && hasPaginationCompanion) {\n return { isEnvelope: true, dataPath: arrayPropName };\n }\n\n // Non-standard array property name — still treat as envelope if pagination companion exists\n if (hasPaginationCompanion) {\n return { isEnvelope: true, dataPath: arrayPropName };\n }\n }\n\n return { isEnvelope: false, dataPath: null };\n}\n\nfunction extractListResponse(schema: SchemaObject, contextName: string, dataPath: string): ResponseExtractionResult {\n let itemTypeRef: TypeRef = { kind: 'primitive', type: 'string' };\n const inlineModels: Model[] = [];\n\n // Collect all property sources (allOf sub-schemas or flat schema)\n const propSources: Record<string, SchemaObject | undefined>[] = [];\n if (schema.allOf) {\n for (const sub of schema.allOf) {\n if (sub.properties) propSources.push(sub.properties);\n }\n }\n if (schema.properties) {\n propSources.push(schema.properties);\n }\n\n for (const props of propSources) {\n const dataProp = props[dataPath];\n if (!dataProp) continue;\n\n if (dataProp.type === 'array' && dataProp.items) {\n const items = dataProp.items;\n if (items.$ref) {\n itemTypeRef = schemaToTypeRef(items, contextName);\n } else if (items.type === 'object' && items.properties) {\n const itemName = contextName.replace(/Response$/, '') + 'Item';\n itemTypeRef = { kind: 'model', name: itemName };\n inlineModels.push(...extractInlineModel(itemName, items));\n }\n }\n }\n\n return {\n response: { kind: 'array', items: itemTypeRef },\n inlineModels,\n isPaginated: true,\n dataPath,\n itemType: itemTypeRef,\n };\n}\n\nfunction hasDiscriminantConstField(schema: SchemaObject): { property: string; value: string } | null {\n if (!schema.properties) return null;\n\n // Prefer well-known discriminant properties for backward compatibility\n const preferred = ['object', 'type'];\n for (const name of preferred) {\n const field = schema.properties[name];\n if (!field) continue;\n if (field.const !== undefined && typeof field.const === 'string') {\n return { property: name, value: field.const };\n }\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return { property: name, value: field.enum[0] };\n }\n }\n\n // Fall back to any property with a const or single-value enum\n for (const [name, field] of Object.entries(schema.properties)) {\n if (!field) continue;\n if (field.const !== undefined && typeof field.const === 'string') {\n return { property: name, value: field.const };\n }\n if (field.enum && field.enum.length === 1 && typeof field.enum[0] === 'string') {\n return { property: name, value: field.enum[0] };\n }\n }\n\n return null;\n}\n\nfunction isSingleResourceWrapper(schema: SchemaObject): boolean {\n if (schema.type !== 'object') return false;\n if (!schema.properties) return false;\n\n // Find the wrapper property: use required[0] if available, or the single property key\n let wrapperKey: string | undefined;\n if (schema.required && schema.required.length === 1) {\n wrapperKey = schema.required[0];\n } else {\n const propKeys = Object.keys(schema.properties);\n if (propKeys.length === 1) {\n wrapperKey = propKeys[0];\n }\n }\n if (!wrapperKey) return false;\n\n const propSchema = schema.properties[wrapperKey];\n if (!propSchema) return false;\n\n // Direct object with a discriminant const field\n if (propSchema.type === 'object' && hasDiscriminantConstField(propSchema) !== null) return true;\n\n // oneOf with object + null (nullable resource)\n if (propSchema.oneOf) {\n return propSchema.oneOf.some((v) => v.type === 'object' && hasDiscriminantConstField(v) !== null);\n }\n\n return false;\n}\n\nfunction extractWrappedResource(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n const props = schema.properties!;\n const wrapperKey = schema.required && schema.required.length === 1 ? schema.required[0] : Object.keys(props)[0];\n const propSchema = props[wrapperKey]!;\n const inlineModels: Model[] = [];\n\n // Derive model name from the object const value or wrapper property name\n const resourceName = contextName.replace(/Response$/, '');\n\n if (propSchema.oneOf) {\n const objectVariant = propSchema.oneOf.find((v) => v.type === 'object' && hasDiscriminantConstField(v) !== null);\n\n if (objectVariant) {\n const modelName = deriveModelName(objectVariant, resourceName);\n inlineModels.push(...extractInlineModel(modelName, objectVariant));\n\n const hasNullVariant = propSchema.oneOf.some(\n (v) => v.type === 'null' || (Array.isArray(v.type) && v.type.includes('null')),\n );\n\n const modelRef: TypeRef = { kind: 'model', name: modelName };\n return {\n response: hasNullVariant ? { kind: 'nullable', inner: modelRef } : modelRef,\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // Direct object\n const modelName = deriveModelName(propSchema, resourceName);\n inlineModels.push(...extractInlineModel(modelName, propSchema));\n\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n}\n\nfunction extractDirectResource(schema: SchemaObject, contextName: string): ResponseExtractionResult {\n const inlineModels: Model[] = [];\n\n // Direct object with properties (with or without explicit type: 'object')\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const modelName = deriveModelName(schema, contextName);\n inlineModels.push(...extractInlineModel(modelName, schema));\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n }\n\n // allOf with properties — merge into a single model\n if (schema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of schema.allOf) {\n if (sub.properties) {\n Object.assign(mergedProperties, sub.properties);\n }\n if (sub.required) {\n mergedRequired.push(...sub.required);\n }\n }\n if (Object.keys(mergedProperties).length > 0) {\n const merged: SchemaObject = { type: 'object', properties: mergedProperties, required: mergedRequired };\n const modelName = deriveModelName(merged, contextName);\n inlineModels.push(...extractInlineModel(modelName, merged));\n return {\n response: { kind: 'model', name: modelName },\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // oneOf — delegate to schemaToTypeRef (returns union) but also extract inline models\n // from object variants so the model refs resolve\n if (schema.oneOf) {\n for (const variant of schema.oneOf) {\n if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const modelName = deriveModelName(variant, contextName);\n const existingNames = new Set(inlineModels.map((m) => m.name));\n if (!existingNames.has(modelName)) {\n inlineModels.push(...extractInlineModel(modelName, variant));\n }\n }\n }\n }\n\n // Array with inline object items — extract the item model\n if (schema.type === 'array' && schema.items) {\n const items = schema.items;\n if (items.$ref) {\n return {\n response: { kind: 'array', items: schemaToTypeRef(items, contextName) },\n inlineModels,\n isPaginated: false,\n };\n }\n if (items.properties && (items.type === 'object' || !items.type)) {\n const itemName = contextName.replace(/Response$/, '') + 'Item';\n inlineModels.push(...extractInlineModel(itemName, items));\n return {\n response: { kind: 'array', items: { kind: 'model', name: itemName } },\n inlineModels,\n isPaginated: false,\n };\n }\n }\n\n // Non-object schema (primitive, union, etc.) — delegate to schemaToTypeRef\n return {\n response: schemaToTypeRef(schema, contextName),\n inlineModels,\n isPaginated: false,\n };\n}\n\nfunction deriveModelName(schema: SchemaObject, fallback: string): string {\n if (!schema.properties) return toPascalCase(fallback);\n\n // Prefer well-known discriminant properties for backward compatibility\n const preferred = ['object', 'type'];\n for (const name of preferred) {\n const field = schema.properties[name];\n if (field && field.const && typeof field.const === 'string') {\n return toPascalCase(field.const);\n }\n }\n\n // Fall back to any property with a const string value\n for (const [, field] of Object.entries(schema.properties)) {\n if (field && field.const && typeof field.const === 'string') {\n return toPascalCase(field.const);\n }\n }\n\n return toPascalCase(fallback);\n}\n\n/**\n * Qualify a nested inline model name with its parent to avoid generic names.\n * e.g., parent=\"Connection\" + field=\"domains\" → \"ConnectionDomain\" (singularized)\n * Only qualifies when the field name alone would be too generic.\n */\nfunction qualifyNestedName(parentName: string, fieldName: string): string {\n const pascalField = toPascalCase(fieldName);\n // If the field name already starts with the parent name, don't double-prefix\n if (pascalField.startsWith(parentName)) return pascalField;\n // Qualify with parent and singularize:\n // Connection + Domains → ConnectionDomains → singularize lead word → ConnectionDomain\n const cleanParent = stripListItemMarkers(parentName);\n const qualified = `${cleanParent}${pascalField}`;\n // Singularize the trailing word: ConnectionDomains → ConnectionDomain\n const match = qualified.match(/^(.+?)([A-Z][a-z]+s?)$/);\n if (match && match[2]) {\n const trailing = singularize(match[2]);\n return match[1] + trailing;\n }\n return qualified;\n}\n\nfunction extractInlineModel(name: string, schema: SchemaObject): Model[] {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n const properties = schema.properties ?? {};\n const nestedModels: Model[] = [];\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, name, requiredSet));\n\n // Recursively extract nested inline objects — qualify with parent name\n // to avoid generic names like \"Domains\" when multiple parents have a \"domains\" field\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n const nestedName = qualifyNestedName(name, fieldName);\n nestedModels.push(...extractInlineModel(nestedName, fieldSchema));\n }\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n const items = fieldSchema.items;\n if (items.type === 'object' && items.properties) {\n const nestedName = qualifyNestedName(name, fieldName);\n nestedModels.push(...extractInlineModel(nestedName, items));\n }\n }\n // Handle allOf with inline object properties — merge into a single nested model\n if (fieldSchema.allOf) {\n const mergedProperties: Record<string, SchemaObject | undefined> = {};\n const mergedRequired: string[] = [];\n for (const sub of fieldSchema.allOf) {\n if (sub.properties) Object.assign(mergedProperties, sub.properties);\n if (sub.required) mergedRequired.push(...sub.required);\n }\n if (Object.keys(mergedProperties).length > 0) {\n const nestedName = qualifyNestedName(name, fieldName);\n const merged: SchemaObject = { type: 'object', properties: mergedProperties, required: mergedRequired };\n const existingNames = new Set(nestedModels.map((m) => m.name));\n if (!existingNames.has(nestedName)) {\n nestedModels.push(...extractInlineModel(nestedName, merged));\n }\n }\n }\n // Handle oneOf containing inline objects — extract the first non-null object variant\n if (fieldSchema.oneOf) {\n const objectVariant = fieldSchema.oneOf.find((v) => v.properties && (v.type === 'object' || !v.type));\n if (objectVariant) {\n const nestedName = qualifyNestedName(name, fieldName);\n const existingNames = new Set(nestedModels.map((m) => m.name));\n if (!existingNames.has(nestedName)) {\n nestedModels.push(...extractInlineModel(nestedName, objectVariant));\n }\n }\n }\n }\n\n return [{ name, description: schema.description, fields }, ...nestedModels];\n}\n","import type {\n Service,\n Operation,\n HttpMethod,\n Parameter,\n ParameterGroup,\n TypeRef,\n ErrorResponse,\n SuccessResponse,\n SecurityRequirement,\n Model,\n Field,\n PaginationMeta,\n} from '../ir/types.js';\nimport { toPascalCase, toCamelCase, cleanSchemaName } from '../utils/naming.js';\nimport type { SchemaObject } from './schemas.js';\nimport { schemaToTypeRef, buildFieldFromSchema } from './schemas.js';\nimport { detectPagination } from './pagination.js';\nimport { classifyAndExtractResponse } from './responses.js';\n\ninterface PathItem {\n get?: OperationObject;\n post?: OperationObject;\n put?: OperationObject;\n patch?: OperationObject;\n delete?: OperationObject;\n head?: OperationObject;\n options?: OperationObject;\n trace?: OperationObject;\n parameters?: ParameterObject[];\n}\n\ninterface ParameterGroupExtension {\n optional: boolean;\n variants: Record<string, string[]>;\n}\n\ninterface OperationObject {\n operationId?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n parameters?: ParameterObject[];\n requestBody?: RequestBodyObject;\n responses?: Record<string, ResponseObject>;\n deprecated?: boolean;\n 'x-oagen-async'?: boolean;\n security?: Array<Record<string, string[]>>;\n 'x-mutually-exclusive-parameter-groups'?: Record<string, ParameterGroupExtension>;\n 'x-mutually-exclusive-body-groups'?: Record<string, ParameterGroupExtension>;\n}\n\ninterface ParameterObject {\n name: string;\n in: 'path' | 'query' | 'header' | 'cookie';\n required?: boolean;\n description?: string;\n schema?: SchemaObject;\n deprecated?: boolean;\n example?: unknown;\n style?: string;\n explode?: boolean;\n}\n\ninterface RequestBodyObject {\n required?: boolean;\n content?: Record<string, { schema?: SchemaObject }>;\n}\n\ninterface ResponseObject {\n description?: string;\n content?: Record<string, { schema?: SchemaObject }>;\n}\n\nconst HTTP_METHODS: HttpMethod[] = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];\n\nexport interface OperationExtractionResult {\n services: Service[];\n inlineModels: Model[];\n}\n\nexport function extractOperations(\n paths: Record<string, PathItem> | undefined,\n operationIdTransform?: (id: string) => string,\n componentSchemas?: Record<string, SchemaObject>,\n): OperationExtractionResult {\n if (!paths) return { services: [], inlineModels: [] };\n\n const serviceMap = new Map<string, Operation[]>();\n const inlineModels: Model[] = [];\n\n for (const [path, pathItem] of Object.entries(paths)) {\n const pathLevelParams = pathItem.parameters ?? [];\n\n for (const method of HTTP_METHODS) {\n const op = pathItem[method];\n if (!op) continue;\n\n const serviceName = inferServiceName(path, op.tags?.[0]);\n\n const { operation, inlineModels: opModels } = buildOperation(\n method,\n path,\n op,\n pathLevelParams,\n operationIdTransform,\n serviceName,\n componentSchemas,\n );\n inlineModels.push(...opModels);\n const ops = serviceMap.get(serviceName) ?? [];\n ops.push(operation);\n serviceMap.set(serviceName, ops);\n }\n }\n\n // Split services when a single tag groups operations from multiple path prefixes.\n // Example: /organizations and /organization_domains both tagged \"organizations\"\n // should become separate services based on their first path segment.\n for (const [serviceName, operations] of serviceMap) {\n const pathGroups = new Map<string, Operation[]>();\n for (const op of operations) {\n const firstSeg = op.path.split('/').filter(Boolean)[0] ?? '';\n const groupKey = firstSeg.startsWith('{') ? serviceName : toPascalCase(firstSeg);\n const group = pathGroups.get(groupKey) ?? [];\n group.push(op);\n pathGroups.set(groupKey, group);\n }\n // Only split if there are multiple distinct path-prefix groups AND\n // at least one group name differs from the current service name\n if (pathGroups.size > 1) {\n const needsSplit = [...pathGroups.keys()].some((k) => k !== serviceName);\n if (needsSplit) {\n serviceMap.delete(serviceName);\n for (const [groupName, groupOps] of pathGroups) {\n const existing = serviceMap.get(groupName) ?? [];\n existing.push(...groupOps);\n serviceMap.set(groupName, existing);\n }\n }\n }\n }\n\n // Disambiguate operation names within each service.\n // Multiple operations can get the same name (e.g., several \"list\" endpoints\n // in UserManagement for users, invitations, auth factors, etc.).\n for (const [, operations] of serviceMap) {\n disambiguateOperationNames(operations);\n }\n\n const services = Array.from(serviceMap.entries()).map(([name, operations]) => ({\n name,\n operations,\n }));\n\n return { services, inlineModels };\n}\n\nfunction inferServiceName(path: string, tag?: string): string {\n // Prefer OpenAPI tag when available — tags represent the logical grouping\n // (e.g., \"multi-factor-auth\" for /auth/factors/* endpoints).\n if (tag) {\n return toPascalCase(tag);\n }\n // Fallback: extract first meaningful path segment: /widgets/{id}/sub → \"Widgets\"\n const segments = path.split('/').filter(Boolean);\n const first = segments[0] ?? 'Default';\n // Skip path params\n if (first.startsWith('{')) return 'Default';\n return toPascalCase(first);\n}\n\n/**\n * Strip overload indices (e.g. NestJS emits `Foo_bar[0]` when a controller\n * method handles multiple routes) from an operationId so derived names never\n * leak the bracketed digit. Without this, `authenticate[0]` would surface as\n * `authenticate0` in method names and `Authenticate0Request` in body model\n * names. Brackets at the end (or with trailing whitespace) are common in\n * NestJS-style backends; this regex is intentionally narrow to avoid eating\n * legitimate digits like `oauth2`.\n */\nfunction normalizeOperationIdForNaming(operationId: string): string {\n return operationId.replace(/\\[\\d+\\]\\s*$/, '');\n}\n\nfunction inferOperationName(\n method: HttpMethod,\n path: string,\n operationId?: string,\n operationIdTransform?: (id: string) => string,\n): string {\n if (operationId) {\n const normalized = normalizeOperationIdForNaming(operationId);\n if (operationIdTransform) {\n return operationIdTransform(normalized);\n }\n return toCamelCase(normalized);\n }\n\n // Fallback when no operationId is available — use method + path to build\n // a descriptive name like \"listUsers\", \"getOrganization\", \"deleteAuthFactor\"\n const verb = inferVerb(method, path);\n const resource = inferResourceFromPath(path);\n return resource ? toCamelCase(`${verb}_${resource}`) : verb;\n}\n\n/**\n * Infer the CRUD verb from HTTP method and path shape.\n */\nfunction inferVerb(method: HttpMethod, path: string): string {\n const segments = path.split('/').filter(Boolean);\n const hasTrailingParam = segments.length > 0 && segments[segments.length - 1].startsWith('{');\n\n switch (method) {\n case 'get':\n return hasTrailingParam ? 'get' : 'list';\n case 'post':\n return 'create';\n case 'put':\n case 'patch':\n return 'update';\n case 'delete':\n return 'delete';\n case 'head':\n return 'check';\n case 'options':\n return 'options';\n case 'trace':\n return 'trace';\n default:\n return method;\n }\n}\n\n/**\n * Extract a resource noun from the path for operation naming.\n * Uses the last non-param segment (the resource being operated on).\n *\n * Examples:\n * /user_management/users → \"Users\"\n * /user_management/users/{id} → \"User\" (singular for item operations)\n * /user_management/users/{id}/auth_factors → \"AuthFactors\"\n * /organizations/{id}/api_keys → \"ApiKeys\"\n * /sso/authorize → \"Authorize\" (action endpoint)\n */\nfunction inferResourceFromPath(path: string): string | null {\n const segments = path.split('/').filter(Boolean);\n if (segments.length <= 1) return null;\n\n // Find the last meaningful (non-param) segment\n let resourceSegment: string | null = null;\n for (let i = segments.length - 1; i >= 0; i--) {\n if (!segments[i].startsWith('{')) {\n resourceSegment = segments[i];\n break;\n }\n }\n\n if (!resourceSegment) return null;\n // Skip the service name (first segment) — it would be redundant\n if (resourceSegment === segments[0]) return null;\n\n return toPascalCase(resourceSegment);\n}\n\n/**\n * Detect and resolve name collisions within a service's operations.\n *\n * When multiple operations share the same name (e.g., several \"list\" from\n * different sub-resources), disambiguate by appending the resource noun\n * from the path. Only renames operations on DIFFERENT paths — same-name\n * operations on the same path (e.g., PUT + PATCH both \"update\") are left as-is\n * since they represent the same logical resource.\n */\nfunction disambiguateOperationNames(operations: Operation[]): void {\n // Group by name\n const byName = new Map<string, Operation[]>();\n for (const op of operations) {\n const group = byName.get(op.name) ?? [];\n group.push(op);\n byName.set(op.name, group);\n }\n\n for (const [name, group] of byName) {\n if (group.length <= 1) continue;\n\n // Check if these are genuinely different resources (different paths)\n // vs the same resource with different methods (PUT + PATCH)\n const uniquePaths = new Set(group.map((op) => op.path));\n if (uniquePaths.size <= 1) continue; // same path, different methods — no disambiguation needed\n\n for (const op of group) {\n const resource = inferResourceFromPath(op.path);\n if (resource) {\n const newName = toCamelCase(`${name}_${resource}`);\n (op as { name: string }).name = newName;\n }\n }\n\n // If disambiguation still left collisions (same sub-resource),\n // use the full distinguishing path segment chain\n const renamed = new Map<string, Operation[]>();\n for (const op of group) {\n const rGroup = renamed.get(op.name) ?? [];\n rGroup.push(op);\n renamed.set(op.name, rGroup);\n }\n for (const [, rGroup] of renamed) {\n if (rGroup.length <= 1) continue;\n // Still colliding — different paths map to same resource name.\n // Use deeper path context to disambiguate.\n for (const op of rGroup) {\n const deeper = inferDeeperContext(op.path);\n if (deeper) {\n (op as { name: string }).name = toCamelCase(`${op.name}_${deeper}`);\n }\n }\n }\n }\n}\n\n/**\n * Extract a deeper disambiguation context from the path when the last\n * segment isn't unique enough. Uses the second-to-last non-param segment.\n *\n * /users/{id}/auth_factors → already captured as \"AuthFactors\"\n * /users/external_id/{external_id} → \"ExternalId\" (special path, not a sub-resource)\n */\nfunction inferDeeperContext(path: string): string | null {\n const segments = path.split('/').filter(Boolean);\n const nonParams = segments.filter((s) => !s.startsWith('{'));\n // Skip first (service) and last (already used) — use the middle ones\n if (nonParams.length >= 3) {\n return toPascalCase(nonParams.slice(1, -1).join('_'));\n }\n return null;\n}\n\n/**\n * Extract mutually-exclusive parameter groups from the `x-mutually-exclusive-parameter-groups`\n * operation extension. Cross-references grouped parameter names against the already-extracted\n * IR parameter arrays so emitters get object-identity references.\n */\nfunction extractParameterGroups(\n op: OperationObject,\n allIRParams: Parameter[],\n operationContext: string,\n): ParameterGroup[] | undefined {\n const raw = op['x-mutually-exclusive-parameter-groups'];\n if (!raw || typeof raw !== 'object') return undefined;\n\n const paramByName = new Map<string, Parameter>();\n for (const p of allIRParams) {\n paramByName.set(p.name, p);\n }\n\n const groups: ParameterGroup[] = [];\n\n for (const [groupName, groupDef] of Object.entries(raw)) {\n if (!groupDef || typeof groupDef !== 'object') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: expected an object with \"optional\" and \"variants\".`,\n );\n }\n\n if (typeof groupDef.optional !== 'boolean') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.optional in ${operationContext}: expected a boolean.`,\n );\n }\n\n if (!groupDef.variants || typeof groupDef.variants !== 'object') {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants in ${operationContext}: expected an object mapping variant names to parameter name arrays.`,\n );\n }\n\n if (Object.keys(groupDef.variants).length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName} in ${operationContext}: group has zero variants.`,\n );\n }\n\n const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {\n if (!Array.isArray(paramNames) || paramNames.length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`,\n );\n }\n const parameters: Parameter[] = paramNames.map((pName) => {\n const irParam = paramByName.get(pName);\n if (!irParam) {\n throw new Error(\n `x-mutually-exclusive-parameter-groups.${groupName}.variants.${variantName} references parameter \"${pName}\" which does not exist in the operation's parameters[] (${operationContext}).`,\n );\n }\n return irParam;\n });\n return { name: variantName, parameters };\n });\n\n groups.push({\n name: groupName,\n optional: groupDef.optional,\n variants,\n });\n }\n\n return groups.length > 0 ? groups : undefined;\n}\n\n/**\n * Extract mutually-exclusive body parameter groups from the\n * `x-mutually-exclusive-body-groups` operation extension. Unlike query\n * parameter groups (whose parameters live in operation.queryParams), body\n * group parameters are synthetic — built from the oneOf variant schemas in\n * the request body. Emitters use the group's presence to generate sum-type\n * interfaces and custom JSON marshalling instead of flat optional fields.\n */\nfunction extractBodyParameterGroups(op: OperationObject, operationContext: string): ParameterGroup[] | undefined {\n const raw = op['x-mutually-exclusive-body-groups'];\n if (!raw || typeof raw !== 'object') return undefined;\n\n // Collect the body schema's oneOf variant fields so we can resolve types.\n // The body schema has been structurally rewritten to allOf: [base, { oneOf: [...] }]\n // by the spec generator; the variant properties live inside oneOf branches.\n const bodySchema = op.requestBody?.content?.['application/json']?.schema;\n const variantFieldSchemas = new Map<string, SchemaObject>();\n\n if (bodySchema) {\n // Walk allOf → oneOf → variant.properties to find all variant fields\n for (const sub of bodySchema.allOf ?? []) {\n for (const variant of sub.oneOf ?? []) {\n if (variant.properties) {\n for (const [name, fieldSchema] of Object.entries(variant.properties)) {\n if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);\n }\n }\n }\n }\n // Also check top-level oneOf (for inline schemas that aren't wrapped in allOf)\n for (const variant of bodySchema.oneOf ?? []) {\n if (variant.properties) {\n for (const [name, fieldSchema] of Object.entries(variant.properties)) {\n if (fieldSchema) variantFieldSchemas.set(name, fieldSchema);\n }\n }\n }\n }\n\n const groups: ParameterGroup[] = [];\n\n for (const [groupName, groupDef] of Object.entries(raw)) {\n if (!groupDef || typeof groupDef !== 'object') continue;\n if (typeof groupDef.optional !== 'boolean') continue;\n if (!groupDef.variants || typeof groupDef.variants !== 'object') continue;\n if (Object.keys(groupDef.variants).length === 0) continue;\n\n const variants = Object.entries(groupDef.variants).map(([variantName, paramNames]) => {\n if (!Array.isArray(paramNames) || paramNames.length === 0) {\n throw new Error(\n `Malformed x-mutually-exclusive-body-groups.${groupName}.variants.${variantName} in ${operationContext}: expected a non-empty array of parameter names.`,\n );\n }\n const parameters: Parameter[] = paramNames.map((pName) => {\n const fieldSchema = variantFieldSchemas.get(pName);\n const fieldType: TypeRef = fieldSchema\n ? schemaToTypeRef(fieldSchema, toPascalCase(pName))\n : { kind: 'primitive', type: 'string' };\n return {\n name: pName,\n type: fieldType,\n required: false, // group variant fields are always optional at the struct level\n description: fieldSchema?.description,\n };\n });\n return { name: variantName, parameters };\n });\n\n groups.push({\n name: groupName,\n optional: groupDef.optional,\n variants,\n });\n }\n\n return groups.length > 0 ? groups : undefined;\n}\n\nfunction buildOperation(\n method: HttpMethod,\n path: string,\n op: OperationObject,\n pathLevelParams: ParameterObject[],\n operationIdTransform?: (id: string) => string,\n serviceName?: string,\n componentSchemas?: Record<string, SchemaObject>,\n): { operation: Operation; inlineModels: Model[] } {\n const allParams = [...pathLevelParams, ...(op.parameters ?? [])];\n\n const hasIdempotencyHeader = allParams.some((p) => p.in === 'header' && p.name.toLowerCase() === 'idempotency-key');\n\n // Use the service name as context so inline parameter enums get qualified\n // names. e.g., service \"SSO\" + param \"provider\" → \"SSOProvider\".\n const opContext = serviceName;\n const pathParams = extractParams(allParams, 'path', opContext, componentSchemas);\n const queryParams = extractParams(allParams, 'query', opContext, componentSchemas);\n const headerParams = extractParams(allParams, 'header', opContext, componentSchemas).filter(\n (p) => p.name.toLowerCase() !== 'idempotency-key',\n );\n const cookieParams = extractParams(allParams, 'cookie', opContext, componentSchemas);\n\n const reqBodyModels: Model[] = [];\n const { body: requestBody, encoding: requestBodyEncoding } = extractRequestBody(op.requestBody, op, reqBodyModels);\n const {\n response,\n successResponses,\n errors,\n inlineModels,\n isPaginated,\n dataPath: responseDataPath,\n itemType: responseItemType,\n } = extractResponses(op.responses, op, path, method);\n inlineModels.push(...reqBodyModels);\n\n // Build structured pagination metadata from response classification and query param detection\n const paginationFromParams = detectPagination(response, queryParams, responseDataPath);\n let pagination: PaginationMeta | undefined;\n if (isPaginated) {\n const itemType = responseItemType ?? (response.kind === 'array' ? response.items : response);\n pagination = {\n strategy: paginationFromParams?.strategy ?? 'cursor',\n param: paginationFromParams?.param ?? 'after',\n limitParam: paginationFromParams?.limitParam,\n dataPath: responseDataPath ?? paginationFromParams?.dataPath,\n itemType,\n };\n } else if (paginationFromParams) {\n pagination = paginationFromParams;\n }\n\n // Extract per-operation security overrides\n const security = extractOperationSecurity(op.security);\n\n // Extract mutually-exclusive parameter groups (query/path/header/cookie)\n const allIRParams = [...pathParams, ...queryParams, ...headerParams, ...cookieParams];\n const opLabel = op.operationId ?? `${method.toUpperCase()} ${path}`;\n const queryParamGroups = extractParameterGroups(op, allIRParams, opLabel);\n\n // Extract mutually-exclusive body parameter groups\n const bodyParamGroups = extractBodyParameterGroups(op, opLabel);\n\n // Merge both sources into a single parameterGroups array\n const parameterGroups =\n queryParamGroups || bodyParamGroups ? [...(queryParamGroups ?? []), ...(bodyParamGroups ?? [])] : undefined;\n\n return {\n operation: {\n name: inferOperationName(method, path, op.operationId, operationIdTransform),\n description: buildDescription(op.summary, op.description),\n httpMethod: method,\n path,\n pathParams,\n queryParams,\n headerParams,\n cookieParams: cookieParams.length > 0 ? cookieParams : undefined,\n requestBody,\n requestBodyEncoding,\n response,\n successResponses,\n errors,\n pagination,\n injectIdempotencyKey: hasIdempotencyHeader,\n deprecated: op.deprecated || undefined,\n async: op['x-oagen-async'],\n security,\n parameterGroups,\n },\n inlineModels,\n };\n}\n\n/**\n * Extract per-operation security requirements from an OpenAPI security directive.\n * Returns undefined when the operation uses the spec-level default security.\n *\n * OpenAPI security format: `security: [{ schemeName: [scope1, scope2] }]`\n */\nfunction extractOperationSecurity(\n security: Array<Record<string, string[]>> | undefined,\n): SecurityRequirement[] | undefined {\n if (!security || security.length === 0) return undefined;\n\n const requirements: SecurityRequirement[] = [];\n for (const entry of security) {\n for (const [schemeName, scopes] of Object.entries(entry)) {\n requirements.push({ schemeName, scopes: scopes ?? [] });\n }\n }\n return requirements.length > 0 ? requirements : undefined;\n}\n\nfunction buildDescription(summary: string | undefined, description: string | undefined): string | undefined {\n if (summary && description && summary !== description) {\n return `${summary}\\n\\n${description}`;\n }\n return description ?? summary;\n}\n\nfunction extractParams(\n params: ParameterObject[],\n location: 'path' | 'query' | 'header' | 'cookie',\n operationContext?: string,\n componentSchemas?: Record<string, SchemaObject>,\n): Parameter[] {\n return params\n .filter((p) => p.in === location)\n .map((p) => {\n const refTarget = resolveParamSchemaRef(p.schema, componentSchemas);\n return {\n name: p.name,\n type: p.schema\n ? schemaToTypeRef(p.schema, p.name, operationContext ? toPascalCase(operationContext) : undefined)\n : ({ kind: 'primitive', type: 'string' } as TypeRef),\n required: p.required ?? false,\n description: p.description,\n deprecated: p.deprecated || p.schema?.deprecated || refTarget?.deprecated || undefined,\n default: p.schema?.default ?? refTarget?.default,\n example: p.example ?? p.schema?.example ?? refTarget?.example,\n style: p.style as Parameter['style'],\n explode: p.explode,\n };\n });\n}\n\n/**\n * If a parameter's schema is a `$ref` to `#/components/schemas/X`, return the\n * referenced component schema. Used to surface schema-level metadata (default,\n * example, deprecated) that wouldn't otherwise be visible at the param level.\n *\n * Refs are not pre-resolved by the bundler (`dereference: false` in refs.ts),\n * so without this, a param like `schema: { $ref: '.../PaginationOrder' }`\n * silently loses the target's `default: desc` and the SDK stops emitting the\n * spec-mandated default value in generated method signatures.\n */\nfunction resolveParamSchemaRef(\n schema: SchemaObject | undefined,\n componentSchemas: Record<string, SchemaObject> | undefined,\n): SchemaObject | undefined {\n if (!schema || !componentSchemas) return undefined;\n const ref = (schema as { $ref?: string }).$ref;\n if (!ref) return undefined;\n const match = /^#\\/components\\/schemas\\/(.+)$/.exec(ref);\n if (!match) return undefined;\n return componentSchemas[match[1]];\n}\n\nfunction extractRequestBody(\n body: RequestBodyObject | undefined,\n op: OperationObject | undefined,\n inlineModels: Model[],\n): { body?: TypeRef; encoding?: 'json' | 'form-data' | 'form-urlencoded' | 'binary' | 'text' } {\n if (!body?.content) return {};\n\n // Detect encoding and find schema from content type in priority order\n let encoding: 'json' | 'form-data' | 'form-urlencoded' | 'binary' | 'text' = 'json';\n let schema: SchemaObject | undefined;\n\n if (body.content['application/json']?.schema) {\n encoding = 'json';\n schema = body.content['application/json']!.schema;\n } else if (body.content['multipart/form-data']?.schema) {\n encoding = 'form-data';\n schema = body.content['multipart/form-data']!.schema;\n } else if (body.content['application/x-www-form-urlencoded']?.schema) {\n encoding = 'form-urlencoded';\n schema = body.content['application/x-www-form-urlencoded']!.schema;\n } else if (body.content['application/octet-stream']) {\n encoding = 'binary';\n schema = body.content['application/octet-stream']!.schema;\n } else if (body.content['text/plain']) {\n encoding = 'text';\n schema = body.content['text/plain']!.schema;\n }\n\n if (!schema) {\n // For binary/text, a schema is optional — produce a primitive TypeRef\n if (encoding === 'binary') {\n return { body: { kind: 'primitive', type: 'string', format: 'binary' }, encoding };\n }\n if (encoding === 'text') {\n return { body: { kind: 'primitive', type: 'string' }, encoding };\n }\n return {};\n }\n\n const rawName = op?.operationId\n ? toPascalCase(normalizeOperationIdForNaming(op.operationId)) + 'Request'\n : 'RequestBody';\n const contextName = cleanSchemaName(rawName);\n\n // If the request body is an inline object with properties, extract it as a model\n if (schema.properties && (schema.type === 'object' || !schema.type)) {\n const requiredSet = new Set(schema.required ?? []);\n const fields: Field[] = [];\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, contextName, requiredSet));\n }\n inlineModels.push({ name: contextName, description: undefined, fields });\n return { body: { kind: 'model', name: contextName }, encoding };\n }\n\n // If the request body is a oneOf, extract each variant as an inline model\n // and build a union type pointing to them by name.\n if (schema.oneOf) {\n const variants: TypeRef[] = [];\n\n for (const variant of schema.oneOf) {\n if (variant.$ref) {\n const ref = schemaToTypeRef(variant, contextName);\n variants.push(ref);\n } else if (variant.type === 'null') {\n // skip null variant in union, handle separately\n } else if (variant.properties && (variant.type === 'object' || !variant.type)) {\n const variantName = deriveOneOfVariantName(variant, contextName, inlineModels);\n const requiredSet = new Set(variant.required ?? []);\n const fields: Field[] = [];\n for (const [fieldName, fieldSchema] of Object.entries(variant.properties)) {\n if (!fieldSchema) continue;\n fields.push(buildFieldFromSchema(fieldName, fieldSchema, variantName, requiredSet));\n }\n inlineModels.push({ name: variantName, description: variant.description, fields });\n variants.push({ kind: 'model', name: variantName });\n } else {\n variants.push(schemaToTypeRef(variant, contextName));\n }\n }\n\n const hasNull = schema.oneOf.some(\n (v: SchemaObject) => v.type === 'null' || (Array.isArray(v.type) && v.type.includes('null')),\n );\n const union: TypeRef = {\n kind: 'union',\n variants,\n ...(schema.discriminator\n ? {\n discriminator: { property: schema.discriminator.propertyName, mapping: schema.discriminator.mapping ?? {} },\n }\n : {}),\n };\n const body = hasNull ? ({ kind: 'nullable', inner: union } as TypeRef) : union;\n return { body, encoding };\n }\n\n return { body: schemaToTypeRef(schema, contextName), encoding };\n}\n\n/** Derive a unique variant name for a oneOf inline model. */\nfunction deriveOneOfVariantName(variant: SchemaObject, baseName: string, existingModels: Model[]): string {\n // Try to use a distinguishing property (e.g., \"grant_type\" field's const/enum value)\n if (variant.properties) {\n for (const [, propSchema] of Object.entries(variant.properties)) {\n if (propSchema?.const && typeof propSchema.const === 'string') {\n return toPascalCase(propSchema.const) + baseName.replace(/Request$/, '') + 'Request';\n }\n }\n }\n // Fallback: append a numeric suffix\n const existingNames = new Set(existingModels.map((m) => m.name));\n let name = baseName;\n let suffix = 2;\n while (existingNames.has(name)) {\n name = `${baseName}${suffix}`;\n suffix++;\n }\n return name;\n}\n\nfunction deriveResponseName(op: OperationObject | undefined, path: string, method: HttpMethod): string {\n if (op?.operationId) {\n return cleanSchemaName(toPascalCase(normalizeOperationIdForNaming(op.operationId)) + 'Response');\n }\n const segments = path.split('/').filter(Boolean);\n const resource = segments[0] ?? 'Unknown';\n return toPascalCase(resource) + toPascalCase(method) + 'Response';\n}\n\nfunction extractResponses(\n responses?: Record<string, ResponseObject>,\n op?: OperationObject,\n path?: string,\n method?: HttpMethod,\n): {\n response: TypeRef;\n successResponses?: SuccessResponse[];\n errors: ErrorResponse[];\n inlineModels: Model[];\n isPaginated: boolean;\n dataPath?: string;\n itemType?: TypeRef;\n} {\n const errors: ErrorResponse[] = [];\n let response: TypeRef = { kind: 'primitive', type: 'string' };\n let inlineModels: Model[] = [];\n let isPaginated = false;\n let dataPath: string | undefined;\n let itemType: TypeRef | undefined;\n\n if (!responses) return { response, errors, inlineModels, isPaginated };\n\n const allSuccessResponses: SuccessResponse[] = [];\n\n for (const [statusCode, resp] of Object.entries(responses)) {\n const code = parseInt(statusCode, 10);\n\n if (code >= 200 && code < 300) {\n let extractedType: TypeRef = { kind: 'primitive', type: 'unknown' };\n const jsonContent = resp.content?.['application/json'];\n if (jsonContent?.schema) {\n const contextName = deriveResponseName(op, path ?? '/', method ?? 'get');\n const result = classifyAndExtractResponse(jsonContent.schema, contextName);\n extractedType = result.response;\n // Keep track of inline models and pagination from the latest 2xx with a schema\n inlineModels = result.inlineModels;\n isPaginated = result.isPaginated;\n dataPath = result.dataPath;\n itemType = result.itemType;\n } else if (resp.content) {\n // Handle non-JSON response content types (text/plain, binary, XML, etc.)\n if (resp.content['application/octet-stream'] || resp.content['application/pdf']) {\n extractedType = { kind: 'primitive', type: 'string', format: 'binary' };\n } else if (\n resp.content['text/plain'] ||\n resp.content['text/html'] ||\n resp.content['text/xml'] ||\n resp.content['application/xml']\n ) {\n extractedType = { kind: 'primitive', type: 'string' };\n } else {\n // Try the first available content type's schema\n const firstKey = Object.keys(resp.content)[0];\n if (firstKey) {\n const firstContent = resp.content[firstKey];\n if (firstContent?.schema) {\n extractedType = schemaToTypeRef(\n firstContent.schema,\n deriveResponseName(op, path ?? '/', method ?? 'get'),\n );\n }\n }\n }\n }\n allSuccessResponses.push({ statusCode: code, type: extractedType });\n } else if (code >= 300 && code < 400) {\n // 3xx redirects — include so emitter can detect redirect endpoints\n allSuccessResponses.push({ statusCode: code, type: { kind: 'primitive', type: 'unknown' } });\n } else if (code >= 400) {\n const jsonContent = resp.content?.['application/json'];\n const type = jsonContent?.schema ? schemaToTypeRef(jsonContent.schema, `Error${code}`) : undefined;\n errors.push({ statusCode: code, type });\n }\n }\n\n // Primary response = lowest 2xx with a body schema, falling back to first 2xx\n if (allSuccessResponses.length > 0) {\n const sorted = [...allSuccessResponses].sort((a, b) => a.statusCode - b.statusCode);\n const primary =\n sorted.find((r) => r.type.kind !== 'primitive' || (r.type as { type: string }).type !== 'unknown') ?? sorted[0];\n response = primary.type;\n }\n\n const successResponses = allSuccessResponses.length > 1 ? allSuccessResponses : undefined;\n\n return { response, successResponses, errors, inlineModels, isPaginated, dataPath, itemType };\n}\n","import type { Model, Service, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\n\nfunction keepLargestByName(models: Model[]): Model[] {\n const byName = new Map<string, Model>();\n for (const model of models) {\n const existing = byName.get(model.name);\n if (!existing || model.fields.length > existing.fields.length) {\n byName.set(model.name, model);\n }\n }\n return [...byName.values()];\n}\n\nfunction rewriteModelRef(ref: TypeRef, oldName: string, newName: string): void {\n walkTypeRef(ref, {\n model: (r) => {\n if (r.name === oldName) (r as { name: string }).name = newName;\n },\n });\n}\n\nfunction rewriteModelRefs(models: Model[], services: Service[], oldName: string, newName: string): void {\n for (const model of models) {\n for (const field of model.fields) {\n rewriteModelRef(field.type, oldName, newName);\n }\n }\n for (const service of services) {\n for (const op of service.operations) {\n rewriteModelRef(op.response, oldName, newName);\n if (op.requestBody) {\n rewriteModelRef(op.requestBody, oldName, newName);\n }\n }\n }\n}\n\nexport function mergeInlineResponseModels(schemaModels: Model[], inlineModels: Model[]): Model[] {\n const mergedSchemaModels = [...schemaModels];\n const schemaModelNames = new Set(mergedSchemaModels.map((m) => m.name));\n const schemaModelsByName = new Map(mergedSchemaModels.map((m) => [m.name, m]));\n\n const deduplicatedInlineModels = inlineModels.filter((model) => {\n if (!schemaModelNames.has(model.name)) return true;\n\n const existing = schemaModelsByName.get(model.name)!;\n const existingFieldNames = new Set(existing.fields.map((f) => f.name));\n const inlineFieldNames = new Set(model.fields.map((f) => f.name));\n const hasDifference =\n model.fields.some((f) => !existingFieldNames.has(f.name)) ||\n existing.fields.some((f) => !inlineFieldNames.has(f.name));\n\n if (hasDifference && model.fields.length > existing.fields.length) {\n const idx = mergedSchemaModels.indexOf(existing);\n if (idx !== -1) mergedSchemaModels[idx] = model;\n schemaModelsByName.set(model.name, model);\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has more fields than component schema (${model.fields.length} vs ${existing.fields.length}) — using inline response model`,\n );\n } else if (hasDifference) {\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has different fields than component schema — using component schema`,\n );\n }\n\n return false;\n });\n\n return [...mergedSchemaModels, ...keepLargestByName(deduplicatedInlineModels)];\n}\n\nexport function mergeFieldInlineModels(existingModels: Model[], fieldInlineModels: Model[]): Model[] {\n const modelNames = new Set(existingModels.map((m) => m.name));\n const modelsByName = new Map(existingModels.map((m) => [m.name, m]));\n\n const deduplicatedFieldModels = fieldInlineModels.filter((model) => {\n if (!modelNames.has(model.name)) return true;\n\n const existing = modelsByName.get(model.name)!;\n const existingFieldNames = new Set(existing.fields.map((f) => f.name));\n const inlineFieldNames = new Set(model.fields.map((f) => f.name));\n const hasDifference =\n model.fields.some((f) => !existingFieldNames.has(f.name)) ||\n existing.fields.some((f) => !inlineFieldNames.has(f.name));\n\n if (hasDifference) {\n console.warn(\n `[oagen] Warning: Inline model \"${model.name}\" has different fields than component schema — using component schema`,\n );\n }\n\n return false;\n });\n\n return [...existingModels, ...keepLargestByName(deduplicatedFieldModels)];\n}\n\nfunction hasModelConstDiscriminant(model: Model): boolean {\n return model.fields.some(\n (f) => (f.name === 'object' || f.name === 'type') && f.type.kind === 'literal' && typeof f.type.value === 'string',\n );\n}\n\nfunction isModelReferencedByOthers(name: string, models: Model[], excludeNames: Set<string>): boolean {\n for (const model of models) {\n if (excludeNames.has(model.name)) continue;\n for (const field of model.fields) {\n let found = false;\n walkTypeRef(field.type, {\n model: (r) => {\n if (r.name === name) found = true;\n },\n });\n if (found) return true;\n }\n }\n return false;\n}\n\nexport function collapseJsonSuffixModels(models: Model[], services: Service[]): Model[] {\n const normalizedModels = [...models];\n const byName = new Map(normalizedModels.map((m) => [m.name, m]));\n\n // Pass 1: collect merge candidates\n const mergeCandidates: Array<{ jsonModel: Model; baseModel: Model }> = [];\n for (const model of normalizedModels) {\n if (!model.name.endsWith('Json')) continue;\n\n const baseName = model.name.slice(0, -4);\n const baseModel = byName.get(baseName);\n if (!baseModel || model.fields.length <= baseModel.fields.length) continue;\n\n const isSuperset = baseModel.fields.every((f) => model.fields.some((mf) => mf.name === f.name));\n if (!isSuperset) continue;\n\n // Guard: both models have a const discriminant — they are distinct entities\n if (hasModelConstDiscriminant(model) && hasModelConstDiscriminant(baseModel)) continue;\n\n // Guard: a third model explicitly references the Json-suffix model\n if (isModelReferencedByOthers(model.name, normalizedModels, new Set([model.name, baseName]))) continue;\n\n mergeCandidates.push({ jsonModel: model, baseModel });\n }\n\n // Pass 2: apply merges\n const toRemove = new Set<string>();\n for (const { jsonModel, baseModel } of mergeCandidates) {\n baseModel.fields = jsonModel.fields;\n toRemove.add(jsonModel.name);\n rewriteModelRefs(normalizedModels, services, jsonModel.name, baseModel.name);\n console.warn(\n `[oagen] Merged \"${jsonModel.name}\" into \"${baseModel.name}\" (${jsonModel.fields.length} fields, superset)`,\n );\n }\n\n // Pass 3: cascade renames to inline children of collapsed Json-suffix models.\n // e.g. when AuditLogSchemaJson → AuditLogSchema, also rename\n // AuditLogSchemaJsonTarget → AuditLogSchemaTarget.\n for (const { jsonModel, baseModel } of mergeCandidates) {\n const jsonPrefix = jsonModel.name;\n const basePrefix = baseModel.name;\n\n for (const model of normalizedModels) {\n if (toRemove.has(model.name)) continue;\n if (model.name.length <= jsonPrefix.length) continue;\n if (!model.name.startsWith(jsonPrefix)) continue;\n\n const newName = basePrefix + model.name.slice(jsonPrefix.length);\n const existing = byName.get(newName);\n\n if (existing && !toRemove.has(existing.name)) {\n toRemove.add(model.name);\n rewriteModelRefs(normalizedModels, services, model.name, newName);\n console.warn(`[oagen] Collapsed child \"${model.name}\" into existing \"${newName}\"`);\n } else {\n rewriteModelRefs(normalizedModels, services, model.name, newName);\n model.name = newName;\n byName.set(newName, model);\n console.warn(`[oagen] Renamed child \"${jsonPrefix}…\" → \"${newName}\"`);\n }\n }\n }\n\n return normalizedModels.filter((m) => !toRemove.has(m.name));\n}\n","import type { Enum, Model, Service } from '../ir/types.js';\nimport { collectInlineEnumFromRef } from './schemas.js';\n\nexport function collectInlineEnumsFromModels(models: Model[], enums: Enum[]): void {\n const enumNames = new Set(enums.map((e) => e.name));\n for (const model of models) {\n for (const field of model.fields) {\n collectInlineEnumFromRef(field.type, enums, enumNames);\n }\n }\n}\n\n/**\n * Collect inline enum definitions from operation parameters (query, path, header)\n * and promote them to top-level enums so emitters can generate typed enum files.\n */\nexport function collectInlineEnumsFromOperations(services: Service[], enums: Enum[]): void {\n const enumNames = new Set(enums.map((e) => e.name));\n for (const service of services) {\n for (const op of service.operations) {\n for (const param of [...op.pathParams, ...op.queryParams, ...op.headerParams, ...(op.cookieParams ?? [])]) {\n collectInlineEnumFromRef(param.type, enums, enumNames);\n }\n }\n }\n}\n","import type { ApiSpec, TypeRef } from '../ir/types.js';\nimport { walkTypeRef } from '../ir/types.js';\n\nexport function validateModelRefs(spec: ApiSpec): void {\n const knownNames = new Set<string>();\n for (const m of spec.models) knownNames.add(m.name);\n for (const e of spec.enums) knownNames.add(e.name);\n\n function walkRef(ref: TypeRef, context: string): void {\n walkTypeRef(ref, {\n model: (r) => {\n if (!knownNames.has(r.name)) {\n console.warn(`[oagen] Warning: Unresolved model reference \"${r.name}\" (context: ${context})`);\n }\n },\n });\n }\n\n for (const model of spec.models) {\n for (const field of model.fields) {\n walkRef(field.type, `${model.name}.${field.name}`);\n }\n }\n\n for (const service of spec.services) {\n for (const op of service.operations) {\n for (const p of [...op.pathParams, ...op.queryParams, ...op.headerParams]) {\n walkRef(p.type, `${service.name}.${op.name}.${p.name}`);\n }\n if (op.requestBody) walkRef(op.requestBody, `${service.name}.${op.name}.requestBody`);\n walkRef(op.response, `${service.name}.${op.name}.response`);\n }\n }\n}\n","import type { ApiSpec, AuthScheme, ServerEntry } from '../ir/types.js';\nimport { defaultSdkBehavior } from '../ir/sdk-behavior.js';\nimport { SpecParseError } from '../errors.js';\nimport { loadAndBundleSpec } from './refs.js';\nimport { extractSchemas, extractInlineModelsFromSchemas, clearSchemaNameTransform } from './schemas.js';\nimport { extractOperations } from './operations.js';\nimport {\n mergeInlineResponseModels,\n collapseJsonSuffixModels,\n mergeFieldInlineModels,\n} from './normalize-inline-models.js';\nimport { collectInlineEnumsFromModels, collectInlineEnumsFromOperations } from './collect-inline-enums.js';\nimport { validateModelRefs } from './normalize-model-refs.js';\n\n/**\n * A bundled OpenAPI document, post-`$ref` resolution but pre-IR extraction.\n *\n * This is the shape the spec author wrote, with external refs inlined and\n * internal refs left intact. It is intentionally loose (`Record<string,\n * unknown>`) so `transformSpec` can reach arbitrary spec extensions without\n * fighting types — narrow with `as` at use sites.\n */\nexport type OpenApiDocument = Record<string, unknown>;\n\nexport interface ParseOptions {\n operationIdTransform?: (id: string) => string;\n schemaNameTransform?: (name: string) => string;\n /**\n * Domain-facing field-name overrides, keyed by IR model name then wire field\n * name: `{ Connection: { connection_type: 'type' } }`. Sets `Field.domainName`\n * so emitters expose the field under the friendlier name while keeping the\n * wire key. Language-agnostic — honored by any emitter that reads `domainName`.\n */\n fieldHints?: Record<string, Record<string, string>>;\n /**\n * Pre-IR overlay applied to the bundled OpenAPI document before any IR\n * extraction runs. Use this when the upstream spec can't be changed but you\n * need to patch around a spec quirk that would otherwise emit a breaking SDK\n * change — e.g. rewriting a path's response `$ref` back to its prior schema,\n * merging the new fields onto the prior schema, and dropping the fork.\n *\n * The function may mutate the document in place and return it, or return a\n * new object; the returned value is what the rest of oagen sees.\n *\n * Runs once, after `$ref` bundling and before schema/operation extraction.\n * If you need to inspect the resulting IR instead, post-process the\n * `ApiSpec` returned by `parseSpec`.\n */\n transformSpec?: (spec: OpenApiDocument) => OpenApiDocument;\n}\n\nexport async function parseSpec(specPath: string, options?: ParseOptions): Promise<ApiSpec> {\n const { parsed } = await loadAndBundleSpec(specPath);\n const transformed = options?.transformSpec ? options.transformSpec(parsed) : parsed;\n\n const spec = transformed as {\n openapi?: string;\n info?: { title?: string; version?: string; description?: string };\n servers?: Array<{ url?: string; description?: string }>;\n paths?: Record<string, unknown>;\n components?: {\n schemas?: Record<string, unknown>;\n securitySchemes?: Record<\n string,\n { type: string; scheme?: string; in?: string; name?: string; flows?: Record<string, unknown> }\n >;\n };\n };\n\n // Validate OpenAPI version\n const version = spec.openapi ?? '';\n if (!version.startsWith('3.')) {\n throw new SpecParseError(\n `Unsupported OpenAPI version: ${version}. oagen requires OpenAPI 3.x`,\n `Update the spec to OpenAPI 3.0 or 3.1. If you are using Swagger 2.x, convert it first with \\`npx swagger2openapi ${specPath}\\`.`,\n );\n }\n\n const { models, enums } = extractSchemas(\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n { schemaNameTransform: options?.schemaNameTransform },\n );\n\n const { services, inlineModels } = extractOperations(\n spec.paths as Record<string, Record<string, unknown>> | undefined,\n options?.operationIdTransform,\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n );\n\n const responseNormalizedModels = mergeInlineResponseModels(models, inlineModels);\n\n // Extract inline models from model field definitions (objects/arrays with properties).\n // schemaNameTransform is kept active so inline child names use the\n // transformed parent name (e.g. AuditLogSchemaJson→AuditLogSchema yields\n // AuditLogSchemaTarget, not AuditLogSchemaJsonTarget).\n const fieldInlineModels = extractInlineModelsFromSchemas(\n spec.components?.schemas as Record<string, Record<string, unknown>> | undefined,\n );\n clearSchemaNameTransform();\n const fieldMergedModels = mergeFieldInlineModels(responseNormalizedModels, fieldInlineModels);\n const finalModels = collapseJsonSuffixModels(fieldMergedModels, services);\n applyFieldHints(finalModels, options?.fieldHints);\n collectInlineEnumsFromModels(finalModels, enums);\n collectInlineEnumsFromOperations(services, enums);\n\n const auth = extractAuthSchemes(spec.components?.securitySchemes);\n\n const serverEntries: ServerEntry[] = (spec.servers ?? [])\n .map((s) => ({ url: s.url ?? '', description: s.description }))\n .filter((s) => s.url);\n\n const result: ApiSpec = {\n name: spec.info?.title ?? 'Unknown API',\n version: spec.info?.version ?? '0.0.0',\n description: spec.info?.description,\n baseUrl: serverEntries[0]?.url ?? '',\n servers: serverEntries.length > 0 ? serverEntries : undefined,\n services,\n models: finalModels,\n enums,\n auth,\n sdk: defaultSdkBehavior(),\n };\n\n validateModelRefs(result);\n\n return result;\n}\n/**\n * Apply `fieldHints` onto the built models, setting `Field.domainName` for each\n * matching (model name, wire field name) pair. Serialization still uses\n * `Field.name`; only the domain-facing identifier changes.\n */\nfunction applyFieldHints(\n models: import('../ir/types.js').Model[],\n fieldHints: Record<string, Record<string, string>> | undefined,\n): void {\n if (!fieldHints) return;\n for (const model of models) {\n const hints = fieldHints[model.name];\n if (!hints) continue;\n for (const field of model.fields) {\n const domainName = hints[field.name];\n if (domainName) field.domainName = domainName;\n }\n }\n}\n\n/** Extract authentication schemes from OpenAPI securitySchemes. */\nfunction extractAuthSchemes(\n securitySchemes?: Record<\n string,\n { type: string; scheme?: string; in?: string; name?: string; flows?: Record<string, unknown> }\n >,\n): AuthScheme[] | undefined {\n if (!securitySchemes) return undefined;\n const schemes: AuthScheme[] = [];\n for (const [, scheme] of Object.entries(securitySchemes)) {\n if (scheme.type === 'http' && scheme.scheme === 'bearer') {\n schemes.push({ kind: 'bearer' });\n } else if (scheme.type === 'apiKey' && scheme.in && scheme.name) {\n schemes.push({ kind: 'apiKey', in: scheme.in as 'header' | 'query' | 'cookie', name: scheme.name });\n } else if (scheme.type === 'oauth2' && scheme.flows) {\n schemes.push({ kind: 'oauth2', flows: scheme.flows });\n }\n }\n return schemes.length > 0 ? schemes : undefined;\n}\n","import type { Operation, TypeRef } from '../ir/types.js';\nimport { assertNever } from '../ir/types.js';\n\nexport interface OperationPlan {\n operation: Operation;\n isDelete: boolean;\n hasBody: boolean;\n isIdempotentPost: boolean;\n pathParamsInOptions: boolean;\n isPaginated: boolean;\n responseModelName: string | null;\n /** For paginated operations, the model name of individual list items\n * (unwrapped from the list wrapper). Null for non-paginated. */\n paginatedItemModelName: string | null;\n isModelResponse: boolean;\n /** True when the response is an unpaginated `type: array` of models.\n * Emitters should use this to return `Model[]` (or the language's list\n * equivalent) and map the deserializer over each element. */\n isArrayResponse: boolean;\n hasQueryParams: boolean;\n isAsync: boolean;\n}\n\nexport function planOperation(op: Operation): OperationPlan {\n const isDelete = op.httpMethod === 'delete';\n const hasBody = !!op.requestBody;\n const isIdempotentPost = op.injectIdempotencyKey && op.httpMethod === 'post';\n const hasQueryParams = op.queryParams.length > 0;\n const pathParamsInOptions = op.pathParams.length > 1 || (op.pathParams.length > 0 && (hasBody || hasQueryParams));\n const isPaginated = op.pagination !== undefined;\n const responseModelName = resolveResponseModelName(op);\n const paginatedItemModelName =\n isPaginated && op.pagination?.itemType.kind === 'model' ? op.pagination.itemType.name : null;\n const isModelResponse = responseModelName !== null;\n // Unpaginated `type: array` of models — needs `Model[]` return + elementwise\n // deserialization. Paginated operations use the pagination wrapper instead.\n const isArrayResponse = !isPaginated && op.response.kind === 'array' && op.response.items.kind === 'model';\n const isAsync = op.async ?? true;\n\n return {\n operation: op,\n isDelete,\n hasBody,\n isIdempotentPost,\n pathParamsInOptions,\n isPaginated,\n responseModelName,\n paginatedItemModelName,\n isModelResponse,\n isArrayResponse,\n hasQueryParams,\n isAsync,\n };\n}\n\nexport function resolveResponseModelName(op: Operation): string | null {\n if (op.httpMethod === 'delete') return null;\n return extractModelName(op.response);\n}\n\nfunction extractModelName(ref: TypeRef): string | null {\n switch (ref.kind) {\n case 'model':\n return ref.name;\n case 'array':\n return ref.items.kind === 'model' ? ref.items.name : null;\n case 'nullable':\n return extractModelName(ref.inner);\n case 'union': {\n const firstModel = ref.variants.find((v) => v.kind === 'model');\n return firstModel && firstModel.kind === 'model' ? firstModel.name : null;\n }\n case 'map':\n case 'enum':\n case 'primitive':\n case 'literal':\n return null;\n default:\n return assertNever(ref);\n }\n}\n","import type { ApiSpec, Enum, Field, Model, TypeRef } from '../ir/types.js';\n\n/**\n * Builds illustrative example values for IR types. Used by snippet emitters\n * to produce realistic argument values in call-site samples.\n *\n * Values prefer, in order:\n * 1. An explicit `example` carried on the field/param.\n * 2. The `default` from the schema.\n * 3. The first enum value, when the type is an enum.\n * 4. A type-driven default (e.g. `\"string_example\"`, `1`, `true`).\n *\n * Recursion through models/arrays/maps is depth-limited; cyclic models\n * collapse to a placeholder object rather than blowing the stack.\n */\nexport interface ExampleBuilder {\n /** Build an example value for a single type reference (no field metadata). */\n forType(type: TypeRef): unknown;\n /** Build an example value for a field, honoring its `example`/`default`. */\n forField(field: Field): unknown;\n /** Build an example object from a model, keyed by field wire name. */\n forModel(model: Model | string): Record<string, unknown>;\n}\n\nconst MAX_DEPTH = 6;\n\nexport function createExampleBuilder(spec: ApiSpec): ExampleBuilder {\n const modelsByName = new Map<string, Model>();\n for (const m of spec.models) modelsByName.set(m.name, m);\n const enumsByName = new Map<string, Enum>();\n for (const e of spec.enums) enumsByName.set(e.name, e);\n\n function buildForType(type: TypeRef, depth: number): unknown {\n if (depth > MAX_DEPTH) return null;\n\n switch (type.kind) {\n case 'primitive':\n return primitiveExample(type.type, type.format);\n case 'literal':\n return type.value;\n case 'enum': {\n if (type.values && type.values.length > 0) return type.values[0];\n const e = enumsByName.get(type.name);\n return e?.values[0]?.value ?? null;\n }\n case 'array':\n return [buildForType(type.items, depth + 1)];\n case 'nullable':\n return buildForType(type.inner, depth);\n case 'union': {\n const first = type.variants[0];\n return first ? buildForType(first, depth) : null;\n }\n case 'map': {\n const key = 'key';\n const value = buildForType(type.valueType, depth + 1);\n return { [key]: value };\n }\n case 'model':\n return buildForModel(type.name, depth + 1);\n default:\n return null;\n }\n }\n\n function buildForModel(nameOrModel: string | Model, depth: number): Record<string, unknown> {\n if (depth > MAX_DEPTH) return {};\n const model = typeof nameOrModel === 'string' ? modelsByName.get(nameOrModel) : nameOrModel;\n if (!model) return {};\n\n const result: Record<string, unknown> = {};\n for (const field of model.fields) {\n if (field.deprecated || field.readOnly) continue;\n result[field.name] = buildForField(field, depth);\n }\n return result;\n }\n\n function buildForField(field: Field, depth: number): unknown {\n if (field.example !== undefined) return field.example;\n if (field.default !== undefined) return field.default;\n return buildForType(field.type, depth);\n }\n\n return {\n forType: (type) => buildForType(type, 0),\n forField: (field) => buildForField(field, 0),\n forModel: (model) => buildForModel(model, 0),\n };\n}\n\nfunction primitiveExample(type: string, format?: string): unknown {\n switch (type) {\n case 'string':\n if (format === 'date-time') return '2026-01-15T12:00:00.000Z';\n if (format === 'date') return '2026-01-15';\n if (format === 'email') return 'user@example.com';\n if (format === 'uri' || format === 'url') return 'https://example.com';\n if (format === 'uuid') return '00000000-0000-0000-0000-000000000000';\n return 'string_example';\n case 'integer':\n case 'number':\n return 1;\n case 'boolean':\n return true;\n case 'unknown':\n default:\n return null;\n }\n}\n","import type { GeneratedFile, EmitterContext } from '../engine/types.js';\nimport type { ResolvedOperation } from '../ir/operation-hints.js';\nimport { createExampleBuilder } from './example-builder.js';\nimport type { SnippetEmitter, SnippetResult } from './types.js';\n\n/**\n * Run one or more snippet emitters over every resolved operation in the spec.\n *\n * Iteration order matches `ctx.resolvedOperations`. For each operation the\n * runner asks every emitter to render once; emitters that return `null`\n * contribute nothing for that op (the URL-builder / unsupported case).\n *\n * Returns a flat list of {@link SnippetResult}. Consumers map these to\n * file paths according to their own layout — see\n * {@link snippetResultsToFiles} for a convenience that writes\n * `<outputDir>/<language>/<methodName>-request.<ext>`.\n */\nexport function runSnippetEmitters(emitters: SnippetEmitter[], ctx: EmitterContext): SnippetResult[] {\n const resolved = ctx.resolvedOperations;\n if (!resolved || resolved.length === 0) return [];\n\n const examples = createExampleBuilder(ctx.spec);\n const results: SnippetResult[] = [];\n\n for (const op of resolved) {\n for (const emitter of emitters) {\n const content = emitter.renderOperation(op, ctx, examples);\n if (content === null) continue;\n results.push({\n language: emitter.language,\n fileExtension: emitter.fileExtension,\n operationId: operationIdFor(op),\n mountTarget: op.mountOn,\n methodName: op.methodName,\n content: ensureTrailingNewline(content),\n });\n }\n }\n\n return results;\n}\n\n/**\n * Convenience: turn snippet results into oagen-style {@link GeneratedFile}s\n * under `<outputDir>/<language>/<methodName>-request.<extension>`.\n *\n * Useful for consumers wired into the standard oagen file-writing pipeline.\n * Docs builds that already have their own per-tag file layout (e.g.\n * `content/reference/{tag}/_code/...`) typically skip this helper and route\n * `SnippetResult.operationId` / `mountTarget` through their own mapping.\n */\nexport function snippetResultsToFiles(results: SnippetResult[], outputDir = 'snippets'): GeneratedFile[] {\n return results.map((r) => ({\n path: `${outputDir}/${r.language}/${r.methodName}-request.${r.fileExtension}`,\n content: r.content,\n overwriteExisting: true,\n integrateTarget: false,\n }));\n}\n\nfunction operationIdFor(op: ResolvedOperation): string {\n return `${op.mountOn}.${op.methodName}`;\n}\n\nfunction ensureTrailingNewline(s: string): string {\n return s.endsWith('\\n') ? s : `${s}\\n`;\n}\n","import type { EmitterContext } from '../engine/types.js';\nimport type { ResolvedOperation, ResolvedWrapper } from '../ir/operation-hints.js';\nimport type { Field, Model, Parameter } from '../ir/types.js';\nimport { toSnakeCase } from '../utils/naming.js';\nimport type { ExampleBuilder } from './example-builder.js';\n\n/**\n * One argument resolved for a call-site snippet. The {@link wireName} stays\n * in the spec's casing so each language emitter can apply its own\n * field/param casing rules (snake_case for Python/Ruby/PHP, PascalCase for\n * Go/.NET, etc.).\n *\n * Path and query params carry their {@link Parameter} so emitters can pick\n * language-specific safe names; body args carry their {@link Field} so\n * emitters can read field-level metadata (deprecated, type details).\n */\nexport interface SnippetArg {\n /** 'path' | 'body' | 'query' — used by emitters to pick a casing rule. */\n source: 'path' | 'body' | 'query';\n /** Spec wire name (e.g. `domain_data`, `client_id`). */\n wireName: string;\n /** Pre-computed illustrative value (string, number, array, object, ...). */\n value: unknown;\n /** Original parameter for path/query args, null for body fields. */\n parameter: Parameter | null;\n /** Original field for body args, null for path/query params. */\n field: Field | null;\n}\n\n/**\n * Resolve the set of required arguments for a snippet. Body fields are\n * expanded from the request body model; defaults / inferFromClient fields\n * are filtered out (they're injected by the SDK, not the caller).\n *\n * Iteration order: path params, then required body fields, then required\n * query params. Wire-name collisions between body and path are reported in\n * {@link collisionNames} so the emitter can rename whichever side it\n * prefers (e.g. prefix body field with `body_`).\n */\nexport interface CollectedArgs {\n args: SnippetArg[];\n /** Body field wire names that also appear as path params. */\n collisionNames: Set<string>;\n}\n\nexport function collectSnippetArgs(\n resolved: ResolvedOperation,\n ctx: EmitterContext,\n examples: ExampleBuilder,\n): CollectedArgs {\n const op = resolved.operation;\n const hidden = hiddenParamSet(resolved);\n const args: SnippetArg[] = [];\n const pathWireNames = new Set<string>();\n\n for (const p of op.pathParams) {\n if (!p.required) continue;\n if (hidden.has(p.name)) continue;\n pathWireNames.add(p.name);\n args.push({\n source: 'path',\n wireName: p.name,\n value: exampleForParam(p, examples),\n parameter: p,\n field: null,\n });\n }\n\n const collisionNames = new Set<string>();\n const bodyWireNames = new Set<string>();\n if (op.requestBody?.kind === 'model') {\n const bodyModel = findModel(ctx, op.requestBody.name);\n if (bodyModel) {\n for (const f of bodyModel.fields) {\n if (!f.required || f.deprecated) continue;\n if (hidden.has(f.name)) continue;\n if (pathWireNames.has(f.name)) collisionNames.add(f.name);\n bodyWireNames.add(f.name);\n args.push({\n source: 'body',\n wireName: f.name,\n value: exampleForField(f, examples),\n parameter: null,\n field: f,\n });\n }\n }\n }\n\n for (const q of op.queryParams) {\n if (!q.required) continue;\n if (hidden.has(q.name)) continue;\n // Some operations (e.g. OAuth-style token endpoints) accept the same field\n // via both the query string and the request body. The IR keeps both for\n // wire-format fidelity, but a call site must pass each argument only once,\n // so skip a query param already emitted as a body field. A query param\n // that merely shares a path param's name is left intact: path args are\n // positional and never share the options object, so there is no clash to\n // resolve (path/body collisions are handled separately via collisionNames).\n if (bodyWireNames.has(q.name)) continue;\n args.push({\n source: 'query',\n wireName: q.name,\n value: exampleForParam(q, examples),\n parameter: q,\n field: null,\n });\n }\n\n return { args, collisionNames };\n}\n\n/**\n * Build the arg list for a single split (wrapper) variant. The wrapper's\n * `exposedParams` is the contract; fields are looked up on the variant model\n * by exact name and then snake-case-normalized name. Optional status comes\n * from `wrapper.optionalParams` first, then from the field's `required` flag.\n */\nexport function collectWrapperArgs(\n wrapper: ResolvedWrapper,\n ctx: EmitterContext,\n examples: ExampleBuilder,\n): SnippetArg[] {\n const variantModel = ctx.spec.models.find((m) => m.name === wrapper.targetVariant);\n const variantFields = variantModel?.fields ?? [];\n const optionalSet = new Set(wrapper.optionalParams);\n const args: SnippetArg[] = [];\n\n for (const paramName of wrapper.exposedParams) {\n const field =\n variantFields.find((f) => f.name === paramName || toSnakeCase(f.name) === toSnakeCase(paramName)) ?? null;\n const isOptional = optionalSet.has(paramName) ? true : field ? !field.required : false;\n if (isOptional) continue;\n args.push({\n source: 'body',\n wireName: paramName,\n value: field ? examples.forField(field) : 'string_example',\n parameter: null,\n field,\n });\n }\n\n return args;\n}\n\nexport function hiddenParamSet(resolved: ResolvedOperation): Set<string> {\n const hidden = new Set<string>();\n for (const k of Object.keys(resolved.defaults)) hidden.add(k);\n for (const k of resolved.inferFromClient) hidden.add(k);\n return hidden;\n}\n\nfunction findModel(ctx: EmitterContext, name: string): Model | undefined {\n return ctx.spec.models.find((m) => m.name === name);\n}\n\nfunction exampleForParam(p: Parameter, examples: ExampleBuilder): unknown {\n if (p.example !== undefined) return p.example;\n if (p.default !== undefined) return p.default;\n return examples.forType(p.type);\n}\n\nfunction exampleForField(f: Field, examples: ExampleBuilder): unknown {\n return examples.forField(f);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuLA,SAAgB,qBAAkC;AAChD,QAAO;EACL,OAAO;GACL,sBAAsB;IAAC;IAAK;IAAK;IAAK;IAAK;IAAI;GAC/C,YAAY;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