@contractkit/openapi-to-ck 0.10.2 → 0.11.0

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.
Files changed (41) hide show
  1. package/.turbo/turbo-build$colon$ci.log +7 -7
  2. package/.turbo/turbo-test$colon$ci.log +30 -26
  3. package/CHANGELOG.md +109 -0
  4. package/README.md +30 -8
  5. package/dist/ast-to-ck.d.ts +32 -16
  6. package/dist/ast-to-ck.d.ts.map +1 -1
  7. package/dist/{chunk-JPI3AQ7V.js → chunk-Z53MK4FM.js} +196 -390
  8. package/dist/chunk-Z53MK4FM.js.map +1 -0
  9. package/dist/convert.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/normalize.d.ts +6 -2
  12. package/dist/normalize.d.ts.map +1 -1
  13. package/dist/paths-to-ast.d.ts +2 -0
  14. package/dist/paths-to-ast.d.ts.map +1 -1
  15. package/dist/plugin.d.ts.map +1 -1
  16. package/dist/plugin.js +18 -3
  17. package/dist/plugin.js.map +1 -1
  18. package/dist/schema-to-ast.d.ts +13 -1
  19. package/dist/schema-to-ast.d.ts.map +1 -1
  20. package/dist/tag-splitter.d.ts.map +1 -1
  21. package/dist/types.d.ts +28 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/package.json +4 -5
  24. package/src/ast-to-ck.ts +29 -453
  25. package/src/convert.ts +57 -3
  26. package/src/normalize.ts +87 -11
  27. package/src/paths-to-ast.ts +92 -11
  28. package/src/plugin.ts +17 -2
  29. package/src/schema-to-ast.ts +51 -7
  30. package/src/tag-splitter.ts +21 -16
  31. package/src/types.ts +28 -0
  32. package/tests/__snapshots__/kitchen-sink.ck +102 -0
  33. package/tests/ast-to-ck.test.ts +34 -17
  34. package/tests/component-refs.test.ts +114 -0
  35. package/tests/coverage.test.ts +246 -0
  36. package/tests/error-responses.test.ts +94 -0
  37. package/tests/fixtures/kitchen-sink-3.1.json +100 -0
  38. package/tests/helpers.ts +40 -0
  39. package/tests/kitchen-sink.test.ts +116 -0
  40. package/tests/schema-to-ast.test.ts +11 -2
  41. package/dist/chunk-JPI3AQ7V.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/normalize.ts","../src/circular-refs.ts","../src/schema-to-ast.ts","../src/paths-to-ast.ts","../src/tag-splitter.ts","../src/ast-to-ck.ts","../src/convert.ts","../src/warnings.ts"],"sourcesContent":["import type { NormalizedDocument } from './types.js';\nimport type { WarningCollector } from './warnings.js';\n\n/**\n * Detects the OpenAPI version from a parsed document and normalizes it to a\n * 3.1-like shape. Swagger 2.0 and OpenAPI 3.0 documents are transformed\n * so that downstream code only needs to handle one schema dialect.\n *\n * The transformation is hand-written. An earlier note here claimed `@scalar/openapi-parser`'s\n * `upgrade()` did the heavy lifting; it never did, and that dependency has been dropped.\n *\n * After version normalization, `dereferenceComponents` inlines `$ref`s to reusable non-schema\n * components, so the rest of the pipeline sees only inline parameter, response, request-body and\n * header objects. Schema `$ref`s are deliberately left intact — they become `.ck` model refs.\n */\nexport function normalize(doc: Record<string, unknown>, warnings: WarningCollector): NormalizedDocument {\n const version = detectVersion(doc);\n\n const normalized =\n version === '2.0'\n ? normalizeSwagger2(doc, warnings)\n : version === '3.0'\n ? normalizeOas30(doc as unknown as NormalizedDocument, warnings)\n : // 3.1+ — already in target shape\n (doc as unknown as NormalizedDocument);\n\n dereferenceComponents(normalized, warnings);\n return normalized;\n}\n\n// ─── Component $ref inlining ──────────────────────────────────────────────\n\n/** The component sections whose `$ref`s are inlined. `schemas` is deliberately absent. */\nconst DEREF_SECTIONS = ['parameters', 'requestBodies', 'responses', 'headers'] as const;\n\n/** Guards against a `$ref` chain that loops back on itself. */\nconst MAX_REF_DEPTH = 10;\n\n/**\n * Inline `$ref`s to reusable non-schema components.\n *\n * Only `#/components/schemas/*` refs survive conversion — they become `.ck` model references.\n * Everything else (`parameters`, `requestBodies`, `responses`, `headers`) has no `.ck`\n * counterpart, and nothing downstream resolves it: a `$ref`'d parameter used to reach\n * `parameterToNode` with no `name` and print as `undefined: string`, which *parses*, so the\n * corruption was silent. Resolving here means the rest of the pipeline only ever sees inline\n * objects.\n *\n * Sibling keys are kept and win over the target's, matching how OpenAPI 3.1 treats a `$ref`\n * alongside other properties.\n */\nfunction dereferenceComponents(doc: NormalizedDocument, warnings: WarningCollector): void {\n const components = doc.components as Record<string, Record<string, unknown>> | undefined;\n\n const resolve = (node: unknown, path: string, depth = 0): unknown => {\n if (!node || typeof node !== 'object') return node;\n if (Array.isArray(node)) return node.map(item => resolve(item, path, depth));\n\n const obj = node as Record<string, unknown>;\n const ref = obj.$ref;\n if (typeof ref === 'string') {\n const match = /^#\\/components\\/([^/]+)\\/(.+)$/.exec(ref);\n const section = match?.[1];\n // Schema refs are the ones that survive into `.ck`; leave them for `extractRefName`.\n if (section && section !== 'schemas' && (DEREF_SECTIONS as readonly string[]).includes(section)) {\n if (depth >= MAX_REF_DEPTH) {\n warnings.warn(path, `$ref chain too deep to resolve: ${ref}`);\n return obj;\n }\n const target = components?.[section]?.[decodeRefToken(match[2]!)];\n if (target === undefined) {\n warnings.warn(path, `unresolved $ref '${ref}' — the component is not defined`);\n return obj;\n }\n const siblings = { ...obj };\n delete siblings.$ref;\n const resolved = resolve(target, path, depth + 1);\n return { ...(resolved as Record<string, unknown>), ...siblings };\n }\n return obj;\n }\n\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n // A schema subtree can hold `$ref`s of its own, all of them schema refs.\n out[key] = key === 'schema' || key === 'schemas' ? value : resolve(value, `${path}/${key}`, depth);\n }\n return out;\n };\n\n for (const [path, pathItem] of Object.entries(doc.paths ?? {})) {\n doc.paths![path] = resolve(pathItem, `#/paths/${path}`) as typeof pathItem;\n }\n}\n\n/** Undo the `~1`/`~0` escaping a JSON pointer uses for `/` and `~`. */\nfunction decodeRefToken(token: string): string {\n return decodeURIComponent(token).replace(/~1/g, '/').replace(/~0/g, '~');\n}\n\nfunction detectVersion(doc: Record<string, unknown>): '2.0' | '3.0' | '3.1' {\n if (typeof doc.swagger === 'string' && doc.swagger.startsWith('2')) return '2.0';\n if (typeof doc.openapi === 'string') {\n if (doc.openapi.startsWith('3.0')) return '3.0';\n }\n return '3.1';\n}\n\n// ─── Swagger 2.0 → 3.1 ───────────────────────────────────────────────────\n\nfunction normalizeSwagger2(doc: Record<string, unknown>, warnings: WarningCollector): NormalizedDocument {\n const info = (doc.info as Record<string, unknown>) ?? { title: 'Untitled', version: '0.0.0' };\n const basePath = (doc.basePath as string) ?? '';\n const schemes = (doc.schemes as string[]) ?? ['https'];\n const host = (doc.host as string) ?? 'localhost';\n const globalConsumes = (doc.consumes as string[]) ?? ['application/json'];\n const globalProduces = (doc.produces as string[]) ?? ['application/json'];\n\n const result: NormalizedDocument = {\n openapi: '3.1.0',\n info: {\n title: (info.title as string) ?? 'Untitled',\n version: (info.version as string) ?? '0.0.0',\n description: info.description as string | undefined,\n },\n servers: [{ url: `${schemes[0]}://${host}${basePath}` }],\n paths: {},\n components: {\n schemas: {},\n securitySchemes: {},\n },\n tags: (doc.tags as NormalizedDocument['tags']) ?? [],\n };\n\n // Convert definitions → components/schemas\n const definitions = (doc.definitions as Record<string, unknown>) ?? {};\n for (const [name, schema] of Object.entries(definitions)) {\n result.components!.schemas![name] = normalizeNullable30(schema as Record<string, unknown>);\n }\n\n // Convert securityDefinitions → components/securitySchemes\n const secDefs = (doc.securityDefinitions as Record<string, unknown>) ?? {};\n for (const [name, scheme] of Object.entries(secDefs)) {\n result.components!.securitySchemes![name] = convertSecurityScheme2(scheme as Record<string, unknown>);\n }\n\n // Convert paths\n const paths = (doc.paths as Record<string, Record<string, unknown>>) ?? {};\n for (const [path, pathItem] of Object.entries(paths)) {\n result.paths![path] = normalizePathItem2(pathItem, globalConsumes, globalProduces, warnings);\n }\n\n // Global security\n if (doc.security) {\n result.security = doc.security as Record<string, string[]>[];\n }\n\n return result;\n}\n\nfunction normalizePathItem2(\n pathItem: Record<string, unknown>,\n globalConsumes: string[],\n globalProduces: string[],\n warnings: WarningCollector,\n): Record<string, unknown> {\n const methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];\n const normalized: Record<string, unknown> = {};\n\n // Path-level parameters\n const pathParams = (pathItem.parameters as unknown[]) ?? [];\n\n for (const method of methods) {\n const op = pathItem[method] as Record<string, unknown> | undefined;\n if (!op) continue;\n\n const opConsumes = (op.consumes as string[]) ?? globalConsumes;\n const opProduces = (op.produces as string[]) ?? globalProduces;\n const params = [...pathParams, ...((op.parameters as unknown[]) ?? [])];\n\n // Separate body params from others\n const nonBodyParams: unknown[] = [];\n let requestBody: Record<string, unknown> | undefined;\n\n for (const param of params as Record<string, unknown>[]) {\n if (param.in === 'body') {\n const contentType = opConsumes[0] ?? 'application/json';\n requestBody = {\n description: param.description,\n required: param.required ?? true,\n content: {\n [contentType]: {\n schema: normalizeNullable30((param.schema as Record<string, unknown>) ?? {}),\n },\n },\n };\n } else if (param.in === 'formData') {\n warnings.info(`#/paths/${encodePathSegment(method)}`, 'formData parameters converted to multipart/form-data requestBody');\n // Collect formData params into a schema\n if (!requestBody) {\n requestBody = {\n content: {\n 'multipart/form-data': {\n schema: { type: 'object', properties: {}, required: [] as string[] },\n },\n },\n };\n }\n const formSchema = (requestBody.content as Record<string, Record<string, unknown>>)['multipart/form-data']!.schema as Record<\n string,\n unknown\n >;\n const props = formSchema.properties as Record<string, unknown>;\n props[param.name as string] = normalizeNullable30(param as Record<string, unknown>);\n if (param.required) {\n (formSchema.required as string[]).push(param.name as string);\n }\n } else {\n // Convert param schema\n const normalizedParam = { ...param };\n if (param.type) {\n normalizedParam.schema = normalizeNullable30({\n type: param.type,\n format: param.format,\n enum: param.enum,\n items: param.items,\n default: param.default,\n minimum: param.minimum,\n maximum: param.maximum,\n minLength: param.minLength,\n maxLength: param.maxLength,\n pattern: param.pattern,\n } as Record<string, unknown>);\n delete normalizedParam.type;\n delete normalizedParam.format;\n delete normalizedParam.enum;\n delete normalizedParam.items;\n }\n nonBodyParams.push(normalizedParam);\n }\n }\n\n // Convert responses\n const responses: Record<string, unknown> = {};\n const opResponses = (op.responses as Record<string, Record<string, unknown>>) ?? {};\n for (const [code, resp] of Object.entries(opResponses)) {\n const contentType = opProduces[0] ?? 'application/json';\n const headers = convertResponseHeaders2(resp.headers as Record<string, Record<string, unknown>> | undefined);\n const responseEntry: Record<string, unknown> = {\n description: resp.description ?? '',\n };\n if (resp.schema) {\n responseEntry.content = {\n [contentType]: {\n schema: normalizeNullable30(resp.schema as Record<string, unknown>),\n },\n };\n }\n if (headers) {\n responseEntry.headers = headers;\n }\n responses[code] = responseEntry;\n }\n\n normalized[method] = {\n operationId: op.operationId,\n summary: op.summary,\n description: op.description,\n tags: op.tags,\n parameters: nonBodyParams.length > 0 ? nonBodyParams : undefined,\n requestBody,\n responses,\n security: op.security,\n deprecated: op.deprecated,\n };\n }\n\n return normalized;\n}\n\n/**\n * Convert Swagger 2.0 response headers to a 3.x-shaped Header Object map.\n * 2.0 stores `type`/`format`/`items` inline on the header; 3.x wraps the same fields under `schema`.\n */\nfunction convertResponseHeaders2(\n headers: Record<string, Record<string, unknown>> | undefined,\n): Record<string, Record<string, unknown>> | undefined {\n if (!headers) return undefined;\n const out: Record<string, Record<string, unknown>> = {};\n for (const [name, header] of Object.entries(headers)) {\n if (!header || typeof header !== 'object') continue;\n const { description, type, format, items, ...rest } = header;\n const schema: Record<string, unknown> = { ...rest };\n if (type !== undefined) schema.type = type;\n if (format !== undefined) schema.format = format;\n if (items !== undefined) schema.items = items;\n const normalized: Record<string, unknown> = {};\n if (description !== undefined) normalized.description = description;\n if (Object.keys(schema).length > 0) normalized.schema = normalizeNullable30(schema);\n out[name] = normalized;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nfunction convertSecurityScheme2(scheme: Record<string, unknown>): unknown {\n const type = scheme.type as string;\n if (type === 'basic') {\n return { type: 'http', scheme: 'basic' };\n }\n if (type === 'apiKey') {\n return { type: 'apiKey', name: scheme.name, in: scheme.in };\n }\n if (type === 'oauth2') {\n const flow = scheme.flow as string;\n const flows: Record<string, unknown> = {};\n if (flow === 'implicit') {\n flows.implicit = { authorizationUrl: scheme.authorizationUrl, scopes: scheme.scopes ?? {} };\n } else if (flow === 'password') {\n flows.password = { tokenUrl: scheme.tokenUrl, scopes: scheme.scopes ?? {} };\n } else if (flow === 'application') {\n flows.clientCredentials = { tokenUrl: scheme.tokenUrl, scopes: scheme.scopes ?? {} };\n } else if (flow === 'accessCode') {\n flows.authorizationCode = {\n authorizationUrl: scheme.authorizationUrl,\n tokenUrl: scheme.tokenUrl,\n scopes: scheme.scopes ?? {},\n };\n }\n return { type: 'oauth2', flows };\n }\n return scheme;\n}\n\n// ─── OpenAPI 3.0 → 3.1 ───────────────────────────────────────────────────\n\nfunction normalizeOas30(doc: NormalizedDocument, _warnings: WarningCollector): NormalizedDocument {\n // Walk all schemas and convert `nullable: true` to type arrays\n if (doc.components?.schemas) {\n for (const [name, schema] of Object.entries(doc.components.schemas)) {\n doc.components.schemas[name] = normalizeNullable30(schema as Record<string, unknown>);\n }\n }\n\n // Walk paths and normalize inline schemas\n if (doc.paths) {\n for (const pathItem of Object.values(doc.paths)) {\n normalizePathItemSchemas(pathItem as Record<string, unknown>);\n }\n }\n\n doc.openapi = '3.1.0';\n return doc;\n}\n\nfunction normalizePathItemSchemas(pathItem: Record<string, unknown>): void {\n const methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];\n for (const method of methods) {\n const op = pathItem[method] as Record<string, unknown> | undefined;\n if (!op) continue;\n\n // Normalize parameter schemas\n const params = (op.parameters as Record<string, unknown>[]) ?? [];\n for (const param of params) {\n if (param.schema) {\n param.schema = normalizeNullable30(param.schema as Record<string, unknown>);\n }\n }\n\n // Normalize requestBody schemas\n const reqBody = op.requestBody as Record<string, unknown> | undefined;\n if (reqBody?.content) {\n for (const mediaType of Object.values(reqBody.content as Record<string, Record<string, unknown>>)) {\n if (mediaType.schema) {\n mediaType.schema = normalizeNullable30(mediaType.schema as Record<string, unknown>);\n }\n }\n }\n\n // Normalize response schemas\n const responses = (op.responses as Record<string, Record<string, unknown>>) ?? {};\n for (const resp of Object.values(responses)) {\n if (resp.content) {\n for (const mediaType of Object.values(resp.content as Record<string, Record<string, unknown>>)) {\n if (mediaType.schema) {\n mediaType.schema = normalizeNullable30(mediaType.schema as Record<string, unknown>);\n }\n }\n }\n }\n }\n}\n\n/**\n * Recursively converts OAS 3.0 `nullable: true` to OAS 3.1 `type: [T, \"null\"]`.\n * Also normalizes nested schemas (properties, items, allOf, etc.).\n */\nfunction normalizeNullable30(schema: Record<string, unknown>): Record<string, unknown> {\n if (!schema || typeof schema !== 'object') return schema;\n\n const result = { ...schema };\n\n // Convert nullable: true → type array with null\n if (result.nullable === true && typeof result.type === 'string') {\n result.type = [result.type, 'null'];\n delete result.nullable;\n }\n\n // Convert $ref alongside other properties (OAS 3.0 $ref with siblings was invalid,\n // but OAS 3.1 allows it — no conversion needed, just keep walking)\n\n // Recurse into nested schemas\n if (result.properties && typeof result.properties === 'object') {\n const props = result.properties as Record<string, Record<string, unknown>>;\n for (const [key, val] of Object.entries(props)) {\n props[key] = normalizeNullable30(val);\n }\n }\n if (result.items && typeof result.items === 'object' && !Array.isArray(result.items)) {\n result.items = normalizeNullable30(result.items as Record<string, unknown>);\n }\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = normalizeNullable30(result.additionalProperties as Record<string, unknown>);\n }\n for (const combiner of ['allOf', 'oneOf', 'anyOf'] as const) {\n if (Array.isArray(result[combiner])) {\n result[combiner] = (result[combiner] as Record<string, unknown>[]).map(normalizeNullable30);\n }\n }\n\n return result;\n}\n\nfunction encodePathSegment(s: string): string {\n return s.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n","/**\n * Detects circular $ref chains in OpenAPI schema definitions.\n * Returns the set of schema names that participate in cycles.\n * These should be wrapped in `lazy()` in the output .ck.\n */\nexport function detectCircularRefs(schemas: Record<string, unknown>): Set<string> {\n const circular = new Set<string>();\n const visiting = new Set<string>(); // current DFS path\n const visited = new Set<string>(); // fully explored\n\n function visit(name: string): void {\n if (visited.has(name)) return;\n if (visiting.has(name)) {\n circular.add(name);\n return;\n }\n\n visiting.add(name);\n const schema = schemas[name];\n if (schema && typeof schema === 'object') {\n for (const ref of collectRefs(schema as Record<string, unknown>)) {\n const refName = extractRefName(ref);\n if (refName && schemas[refName]) {\n visit(refName);\n }\n }\n }\n visiting.delete(name);\n visited.add(name);\n }\n\n for (const name of Object.keys(schemas)) {\n visit(name);\n }\n\n return circular;\n}\n\n/**\n * Recursively collects all $ref strings from a schema object.\n */\nfunction collectRefs(obj: Record<string, unknown>): string[] {\n const refs: string[] = [];\n\n function walk(val: unknown): void {\n if (!val || typeof val !== 'object') return;\n if (Array.isArray(val)) {\n for (const item of val) walk(item);\n return;\n }\n const record = val as Record<string, unknown>;\n if (typeof record.$ref === 'string') {\n refs.push(record.$ref);\n }\n for (const v of Object.values(record)) {\n walk(v);\n }\n }\n\n walk(obj);\n return refs;\n}\n\n/**\n * Extracts the schema name from a $ref like \"#/components/schemas/Foo\"\n * or \"#/definitions/Foo\" (Swagger 2.0 after normalization still uses components).\n */\nexport function extractRefName(ref: string): string | undefined {\n const match = ref.match(/^#\\/(?:components\\/schemas|definitions)\\/(.+)$/);\n return match?.[1];\n}\n","import type { ContractTypeNode, ScalarTypeNode, ModelNode, FieldNode, SourceLocation } from '@contractkit/core';\nimport type { NormalizedSchema } from './types.js';\nimport { extractRefName } from './circular-refs.js';\nimport type { WarningCollector } from './warnings.js';\n\n// ─── Conversion Context ───────────────────────────────────────────────────\n\nexport interface SchemaContext {\n /** Schema names involved in circular references — see {@link insideModel}. */\n circularRefs: Set<string>;\n /**\n * Whether the type being built sits inside a `contract` body. Default `true`.\n *\n * `lazy()` exists to break a definition cycle: `topoSortModels` in the TypeScript plugin\n * emits dependencies before dependents and can only fall back to source order for a cycle,\n * so a reference from one cycle member to another has to be deferred. A reference from an\n * operation — a response body, request body, param, or response header — is not part of any\n * such cycle: it names a model the generated module has already imported and fully\n * evaluated. Wrapping it achieves nothing and makes every contract importing a\n * self-referential schema noisier than it needs to be.\n */\n insideModel: boolean;\n /** Warning collector for unsupported features. */\n warnings: WarningCollector;\n /** Current JSON pointer path (for warnings). */\n path: string;\n /** Whether to include descriptions. */\n includeComments: boolean;\n /** All named schemas (for inline extraction). */\n namedSchemas: Record<string, NormalizedSchema>;\n /** Extracted inline models (accumulated during conversion). */\n extractedModels: ModelNode[];\n /** Counter for generating unique names for inline models. */\n inlineCounter: number;\n}\n\nconst LOC: SourceLocation = { file: '', line: 0 };\n\n// ─── Format → Scalar Name Mapping ────────────────────────────────────────\n\nconst FORMAT_TO_SCALAR: Record<string, ScalarTypeNode['name']> = {\n email: 'email',\n 'idn-email': 'email',\n uri: 'url',\n 'uri-reference': 'url',\n iri: 'url',\n 'iri-reference': 'url',\n url: 'url',\n uuid: 'uuid',\n date: 'date',\n 'date-time': 'datetime',\n time: 'time',\n duration: 'duration',\n binary: 'binary',\n int64: 'bigint',\n};\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/**\n * Convert all named schemas in components/schemas to ModelNodes.\n */\nexport function schemasToModels(schemas: Record<string, NormalizedSchema>, ctx: SchemaContext): ModelNode[] {\n const models: ModelNode[] = [];\n\n for (const [name, schema] of Object.entries(schemas)) {\n const modelCtx = { ...ctx, path: `#/components/schemas/${name}` };\n const model = schemaToModel(name, schema, modelCtx);\n if (model) models.push(model);\n }\n\n // Append any inline models extracted during conversion\n models.push(...ctx.extractedModels);\n\n return models;\n}\n\n/**\n * Convert a named schema to a ModelNode.\n */\nfunction schemaToModel(name: string, schema: NormalizedSchema, ctx: SchemaContext): ModelNode | null {\n warnUnsupported(schema, ctx);\n\n const description = ctx.includeComments ? schema.description : undefined;\n\n // allOf with exactly 2 members, one being a $ref → inheritance\n if (schema.allOf && schema.allOf.length === 2) {\n const [first, second] = schema.allOf;\n const refMember = first?.$ref ? first : second?.$ref ? second : null;\n const objectMember = first?.$ref ? second : first;\n\n if (refMember?.$ref && objectMember?.properties) {\n const baseName = extractRefName(refMember.$ref);\n if (baseName) {\n const fields = schemaPropertiesToFields(objectMember, ctx);\n return {\n kind: 'model',\n name,\n bases: [baseName],\n fields,\n description,\n loc: LOC,\n };\n }\n }\n }\n\n // Object with properties → struct\n if (schema.properties || (schema.type === 'object' && !schema.additionalProperties)) {\n const fields = schemaPropertiesToFields(schema, ctx);\n return {\n kind: 'model',\n name,\n fields,\n // `additionalProperties: true` says unknown keys are allowed, which is `mode(loose)`.\n // `false` and absent both match `.ck`'s `strict` default, so neither needs a mode.\n ...(schema.additionalProperties === true ? { mode: 'loose' as const } : {}),\n description,\n loc: LOC,\n };\n }\n\n // Otherwise → type alias\n const typeNode = schemaToTypeNode(schema, ctx);\n return {\n kind: 'model',\n name,\n fields: [],\n type: typeNode,\n description,\n loc: LOC,\n };\n}\n\n/**\n * Convert an OpenAPI schema to a ContractTypeNode.\n */\nexport function schemaToTypeNode(schema: NormalizedSchema, ctx: SchemaContext): ContractTypeNode {\n warnUnrepresentableConstraints(schema, ctx);\n\n // $ref\n if (schema.$ref) {\n const refName = extractRefName(schema.$ref);\n if (refName) {\n if (ctx.insideModel && ctx.circularRefs.has(refName)) {\n return { kind: 'lazy', inner: { kind: 'ref', name: refName } };\n }\n return { kind: 'ref', name: refName };\n }\n ctx.warnings.warn(ctx.path, `Unresolvable $ref: ${schema.$ref}`);\n return { kind: 'scalar', name: 'unknown' };\n }\n\n // const\n if (schema.const !== undefined) {\n return { kind: 'literal', value: schema.const as string | number | boolean };\n }\n\n // enum\n if (schema.enum) {\n return { kind: 'enum', values: schema.enum.map(String) };\n }\n\n // oneOf / anyOf → union (or discriminatedUnion when discriminator.propertyName is set)\n if (schema.oneOf && schema.oneOf.length > 0) {\n if (schema.discriminator?.propertyName) {\n return toDiscriminatedUnion(schema.oneOf, schema.discriminator.propertyName, ctx);\n }\n return toUnion(schema.oneOf, ctx);\n }\n if (schema.anyOf && schema.anyOf.length > 0) {\n if (schema.discriminator?.propertyName) {\n return toDiscriminatedUnion(schema.anyOf, schema.discriminator.propertyName, ctx);\n }\n return toUnion(schema.anyOf, ctx);\n }\n\n // allOf → intersection\n if (schema.allOf && schema.allOf.length > 0) {\n if (schema.allOf.length === 1) {\n return schemaToTypeNode(schema.allOf[0]!, ctx);\n }\n return {\n kind: 'intersection',\n members: schema.allOf.map(s => schemaToTypeNode(s, ctx)),\n };\n }\n\n // Handle nullable type arrays: [string, null] → nullable\n const types = normalizeTypeField(schema);\n\n if (types === null) {\n // No type information at all\n if (schema.properties) {\n return schemaToInlineObject(schema, ctx);\n }\n return { kind: 'scalar', name: 'unknown' };\n }\n\n const { baseType, nullable } = types;\n\n let typeNode: ContractTypeNode;\n\n switch (baseType) {\n case 'string':\n typeNode = stringSchemaToType(schema);\n break;\n case 'integer':\n typeNode = integerSchemaToType(schema);\n break;\n case 'number':\n typeNode = numberSchemaToType(schema);\n break;\n case 'boolean':\n typeNode = { kind: 'scalar', name: 'boolean' };\n break;\n case 'null':\n typeNode = { kind: 'scalar', name: 'null' };\n break;\n case 'array':\n typeNode = arraySchemaToType(schema, ctx);\n break;\n case 'object':\n typeNode = objectSchemaToType(schema, ctx);\n break;\n default:\n ctx.warnings.warn(ctx.path, `Unknown type: ${baseType}`);\n typeNode = { kind: 'scalar', name: 'unknown' };\n }\n\n if (nullable) {\n return { kind: 'union', members: [typeNode, { kind: 'scalar', name: 'null' }] };\n }\n\n return typeNode;\n}\n\n// ─── Type-Specific Converters ─────────────────────────────────────────────\n\nfunction stringSchemaToType(schema: NormalizedSchema): ContractTypeNode {\n // Check format first\n if (schema.format) {\n const scalarName = FORMAT_TO_SCALAR[schema.format];\n if (scalarName) {\n return { kind: 'scalar', name: scalarName };\n }\n }\n\n const mods: Partial<ScalarTypeNode> = {};\n if (schema.minLength !== undefined && schema.maxLength !== undefined && schema.minLength === schema.maxLength) {\n mods.len = schema.minLength;\n } else {\n if (schema.minLength !== undefined) mods.min = schema.minLength;\n if (schema.maxLength !== undefined) mods.max = schema.maxLength;\n }\n if (schema.pattern) mods.regex = schema.pattern;\n if (schema.format && !FORMAT_TO_SCALAR[schema.format]) mods.format = schema.format;\n\n return { kind: 'scalar', name: 'string', ...mods };\n}\n\nfunction integerSchemaToType(schema: NormalizedSchema): ContractTypeNode {\n const name: ScalarTypeNode['name'] = schema.format === 'int64' ? 'bigint' : 'int';\n const mods: Partial<ScalarTypeNode> = {};\n if (schema.minimum !== undefined) mods.min = schema.minimum;\n if (schema.maximum !== undefined) mods.max = schema.maximum;\n return { kind: 'scalar', name, ...mods };\n}\n\nfunction numberSchemaToType(schema: NormalizedSchema): ContractTypeNode {\n const mods: Partial<ScalarTypeNode> = {};\n if (schema.minimum !== undefined) mods.min = schema.minimum;\n if (schema.maximum !== undefined) mods.max = schema.maximum;\n return { kind: 'scalar', name: 'number', ...mods };\n}\n\nfunction arraySchemaToType(schema: NormalizedSchema, ctx: SchemaContext): ContractTypeNode {\n // Tuple: prefixItems (OAS 3.1)\n if (schema.prefixItems && schema.prefixItems.length > 0) {\n return {\n kind: 'tuple',\n items: schema.prefixItems.map(s => schemaToTypeNode(s, ctx)),\n };\n }\n\n const item = schema.items ? schemaToTypeNode(schema.items, ctx) : { kind: 'scalar' as const, name: 'unknown' as const };\n const mods: { min?: number; max?: number } = {};\n if (schema.minItems !== undefined) mods.min = schema.minItems;\n if (schema.maxItems !== undefined) mods.max = schema.maxItems;\n\n return { kind: 'array', item, ...mods };\n}\n\nfunction objectSchemaToType(schema: NormalizedSchema, ctx: SchemaContext): ContractTypeNode {\n // Record type: additionalProperties with no named properties\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object' && !schema.properties) {\n return {\n kind: 'record',\n key: { kind: 'scalar', name: 'string' },\n value: schemaToTypeNode(schema.additionalProperties, ctx),\n };\n }\n\n // Object with properties → inline object or extracted model\n if (schema.properties) {\n return schemaToInlineObject(schema, ctx);\n }\n\n // Empty object\n return { kind: 'scalar', name: 'object' };\n}\n\nfunction schemaToInlineObject(schema: NormalizedSchema, ctx: SchemaContext): ContractTypeNode {\n const fields = schemaPropertiesToFields(schema, ctx);\n return { kind: 'inlineObject', fields };\n}\n\n// ─── Field Conversion ─────────────────────────────────────────────────────\n\nfunction schemaPropertiesToFields(schema: NormalizedSchema, ctx: SchemaContext): FieldNode[] {\n const properties = schema.properties ?? {};\n const required = new Set(schema.required ?? []);\n const fields: FieldNode[] = [];\n\n for (const [name, propSchema] of Object.entries(properties)) {\n const propCtx = { ...ctx, path: `${ctx.path}/properties/${name}` };\n const fieldType = schemaToTypeNode(propSchema, propCtx);\n\n // Determine nullable from the type (if it's a union with null)\n let nullable = false;\n let effectiveType = fieldType;\n if (fieldType.kind === 'union') {\n const nonNull = fieldType.members.filter(m => !(m.kind === 'scalar' && m.name === 'null'));\n if (nonNull.length < fieldType.members.length) {\n nullable = true;\n effectiveType = nonNull.length === 1 ? nonNull[0]! : { kind: 'union', members: nonNull };\n }\n }\n\n const visibility = propSchema.readOnly ? ('readonly' as const) : propSchema.writeOnly ? ('writeonly' as const) : ('normal' as const);\n\n fields.push({\n name,\n optional: !required.has(name),\n nullable,\n visibility,\n type: effectiveType,\n default: propSchema.default as string | number | boolean | undefined,\n deprecated: propSchema.deprecated,\n description: ctx.includeComments ? propSchema.description : undefined,\n loc: LOC,\n });\n }\n\n return fields;\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────────\n\nfunction normalizeTypeField(schema: NormalizedSchema): { baseType: string; nullable: boolean } | null {\n if (!schema.type) return null;\n\n if (typeof schema.type === 'string') {\n return { baseType: schema.type, nullable: false };\n }\n\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const nonNull = types.filter(t => t !== 'null');\n const nullable = types.includes('null');\n if (nonNull.length === 1) {\n return { baseType: nonNull[0]!, nullable };\n }\n // Multiple non-null types — unusual but handle gracefully\n if (nonNull.length === 0) {\n return { baseType: 'null', nullable: false };\n }\n // Multiple types → treat as unknown\n return { baseType: nonNull[0]!, nullable };\n }\n\n return null;\n}\n\nfunction toUnion(schemas: NormalizedSchema[], ctx: SchemaContext): ContractTypeNode {\n const members = schemas.map(s => schemaToTypeNode(s, ctx));\n if (members.length === 1) return members[0]!;\n return { kind: 'union', members };\n}\n\nfunction toDiscriminatedUnion(schemas: NormalizedSchema[], discriminator: string, ctx: SchemaContext): ContractTypeNode {\n const members = schemas.map(s => schemaToTypeNode(s, ctx));\n if (members.length === 1) return members[0]!;\n return { kind: 'discriminatedUnion', discriminator, members };\n}\n\n/** JSON Schema keywords with no `.ck` counterpart, warned about rather than silently dropped. */\nconst UNREPRESENTABLE_KEYWORDS = ['exclusiveMinimum', 'exclusiveMaximum', 'multipleOf', 'uniqueItems'] as const;\n\nfunction warnUnsupported(schema: NormalizedSchema, ctx: SchemaContext): void {\n if (schema.xml) ctx.warnings.warn(ctx.path, 'xml metadata is not supported, skipping');\n if (schema.externalDocs) ctx.warnings.info(ctx.path, 'externalDocs is not supported, skipping');\n if (schema.not) ctx.warnings.warn(ctx.path, 'not keyword is not supported, skipping');\n}\n\n/**\n * Report constraints `.ck` has no vocabulary for.\n *\n * Its scalar and array arguments are `min`, `max`, `len`, `regex` and `format`. Folding\n * `exclusiveMinimum` into `min=` would be an off-by-one lie and `multipleOf` has no analogue at\n * all, so the constraint is reported as lost rather than approximated.\n */\nfunction warnUnrepresentableConstraints(schema: NormalizedSchema, ctx: SchemaContext): void {\n for (const keyword of UNREPRESENTABLE_KEYWORDS) {\n if (schema[keyword] !== undefined) ctx.warnings.warn(ctx.path, `${keyword} has no .ck equivalent, dropping the constraint`);\n }\n}\n\n/**\n * Extract a named model from an inline object schema (used for request/response bodies).\n */\nexport function extractInlineModel(\n schema: NormalizedSchema,\n suggestedName: string,\n ctx: SchemaContext,\n): { typeNode: ContractTypeNode; model?: ModelNode } {\n // If it's a $ref, just use the ref\n if (schema.$ref) {\n return { typeNode: schemaToTypeNode(schema, ctx) };\n }\n\n // If it's an object with properties, extract as a named model\n if (schema.properties || (schema.type === 'object' && schema.additionalProperties === undefined)) {\n // The extracted model is a `contract` body like any other, so references inside it are\n // subject to the same ordering problem an authored one would be.\n const fields = schemaPropertiesToFields(schema, { ...ctx, insideModel: true });\n const model: ModelNode = {\n kind: 'model',\n name: suggestedName,\n fields,\n description: ctx.includeComments ? schema.description : undefined,\n loc: LOC,\n };\n return {\n typeNode: { kind: 'ref', name: suggestedName },\n model,\n };\n }\n\n // Otherwise return the type node directly\n return { typeNode: schemaToTypeNode(schema, ctx) };\n}\n\n/**\n * Sanitize an OpenAPI schema name to a valid .ck identifier (PascalCase).\n */\nexport function sanitizeName(name: string, warnings: WarningCollector): string {\n // Replace dots, hyphens, spaces, and other invalid chars with word boundaries\n const cleaned = name\n .replace(/[^a-zA-Z0-9_$]/g, ' ')\n .split(/\\s+/)\n .filter(Boolean)\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n\n // `identStart` excludes digits, so a schema named \"3DModel\" would sanitize to something the\n // parser rejects. Prefix rather than drop the digit, which would collide names.\n const safe = /^[0-9]/.test(cleaned) ? `_${cleaned}` : cleaned;\n\n if (safe !== name) {\n warnings.info(`#/components/schemas/${name}`, `Schema name sanitized: \"${name}\" → \"${safe}\"`);\n }\n\n return safe || 'UnnamedSchema';\n}\n","import type {\n OpRouteNode,\n OpOperationNode,\n OpParamNode,\n OpRequestNode,\n OpResponseNode,\n OpResponseBodyNode,\n OpResponseHeaderNode,\n HttpMethod,\n ModelNode,\n SourceLocation,\n SecurityNode,\n} from '@contractkit/core';\nimport type {\n NormalizedDocument,\n NormalizedPathItem,\n NormalizedOperation,\n NormalizedParameter,\n NormalizedRequestBody,\n NormalizedResponse,\n} from './types.js';\nimport { schemaToTypeNode, extractInlineModel } from './schema-to-ast.js';\nimport type { SchemaContext } from './schema-to-ast.js';\nimport type { WarningCollector } from './warnings.js';\n\nconst LOC: SourceLocation = { file: '', line: 0 };\n\n/** A plain `type/subtype`, which is all `mimeType` in the grammar accepts. */\nconst MIME_RE = /^[a-z0-9][a-z0-9.+_-]*\\/[a-z0-9][a-z0-9.+_-]*$/i;\n\n/**\n * Reduce a summary to something `nameText` can hold.\n *\n * `nameText = (~(\"\\n\" | \"}\" | \" #\" | \"\\t#\") any)+` — the value runs to end of line and stops at\n * a closing brace or a whitespace-preceded `#`. An OpenAPI summary respects none of that, and an\n * unsanitized one would mis-parse the rest of the operation.\n */\nfunction toNameText(summary: string): string {\n return summary\n .replace(/[}#]/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n}\nconst HTTP_METHODS: HttpMethod[] = ['get', 'post', 'put', 'patch', 'delete'];\n\n/** Methods a spec may declare that `httpMethod` in the grammar has no keyword for. */\nconst UNSUPPORTED_METHODS = ['head', 'options', 'trace'] as const;\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\nexport interface PathsContext {\n circularRefs: Set<string>;\n warnings: WarningCollector;\n includeComments: boolean;\n namedSchemas: Record<string, unknown>;\n /** Accumulates inline models extracted from request/response bodies. */\n extractedModels: ModelNode[];\n /** Global security from the spec (for detecting explicit overrides). */\n globalSecurity?: Record<string, string[]>[];\n /** How bodied 4xx/5xx responses are imported. See `ConvertOptions.errorResponses`. */\n errorResponses: 'documented' | 'emitted';\n}\n\n/**\n * Convert OpenAPI paths to OpRouteNode[].\n * Returns routes along with a tag mapping for each route.\n */\nexport function pathsToRoutes(doc: NormalizedDocument, ctx: PathsContext): { routes: OpRouteNode[]; routeTags: Map<OpRouteNode, string> } {\n const routes: OpRouteNode[] = [];\n const routeTags = new Map<OpRouteNode, string>();\n const paths = doc.paths ?? {};\n\n for (const [path, pathItem] of Object.entries(paths)) {\n if (!pathItem) continue;\n const result = pathItemToRoute(path, pathItem, ctx);\n if (result) {\n routes.push(result.route);\n routeTags.set(result.route, result.tag);\n }\n }\n\n return { routes, routeTags };\n}\n\n// ─── Path Item → Route ───────────────────────────────────────────────────\n\nfunction pathItemToRoute(path: string, pathItem: NormalizedPathItem, ctx: PathsContext): { route: OpRouteNode; tag: string } | null {\n const operations: OpOperationNode[] = [];\n let primaryTag = 'default';\n\n // Collect path-level parameters\n const pathParams = (pathItem.parameters ?? []).filter(p => p.in === 'path');\n\n for (const method of UNSUPPORTED_METHODS) {\n // A grammar limitation, not a converter one — `.ck` has no keyword for these verbs.\n if ((pathItem as Record<string, unknown>)[method]) {\n ctx.warnings.warn(`#/paths/${encodePathSegment(path)}/${method}`, `\\`${method}\\` operations have no .ck equivalent; dropped`);\n }\n }\n\n for (const method of HTTP_METHODS) {\n const op = pathItem[method];\n if (!op) continue;\n\n const opNode = operationToNode(method, op, path, ctx);\n operations.push(opNode);\n\n // Use first tag of first operation as the route's tag\n if (op.tags && op.tags.length > 0 && primaryTag === 'default') {\n primaryTag = op.tags[0]!;\n }\n }\n\n if (operations.length === 0) return null;\n\n // Build params from path-level + inferred from path template\n const params = buildPathParams(path, pathParams, pathItem, ctx);\n\n const route: OpRouteNode = {\n path,\n operations,\n loc: LOC,\n };\n\n if (params.length > 0) {\n route.params = { kind: 'params', nodes: params };\n }\n\n if (pathItem.description && ctx.includeComments) {\n route.description = pathItem.description;\n }\n\n return { route, tag: primaryTag };\n}\n\n// ─── Operation → Node ─────────────────────────────────────────────────────\n\nfunction operationToNode(method: HttpMethod, op: NormalizedOperation, path: string, ctx: PathsContext): OpOperationNode {\n const pathPrefix = `#/paths/${encodePathSegment(path)}/${method}`;\n const schemaCtx = makeSchemaCtx(ctx, pathPrefix);\n\n const node: OpOperationNode = {\n method,\n responses: [],\n loc: LOC,\n };\n\n // operationId → sdk\n if (op.operationId) {\n node.sdk = op.operationId;\n }\n\n // summary → `name:`, the human-readable label the key exists for. `description` stays the\n // doc comment; when only a summary is given it becomes the name and is not doubled as prose.\n if (op.summary) {\n const name = toNameText(op.summary);\n if (name) node.name = name;\n else ctx.warnings.warn(`${pathPrefix}/summary`, 'summary has no content `.ck` can carry as a name; dropped');\n }\n\n // Description\n if (op.description && ctx.includeComments) {\n node.description = op.description;\n }\n\n // Deprecated\n if (op.deprecated) {\n node.modifiers = ['deprecated'];\n }\n\n // Query and header parameters\n const queryParams: OpParamNode[] = [];\n const headerParams: OpParamNode[] = [];\n\n for (const param of op.parameters ?? []) {\n // `dereferenceComponents` inlines `#/components/parameters/*` before this runs, so a\n // parameter with no name is one nothing could resolve. Emitting it would print\n // `undefined: string`, which parses — silent corruption is worse than a dropped param.\n if (!param?.name) {\n ctx.warnings.warn(`${pathPrefix}/parameters`, 'skipped a parameter with no name (an unresolved $ref?)');\n continue;\n }\n if (param.in === 'query') {\n queryParams.push(parameterToNode(param, schemaCtx));\n } else if (param.in === 'header') {\n headerParams.push(parameterToNode(param, schemaCtx));\n } else if (param.in === 'cookie') {\n ctx.warnings.warn(`${pathPrefix}/parameters/${param.name}`, 'cookie parameters have no `.ck` equivalent; dropped');\n }\n }\n\n if (queryParams.length > 0) {\n node.query = { kind: 'params', nodes: queryParams };\n }\n if (headerParams.length > 0) {\n node.headers = { kind: 'params', nodes: headerParams };\n }\n\n // Request body\n if (op.requestBody) {\n node.request = requestBodyToNode(op.requestBody, op.operationId ?? `${method}${toPascalCase(path)}`, schemaCtx, ctx);\n }\n\n // Responses\n const responses = op.responses ?? {};\n for (const [code, resp] of Object.entries(responses)) {\n // Strictly numeric: `parseInt('4XX')` is 4, which would silently invent a status code.\n if (!/^\\d{3}$/.test(code)) {\n // `default`, `2XX`, `4XX` — the response block is keyed by a numeric status.\n ctx.warnings.warn(`${pathPrefix}/responses/${code}`, `response key '${code}' is not a numeric status code; dropped`);\n continue;\n }\n const statusCode = parseInt(code, 10);\n const respNode = responseToNode(statusCode, resp, op.operationId ?? `${method}${toPascalCase(path)}`, schemaCtx, ctx);\n node.responses.push(respNode);\n }\n\n // Security. A spec-level `security` applies to every operation that does not override it;\n // it used to be collected and never read, so a globally-secured spec imported as unsecured.\n const security = op.security ?? ctx.globalSecurity;\n if (security !== undefined) {\n node.security = convertSecurity(security);\n }\n\n return node;\n}\n\n// ─── Parameters ───────────────────────────────────────────────────────────\n\nfunction buildPathParams(path: string, pathLevelParams: NormalizedParameter[], pathItem: NormalizedPathItem, ctx: PathsContext): OpParamNode[] {\n const schemaCtx = makeSchemaCtx(ctx, `#/paths/${encodePathSegment(path)}`);\n\n // Collect all path params from path-level and operation-level\n const paramMap = new Map<string, NormalizedParameter>();\n\n for (const p of pathLevelParams) {\n paramMap.set(p.name, p);\n }\n\n // Also check operation-level path params\n for (const method of HTTP_METHODS) {\n const op = pathItem[method];\n if (!op?.parameters) continue;\n for (const p of op.parameters) {\n if (p.in === 'path' && !paramMap.has(p.name)) {\n paramMap.set(p.name, p);\n }\n }\n }\n\n // Extract param names from path template\n const templateNames = [...path.matchAll(/\\{([^}]+)\\}/g)].map(m => m[1]!);\n\n return templateNames.map(name => {\n const param = paramMap.get(name);\n if (param) {\n return parameterToNode(param, schemaCtx);\n }\n // Infer as uuid if no schema is given\n return {\n name,\n optional: false,\n nullable: false,\n type: { kind: 'scalar' as const, name: 'string' as const },\n loc: LOC,\n };\n });\n}\n\nfunction parameterToNode(param: NormalizedParameter, ctx: SchemaContext): OpParamNode {\n const type = param.schema ? schemaToTypeNode(param.schema, ctx) : { kind: 'scalar' as const, name: 'string' as const };\n\n return {\n name: param.name,\n optional: param.in !== 'path' && !param.required,\n nullable: false,\n type,\n description: ctx.includeComments ? param.description : undefined,\n loc: LOC,\n };\n}\n\n// ─── Request Body ─────────────────────────────────────────────────────────\n\nfunction requestBodyToNode(\n reqBody: NormalizedRequestBody,\n operationName: string,\n schemaCtx: SchemaContext,\n ctx: PathsContext,\n): OpRequestNode | undefined {\n const content = reqBody.content;\n if (!content) return undefined;\n\n const bodies: OpRequestNode['bodies'] = [];\n\n for (const [contentType, mediaType] of Object.entries(content)) {\n // `.ck` accepts any RFC 6838 `type/subtype`, so there is no reason to narrow a spec to\n // the three content types this used to allow. What it cannot carry is a parameterised\n // (`; charset=`) or wildcard mime, since `mimeType` is two `mimeChar+` runs.\n if (!MIME_RE.test(contentType)) {\n ctx.warnings.warn(`${schemaCtx.path}/requestBody/content`, `content type '${contentType}' is not a plain type/subtype; skipped`);\n continue;\n }\n if (!mediaType?.schema) continue;\n const { typeNode, model } = extractInlineModel(mediaType.schema, `${toPascalCase(operationName)}Request`, schemaCtx);\n if (model) {\n ctx.extractedModels.push(model);\n }\n bodies.push({ contentType, bodyType: typeNode });\n }\n\n if (bodies.length === 0) return undefined;\n return { bodies };\n}\n\n// ─── Responses ────────────────────────────────────────────────────────────\n\n/**\n * Whether an imported status should be marked `(documented)` rather than service-produced.\n *\n * Only applies to a status that carries a block, because that is the only case where the\n * modifier does anything: `isEmitted` in core treats a block as \"the service produces this\", and\n * `isRedundantDocumented` warns when `(documented)` is put on a bare bodyless non-2xx, where the\n * status is already not emitted. 3xx is left alone — `observableResponses` already covers\n * everything below 400, so the marker would change nothing a client sees, and a spec'd redirect\n * body is plausibly service-produced.\n */\nfunction shouldDocument(statusCode: number, braced: boolean, resp: NormalizedResponse, ctx: PathsContext): boolean {\n if (!braced) return false;\n // A spec this project emitted says so outright; prefer it over guessing from the status.\n if (resp['x-contractkit-emit'] === 'documented') return true;\n return statusCode >= 400 && ctx.errorResponses === 'documented';\n}\n\nfunction responseToNode(\n statusCode: number,\n resp: NormalizedResponse,\n operationName: string,\n schemaCtx: SchemaContext,\n ctx: PathsContext,\n): OpResponseNode {\n const headers = convertResponseHeaders(resp.headers, schemaCtx);\n const documented = (braced: boolean) => (shouldDocument(statusCode, braced, resp, ctx) ? { emit: 'documented' as const } : {});\n const empty = (): OpResponseNode => ({\n statusCode,\n bodies: [],\n ...(headers ? { headers, hasBlock: true, ...documented(true) } : {}),\n });\n\n if (!resp.content) return empty();\n\n // Every declared content type is kept — `.ck` can express several mimes for one status, so\n // there is no reason to narrow a spec down to its first one on the way in.\n const bodies: OpResponseBodyNode[] = [];\n for (const [contentType, mediaType] of Object.entries(resp.content)) {\n if (!mediaType?.schema) continue;\n // The extracted model is named for the status; a second mime for the same status reuses\n // that name rather than minting a near-duplicate.\n const suffix = bodies.length === 0 ? '' : toPascalCase(contentType.replace(/[^a-z0-9]+/gi, ' '));\n const { typeNode, model } = extractInlineModel(mediaType.schema, `${toPascalCase(operationName)}Response${statusCode}${suffix}`, schemaCtx);\n if (model) ctx.extractedModels.push(model);\n bodies.push({ contentType, bodyType: typeNode });\n }\n\n if (bodies.length === 0) return empty();\n\n return {\n statusCode,\n bodies,\n hasBlock: true,\n ...(headers ? { headers } : {}),\n ...documented(true),\n };\n}\n\nfunction convertResponseHeaders(headers: NormalizedResponse['headers'], schemaCtx: SchemaContext): OpResponseHeaderNode[] | undefined {\n if (!headers) return undefined;\n const out: OpResponseHeaderNode[] = [];\n for (const [name, header] of Object.entries(headers)) {\n if (!header) continue;\n const type = header.schema ? schemaToTypeNode(header.schema, schemaCtx) : { kind: 'scalar' as const, name: 'string' as const };\n out.push({\n name,\n optional: !header.required,\n type,\n description: schemaCtx.includeComments ? header.description : undefined,\n });\n }\n return out.length > 0 ? out : undefined;\n}\n\n// ─── Security ─────────────────────────────────────────────────────────────\n\nfunction convertSecurity(security: Record<string, string[]>[]): SecurityNode {\n // Empty array = explicitly no security\n if (security.length === 0) {\n return 'none';\n }\n\n // The DSL's security model is simpler — OpenAPI scopes/roles don't map onto named policies,\n // so any non-empty security requirement is collapsed to \"authenticated, default policy\".\n return { loc: LOC };\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────────\n\nfunction makeSchemaCtx(ctx: PathsContext, path: string): SchemaContext {\n return {\n circularRefs: ctx.circularRefs,\n warnings: ctx.warnings,\n path,\n includeComments: ctx.includeComments,\n namedSchemas: ctx.namedSchemas as Record<string, never>,\n extractedModels: ctx.extractedModels,\n inlineCounter: 0,\n // A response body, request body, param or header names an already-imported model.\n insideModel: false,\n };\n}\n\nfunction toPascalCase(input: string): string {\n return input\n .replace(/[^a-zA-Z0-9]/g, ' ')\n .split(/\\s+/)\n .filter(Boolean)\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n\nfunction encodePathSegment(s: string): string {\n return s.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n","import type { CkRootNode, ModelNode, OpRouteNode, ContractTypeNode, ParamSource } from '@contractkit/core';\n\n/**\n * Split models and routes into per-tag CkRootNode instances.\n *\n * Algorithm:\n * 1. Routes are assigned to the file of their first tag (untagged → 'default')\n * 2. Models referenced by exactly one tag go into that tag's file\n * 3. Models referenced by 2+ tags go into 'shared'\n * 4. Orphan models (not referenced by any route) go into 'shared'\n */\nexport function splitByTag(models: ModelNode[], routes: OpRouteNode[], routeTags: Map<OpRouteNode, string>): Map<string, CkRootNode> {\n // Step 1: Group routes by tag\n const routesByTag = new Map<string, OpRouteNode[]>();\n for (const route of routes) {\n const tag = routeTags.get(route) ?? 'default';\n const group = routesByTag.get(tag) ?? [];\n group.push(route);\n routesByTag.set(tag, group);\n }\n\n // Step 2: For each tag, collect which model names are referenced\n const modelsByTag = new Map<string, Set<string>>();\n for (const [tag, tagRoutes] of routesByTag) {\n const refs = new Set<string>();\n for (const route of tagRoutes) {\n collectRouteRefs(route, refs);\n }\n modelsByTag.set(tag, refs);\n }\n\n // Step 3: Determine which tag each model belongs to\n const modelNameToModel = new Map(models.map(m => [m.name, m]));\n const modelAssignment = new Map<string, string>(); // modelName → tag or 'shared'\n\n for (const model of models) {\n const tags: string[] = [];\n for (const [tag, refs] of modelsByTag) {\n if (refs.has(model.name)) {\n tags.push(tag);\n }\n }\n\n if (tags.length === 0) {\n // Orphan model → shared\n modelAssignment.set(model.name, 'shared');\n } else if (tags.length === 1) {\n // Single tag reference → that tag's file\n modelAssignment.set(model.name, tags[0]!);\n } else {\n // Multi-tag reference → shared\n modelAssignment.set(model.name, 'shared');\n }\n }\n\n // Also check transitive: models referenced by shared models should also be shared\n // (simple one-pass — could iterate to fixed point for deep chains)\n for (const model of models) {\n if (modelAssignment.get(model.name) === 'shared') {\n const refs = new Set<string>();\n collectModelRefs(model, refs);\n for (const ref of refs) {\n if (modelNameToModel.has(ref)) {\n const currentTag = modelAssignment.get(ref);\n // Only promote to shared if it was assigned to a specific tag\n // (don't override if already shared)\n if (currentTag && currentTag !== 'shared') {\n // Check if another tag also references this model\n const otherTags = [...modelsByTag.entries()].filter(([t, r]) => t !== currentTag && r.has(ref)).map(([t]) => t);\n if (otherTags.length > 0) {\n modelAssignment.set(ref, 'shared');\n }\n }\n }\n }\n }\n }\n\n // Step 4: Build CkRootNode per tag\n const result = new Map<string, CkRootNode>();\n const allTags = new Set([...routesByTag.keys(), ...new Set(modelAssignment.values())]);\n\n for (const tag of allTags) {\n const tagModels = models.filter(m => modelAssignment.get(m.name) === tag);\n const tagRoutes = routesByTag.get(tag) ?? [];\n\n if (tagModels.length === 0 && tagRoutes.length === 0) continue;\n\n const filename = sanitizeFilename(tag);\n result.set(`${filename}.ck`, {\n kind: 'ckRoot',\n meta: tag !== 'shared' ? { area: tag } : {},\n services: {},\n models: tagModels,\n routes: tagRoutes,\n file: `${filename}.ck`,\n });\n }\n\n return result;\n}\n\n/**\n * Create a single CkRootNode with all models and routes.\n */\nexport function mergeIntoSingle(models: ModelNode[], routes: OpRouteNode[], filename: string = 'api'): CkRootNode {\n return {\n kind: 'ckRoot',\n meta: {},\n services: {},\n models,\n routes,\n file: `${filename}.ck`,\n };\n}\n\n// ─── Reference Collection ─────────────────────────────────────────────────\n\nfunction collectRouteRefs(route: OpRouteNode, refs: Set<string>): void {\n if (route.params) {\n collectParamSourceRefs(route.params, refs);\n }\n for (const op of route.operations) {\n if (op.query) collectParamSourceRefs(op.query, refs);\n if (op.headers) collectParamSourceRefs(op.headers, refs);\n if (op.request) {\n for (const body of op.request.bodies) collectTypeRefs(body.bodyType, refs);\n }\n for (const resp of op.responses) {\n for (const body of resp.bodies) collectTypeRefs(body.bodyType, refs);\n }\n }\n}\n\n/**\n * Collect the model names a `params`/`query`/`headers` source refers to.\n *\n * `ParamSource` is a tagged union, and this was written against the shape it had before that:\n * a bare string, an array of params, or a type node. Only `kind: 'ref'` still worked, and only\n * by coincidence — it happens to look like a `ModelRefTypeNode`. `'params'` and `'type'` fell\n * through to `collectTypeRefs`, whose switch has neither case, so a model reached only from a\n * query or header block collected no tags at all and was filed under `shared.ck`.\n */\nfunction collectParamSourceRefs(source: ParamSource, refs: Set<string>): void {\n switch (source.kind) {\n case 'ref':\n refs.add(source.name);\n return;\n case 'params':\n for (const param of source.nodes) collectTypeRefs(param.type, refs);\n return;\n case 'type':\n collectTypeRefs(source.node, refs);\n return;\n }\n}\n\nfunction collectTypeRefs(type: ContractTypeNode, refs: Set<string>): void {\n switch (type.kind) {\n case 'ref':\n refs.add(type.name);\n break;\n case 'array':\n collectTypeRefs(type.item, refs);\n break;\n case 'tuple':\n for (const item of type.items) collectTypeRefs(item, refs);\n break;\n case 'record':\n collectTypeRefs(type.key, refs);\n collectTypeRefs(type.value, refs);\n break;\n case 'union':\n case 'discriminatedUnion':\n case 'intersection':\n for (const member of type.members) collectTypeRefs(member, refs);\n break;\n case 'inlineObject':\n for (const field of type.fields) collectTypeRefs(field.type, refs);\n break;\n case 'lazy':\n collectTypeRefs(type.inner, refs);\n break;\n }\n}\n\nfunction collectModelRefs(model: ModelNode, refs: Set<string>): void {\n if (model.bases) for (const b of model.bases) refs.add(b);\n if (model.type) collectTypeRefs(model.type, refs);\n for (const field of model.fields) {\n collectTypeRefs(field.type, refs);\n }\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────────\n\nfunction sanitizeFilename(tag: string): string {\n return (\n tag\n .toLowerCase()\n .replace(/[^a-z0-9-]/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '') || 'default'\n );\n}\n","import type { CkRootNode } from '@contractkit/core';\nimport { printCk, printType } from '@contractkit/core';\n\n/**\n * `.ck` serialization for the OpenAPI importer.\n *\n * This module used to carry its own printer. `.ck` had two of them — this one and the prettier\n * plugin's — and only the prettier copy was covered by the round-trip tests that the\n * `ck-grammar-change` checklist points at, so this one silently fell behind the grammar: it\n * ignored `hasBlock` and the `(documented)` response modifier, could not emit `mcp:`,\n * `plugins:`, `name:`, `override`, `format(output=)` or options-level header globals, and\n * emitted unparseable source for a regex containing `/` or an enum value containing both quote\n * styles.\n *\n * The printer now lives in `@contractkit/core` next to `parseCk`, and this module is a thin\n * adapter over it. A grammar change has one printer to update.\n */\n\n/**\n * Options controlling how a {@link CkRootNode} is rendered to `.ck` source.\n *\n * @deprecated `includeComments` is a no-op and is kept only so existing callers still compile.\n * Comments are controlled upstream: `ConvertOptions.includeComments` gates every `description`\n * assignment in `schema-to-ast.ts` and `paths-to-ast.ts`, so when it is off the descriptions are\n * absent from the AST and there is nothing left for the printer to suppress.\n */\nexport interface SerializeOptions {\n /** No-op. See the deprecation note on {@link SerializeOptions}. */\n includeComments?: boolean;\n}\n\n/**\n * Serialize a `.ck` AST back to formatted `.ck` source text.\n *\n * Delegates to `printCk`, which prints from a `CkRootNode` alone — no Ohm CST and no original\n * source — so programmatically built nodes print correctly.\n */\nexport function astToCk(root: CkRootNode, _options: SerializeOptions = {}): string {\n return printCk(root);\n}\n\n/** Render a `ContractTypeNode` to its `.ck` source string. Re-exported from core. */\nexport const serializeType = printType;\n","import { readFileSync } from 'node:fs';\nimport { parse as parseYaml } from 'yaml';\nimport type { ConvertOptions, ConvertResult, NormalizedDocument } from './types.js';\nimport { WarningCollector } from './warnings.js';\nimport { normalize } from './normalize.js';\nimport { detectCircularRefs } from './circular-refs.js';\nimport { schemasToModels, sanitizeName } from './schema-to-ast.js';\nimport type { SchemaContext } from './schema-to-ast.js';\nimport { pathsToRoutes } from './paths-to-ast.js';\nimport { splitByTag, mergeIntoSingle } from './tag-splitter.js';\nimport { astToCk } from './ast-to-ck.js';\nimport type { NormalizedSchema } from './types.js';\nimport type { ModelNode } from '@contractkit/core';\nimport { parseCk, decomposeCk, validateRefs, DiagnosticCollector } from '@contractkit/core';\n\n/**\n * Convert an OpenAPI spec (2.0, 3.0, or 3.1) to Contract Kit .ck source files.\n */\nexport async function convertOpenApiToCk(options: ConvertOptions): Promise<ConvertResult> {\n const { split = 'by-tag', includeComments = true, errorResponses = 'documented' } = options;\n const warnings = new WarningCollector(options.onWarning);\n\n // Step 1: Parse the input into a document object\n const rawDoc = await parseInput(options.input);\n\n // Step 2: Normalize to 3.1 shape\n const doc = normalize(rawDoc, warnings);\n\n // Step 3: Sanitize schema names\n const schemas = sanitizeSchemaNames(doc, warnings);\n\n // Step 4: Detect circular references\n const circularRefs = detectCircularRefs(schemas);\n\n // Step 5: Convert schemas to model AST nodes\n const extractedModels: ModelNode[] = [];\n const schemaCtx: SchemaContext = {\n circularRefs,\n warnings,\n path: '#/components/schemas',\n includeComments,\n namedSchemas: schemas,\n extractedModels,\n inlineCounter: 0,\n insideModel: true,\n };\n\n const models = schemasToModels(schemas, schemaCtx);\n\n // Step 6: Convert paths to route AST nodes\n const { routes, routeTags } = pathsToRoutes(doc, {\n circularRefs,\n warnings,\n includeComments,\n namedSchemas: schemas,\n extractedModels,\n globalSecurity: doc.security,\n errorResponses,\n });\n\n // Models extracted from inline request/response body schemas arrive during step 6, after\n // `schemasToModels` has already read the array — without this they are referenced by the\n // generated operations and never defined.\n const known = new Set(models.map(m => m.name));\n for (const extracted of extractedModels) {\n if (known.has(extracted.name)) continue;\n known.add(extracted.name);\n models.push(extracted);\n }\n\n // Step 7: Split or merge\n const files = new Map<string, string>();\n\n if (split === 'by-tag') {\n const ckRoots = splitByTag(models, routes, routeTags);\n for (const [filename, root] of ckRoots) {\n files.set(filename, astToCk(root));\n }\n } else {\n const root = mergeIntoSingle(models, routes);\n files.set('api.ck', astToCk(root));\n }\n\n // Step 8: Check what we are about to hand back actually compiles\n checkGeneratedFiles(files, warnings);\n\n return { files, warnings: warnings.warnings };\n}\n\n/**\n * Re-parse the generated files and report anything that does not survive.\n *\n * The converter builds core AST nodes and prints them, so a bug in either half produces `.ck`\n * that will not compile — and, because the output is written straight to disk, the first sign of\n * it is an error in the user's own build. Spec content is more adversarial than anything a\n * hand-written contract contains (patterns full of punctuation, descriptions full of newlines,\n * schema names that are not identifiers), so it is worth the round trip to find out here.\n *\n * Reference validation runs across all the files together, because `by-tag` deliberately splits\n * a model into one file and its users into another. Parsing alone is not enough: a reference to\n * a contract that was never emitted is perfectly good syntax, which is exactly how the importer\n * shipped operations pointing at inline body models it had dropped.\n */\nfunction checkGeneratedFiles(files: Map<string, string>, warnings: WarningCollector): void {\n const diag = new DiagnosticCollector();\n const roots = [];\n for (const [filename, text] of files) {\n const before = diag.getAll().length;\n const root = parseCk(text, filename, diag);\n if (diag.getAll().length === before) roots.push(root);\n }\n\n if (roots.length === files.size) {\n const decomposed = roots.map(decomposeCk);\n validateRefs(\n decomposed.map(d => d.contract),\n decomposed.map(d => d.op),\n diag,\n );\n }\n\n for (const d of diag.getAll()) {\n if (d.severity !== 'error') continue;\n warnings.warn(d.file, `generated .ck is not valid (line ${d.line}): ${d.message}`);\n }\n}\n\n// ─── Input Parsing ────────────────────────────────────────────────────────\n\nasync function parseInput(input: string | Record<string, unknown>): Promise<Record<string, unknown>> {\n // Already a parsed object\n if (typeof input === 'object') {\n return input;\n }\n\n // Try as a file path first\n try {\n const content = readFileSync(input, 'utf-8');\n return parseJsonOrYaml(content);\n } catch {\n // Not a file path — try parsing as JSON/YAML string\n return parseJsonOrYaml(input);\n }\n}\n\nfunction parseJsonOrYaml(content: string): Record<string, unknown> {\n // Try JSON first (faster)\n try {\n return JSON.parse(content) as Record<string, unknown>;\n } catch {\n // Fall back to YAML\n return parseYaml(content) as Record<string, unknown>;\n }\n}\n\n// ─── Schema Name Sanitization ─────────────────────────────────────────────\n\nfunction sanitizeSchemaNames(doc: NormalizedDocument, warnings: WarningCollector): Record<string, NormalizedSchema> {\n const original = doc.components?.schemas ?? {};\n const sanitized: Record<string, NormalizedSchema> = {};\n const nameMap = new Map<string, string>(); // original → sanitized\n\n for (const name of Object.keys(original)) {\n const clean = sanitizeName(name, warnings);\n if (sanitized[clean]) {\n warnings.warn(`#/components/schemas/${name}`, `Name collision after sanitization: \"${name}\" and another schema both map to \"${clean}\"`);\n // Disambiguate with a suffix\n let i = 2;\n while (sanitized[`${clean}${i}`]) i++;\n nameMap.set(name, `${clean}${i}`);\n sanitized[`${clean}${i}`] = original[name] as NormalizedSchema;\n } else {\n nameMap.set(name, clean);\n sanitized[clean] = original[name] as NormalizedSchema;\n }\n }\n\n // Update $refs in the document to use sanitized names\n if (nameMap.size > 0) {\n updateRefs(doc, nameMap);\n }\n\n return sanitized;\n}\n\nfunction updateRefs(obj: unknown, nameMap: Map<string, string>): void {\n if (!obj || typeof obj !== 'object') return;\n if (Array.isArray(obj)) {\n for (const item of obj) updateRefs(item, nameMap);\n return;\n }\n\n const record = obj as Record<string, unknown>;\n if (typeof record.$ref === 'string') {\n const match = record.$ref.match(/^#\\/components\\/schemas\\/(.+)$/);\n if (match?.[1] && nameMap.has(match[1])) {\n record.$ref = `#/components/schemas/${nameMap.get(match[1])}`;\n }\n }\n\n for (const value of Object.values(record)) {\n updateRefs(value, nameMap);\n }\n}\n","import type { Warning } from './types.js';\n\nexport class WarningCollector {\n readonly warnings: Warning[] = [];\n private onWarning?: (w: Warning) => void;\n\n constructor(onWarning?: (w: Warning) => void) {\n this.onWarning = onWarning;\n }\n\n warn(path: string, message: string): void {\n this.add({ path, message, severity: 'warn' });\n }\n\n info(path: string, message: string): void {\n this.add({ path, message, severity: 'info' });\n }\n\n private add(warning: Warning): void {\n this.warnings.push(warning);\n this.onWarning?.(warning);\n }\n}\n"],"mappings":";;;;AAeO,SAASA,UAAUC,KAA8BC,UAA0B;AAC9E,QAAMC,UAAUC,cAAcH,GAAAA;AAE9B,QAAMI,aACFF,YAAY,QACNG,kBAAkBL,KAAKC,QAAAA,IACvBC,YAAY,QACVI,eAAeN,KAAsCC,QAAAA,IAEpDD;AAEbO,wBAAsBH,YAAYH,QAAAA;AAClC,SAAOG;AACX;AAbgBL;AAkBhB,IAAMS,iBAAiB;EAAC;EAAc;EAAiB;EAAa;;AAGpE,IAAMC,gBAAgB;AAetB,SAASF,sBAAsBP,KAAyBC,UAA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AOC,OAAO,wBAAwBZ,QAAQc,IAAID,MAAM,CAAA,CAAE,CAAA;IAC9D;EACJ;AAEA,aAAWE,SAASd,OAAOe,OAAOL,MAAAA,GAAS;AACvCL,eAAWS,OAAOf,OAAAA;EACtB;AACJ;AAlBSM;","names":["normalize","doc","warnings","version","detectVersion","normalized","normalizeSwagger2","normalizeOas30","dereferenceComponents","DEREF_SECTIONS","MAX_REF_DEPTH","components","resolve","node","path","depth","Array","isArray","map","item","obj","ref","$ref","match","exec","section","includes","warn","target","decodeRefToken","undefined","siblings","resolved","out","key","value","Object","entries","pathItem","paths","token","decodeURIComponent","replace","swagger","startsWith","openapi","info","title","basePath","schemes","host","globalConsumes","consumes","globalProduces","produces","result","description","servers","url","schemas","securitySchemes","tags","definitions","name","schema","normalizeNullable30","secDefs","securityDefinitions","scheme","convertSecurityScheme2","normalizePathItem2","security","methods","pathParams","parameters","method","op","opConsumes","opProduces","params","nonBodyParams","requestBody","param","in","contentType","required","content","encodePathSegment","type","properties","formSchema","props","push","normalizedParam","format","enum","items","default","minimum","maximum","minLength","maxLength","pattern","responses","opResponses","code","resp","headers","convertResponseHeaders2","responseEntry","operationId","summary","length","deprecated","header","rest","keys","flow","flows","implicit","authorizationUrl","scopes","password","tokenUrl","clientCredentials","authorizationCode","_warnings","values","normalizePathItemSchemas","reqBody","mediaType","nullable","val","additionalProperties","combiner","s","detectCircularRefs","schemas","circular","Set","visiting","visited","visit","name","has","add","schema","ref","collectRefs","refName","extractRefName","delete","Object","keys","obj","refs","walk","val","Array","isArray","item","record","$ref","push","v","values","match","LOC","file","line","FORMAT_TO_SCALAR","email","uri","iri","url","uuid","date","time","duration","binary","int64","schemasToModels","schemas","ctx","models","name","schema","Object","entries","modelCtx","path","model","schemaToModel","push","extractedModels","warnUnsupported","description","includeComments","undefined","allOf","length","first","second","refMember","$ref","objectMember","properties","baseName","extractRefName","fields","schemaPropertiesToFields","kind","bases","loc","type","additionalProperties","mode","typeNode","schemaToTypeNode","warnUnrepresentableConstraints","refName","insideModel","circularRefs","has","inner","warnings","warn","const","value","enum","values","map","String","oneOf","discriminator","propertyName","toDiscriminatedUnion","toUnion","anyOf","members","s","types","normalizeTypeField","schemaToInlineObject","baseType","nullable","stringSchemaToType","integerSchemaToType","numberSchemaToType","arraySchemaToType","objectSchemaToType","format","scalarName","mods","minLength","maxLength","len","min","max","pattern","regex","minimum","maximum","prefixItems","items","item","minItems","maxItems","key","required","Set","propSchema","propCtx","fieldType","effectiveType","nonNull","filter","m","visibility","readOnly","writeOnly","optional","default","deprecated","Array","isArray","t","includes","UNREPRESENTABLE_KEYWORDS","xml","externalDocs","info","not","keyword","extractInlineModel","suggestedName","sanitizeName","cleaned","replace","split","Boolean","part","charAt","toUpperCase","slice","join","safe","test","LOC","file","line","MIME_RE","toNameText","summary","replace","trim","HTTP_METHODS","UNSUPPORTED_METHODS","pathsToRoutes","doc","ctx","routes","routeTags","Map","paths","path","pathItem","Object","entries","result","pathItemToRoute","push","route","set","tag","operations","primaryTag","pathParams","parameters","filter","p","in","method","warnings","warn","encodePathSegment","op","opNode","operationToNode","tags","length","params","buildPathParams","loc","kind","nodes","description","includeComments","pathPrefix","schemaCtx","makeSchemaCtx","node","responses","operationId","sdk","name","deprecated","modifiers","queryParams","headerParams","param","parameterToNode","query","headers","requestBody","request","requestBodyToNode","toPascalCase","code","resp","test","statusCode","parseInt","respNode","responseToNode","security","globalSecurity","undefined","convertSecurity","pathLevelParams","paramMap","has","templateNames","matchAll","map","m","get","optional","nullable","type","schema","schemaToTypeNode","required","reqBody","operationName","content","bodies","contentType","mediaType","typeNode","model","extractInlineModel","extractedModels","bodyType","shouldDocument","braced","errorResponses","convertResponseHeaders","documented","emit","empty","hasBlock","suffix","out","header","circularRefs","namedSchemas","inlineCounter","insideModel","input","split","Boolean","part","charAt","toUpperCase","slice","join","s","splitByTag","models","routes","routeTags","routesByTag","Map","route","tag","get","group","push","set","modelsByTag","tagRoutes","refs","Set","collectRouteRefs","modelNameToModel","map","m","name","modelAssignment","model","tags","has","length","collectModelRefs","ref","currentTag","otherTags","entries","filter","t","r","result","allTags","keys","values","tagModels","filename","sanitizeFilename","kind","meta","area","services","file","mergeIntoSingle","params","collectParamSourceRefs","op","operations","query","headers","request","body","bodies","collectTypeRefs","bodyType","resp","responses","source","add","param","nodes","type","node","item","items","key","value","member","members","field","fields","inner","bases","b","toLowerCase","replace","printCk","printType","astToCk","root","_options","printCk","serializeType","printType","readFileSync","parse","parseYaml","WarningCollector","warnings","onWarning","warn","path","message","add","severity","info","warning","push","parseCk","decomposeCk","validateRefs","DiagnosticCollector","convertOpenApiToCk","options","split","includeComments","errorResponses","warnings","WarningCollector","onWarning","rawDoc","parseInput","input","doc","normalize","schemas","sanitizeSchemaNames","circularRefs","detectCircularRefs","extractedModels","schemaCtx","path","namedSchemas","inlineCounter","insideModel","models","schemasToModels","routes","routeTags","pathsToRoutes","globalSecurity","security","known","Set","map","m","name","extracted","has","add","push","files","Map","ckRoots","splitByTag","filename","root","set","astToCk","mergeIntoSingle","checkGeneratedFiles","diag","DiagnosticCollector","roots","text","before","getAll","length","parseCk","size","decomposed","decomposeCk","validateRefs","d","contract","op","severity","warn","file","line","message","content","readFileSync","parseJsonOrYaml","JSON","parse","parseYaml","original","components","sanitized","nameMap","Object","keys","clean","sanitizeName","i","updateRefs","obj","Array","isArray","item","record","$ref","match","get","value","values"]}
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAsB,MAAM,YAAY,CAAC;AAYpF;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAsDxF"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAsB,MAAM,YAAY,CAAC;AAapF;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAqExF"}
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  schemasToModels,
12
12
  serializeType,
13
13
  splitByTag
14
- } from "./chunk-JPI3AQ7V.js";
14
+ } from "./chunk-Z53MK4FM.js";
15
15
  export {
16
16
  astToCk,
17
17
  convertOpenApiToCk,
@@ -5,8 +5,12 @@ import type { WarningCollector } from './warnings.js';
5
5
  * 3.1-like shape. Swagger 2.0 and OpenAPI 3.0 documents are transformed
6
6
  * so that downstream code only needs to handle one schema dialect.
7
7
  *
8
- * Uses @scalar/openapi-parser's `upgrade()` for the heavy lifting when
9
- * available, with manual fallbacks for edge cases.
8
+ * The transformation is hand-written. An earlier note here claimed `@scalar/openapi-parser`'s
9
+ * `upgrade()` did the heavy lifting; it never did, and that dependency has been dropped.
10
+ *
11
+ * After version normalization, `dereferenceComponents` inlines `$ref`s to reusable non-schema
12
+ * components, so the rest of the pipeline sees only inline parameter, response, request-body and
13
+ * header objects. Schema `$ref`s are deliberately left intact — they become `.ck` model refs.
10
14
  */
11
15
  export declare function normalize(doc: Record<string, unknown>, warnings: WarningCollector): NormalizedDocument;
12
16
  //# sourceMappingURL=normalize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,gBAAgB,GAAG,kBAAkB,CAWtG"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,gBAAgB,GAAG,kBAAkB,CAatG"}
@@ -10,6 +10,8 @@ export interface PathsContext {
10
10
  extractedModels: ModelNode[];
11
11
  /** Global security from the spec (for detecting explicit overrides). */
12
12
  globalSecurity?: Record<string, string[]>[];
13
+ /** How bodied 4xx/5xx responses are imported. See `ConvertOptions.errorResponses`. */
14
+ errorResponses: 'documented' | 'emitted';
13
15
  }
14
16
  /**
15
17
  * Convert OpenAPI paths to OpRouteNode[].
@@ -1 +1 @@
1
- {"version":3,"file":"paths-to-ast.d.ts","sourceRoot":"","sources":["../src/paths-to-ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EAQX,SAAS,EAGZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACR,kBAAkB,EAMrB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAOtD,MAAM,WAAW,YAAY;IACzB,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,wEAAwE;IACxE,eAAe,EAAE,SAAS,EAAE,CAAC;IAC7B,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;CAC/C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;CAAE,CAexI"}
1
+ {"version":3,"file":"paths-to-ast.d.ts","sourceRoot":"","sources":["../src/paths-to-ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EAQX,SAAS,EAGZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACR,kBAAkB,EAMrB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA2BtD,MAAM,WAAW,YAAY;IACzB,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,wEAAwE;IACxE,eAAe,EAAE,SAAS,EAAE,CAAC;IAC7B,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAC5C,sFAAsF;IACtF,cAAc,EAAE,YAAY,GAAG,SAAS,CAAC;CAC5C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;CAAE,CAexI"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,mBAAmB,CAAC;AAwC3E,QAAA,MAAM,MAAM,EAAE,iBA0Cb,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,mBAAmB,CAAC;AAsD3E,QAAA,MAAM,MAAM,EAAE,iBA2Cb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/plugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __name,
3
3
  convertOpenApiToCk
4
- } from "./chunk-JPI3AQ7V.js";
4
+ } from "./chunk-Z53MK4FM.js";
5
5
 
6
6
  // src/plugin.ts
7
7
  import { writeFileSync, mkdirSync } from "fs";
@@ -10,6 +10,8 @@ function parseImportArgs(argv) {
10
10
  let specPath = "";
11
11
  let output = ".";
12
12
  let split = "by-tag";
13
+ let includeComments = true;
14
+ let errorResponses = "documented";
13
15
  for (let i = 0; i < argv.length; i++) {
14
16
  const arg = argv[i];
15
17
  if (arg === "--output" || arg === "-o") {
@@ -17,6 +19,11 @@ function parseImportArgs(argv) {
17
19
  } else if (arg === "--split") {
18
20
  const val = argv[++i];
19
21
  if (val === "single" || val === "by-tag") split = val;
22
+ } else if (arg === "--no-comments") {
23
+ includeComments = false;
24
+ } else if (arg === "--error-responses") {
25
+ const val = argv[++i];
26
+ if (val === "documented" || val === "emitted") errorResponses = val;
20
27
  } else if (!arg.startsWith("-")) {
21
28
  specPath = arg;
22
29
  }
@@ -24,7 +31,9 @@ function parseImportArgs(argv) {
24
31
  return {
25
32
  specPath,
26
33
  output,
27
- split
34
+ split,
35
+ includeComments,
36
+ errorResponses
28
37
  };
29
38
  }
30
39
  __name(parseImportArgs, "parseImportArgs");
@@ -38,6 +47,11 @@ Arguments:
38
47
  Options:
39
48
  -o, --output <dir> Output directory for .ck files (default: current directory)
40
49
  --split <mode> How to split output: "by-tag" (one file per tag) or "single" (default: by-tag)
50
+ --no-comments Skip OpenAPI descriptions instead of emitting them as # comments
51
+ --error-responses <mode>
52
+ How to import a 4xx/5xx that declares a body: "documented" (default)
53
+ marks it \`404(documented):\`, so the SDK throws it and the generated
54
+ router does not write it; "emitted" imports it as service-produced
41
55
  -h, --help Show this help message`;
42
56
  var plugin = {
43
57
  name: "import-openapi",
@@ -55,7 +69,8 @@ var plugin = {
55
69
  const result = await convertOpenApiToCk({
56
70
  input: resolve(parsed.specPath),
57
71
  split: parsed.split,
58
- includeComments: true,
72
+ includeComments: parsed.includeComments,
73
+ errorResponses: parsed.errorResponses,
59
74
  onWarning: /* @__PURE__ */ __name((w) => {
60
75
  const prefix = w.severity === "warn" ? "\u26A0" : "\u2139";
61
76
  console.warn(` ${prefix} ${w.path}: ${w.message}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import { writeFileSync, mkdirSync } from 'node:fs';\nimport { resolve, join } from 'node:path';\nimport { convertOpenApiToCk } from './convert.js';\nimport type { Warning } from './types.js';\nimport type { ContractKitPlugin, CommandContext } from '@contractkit/core';\n\ninterface ImportArgs {\n specPath: string;\n output: string;\n split: 'single' | 'by-tag';\n}\n\nfunction parseImportArgs(argv: string[]): ImportArgs {\n let specPath = '';\n let output = '.';\n let split: 'single' | 'by-tag' = 'by-tag';\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]!;\n if (arg === '--output' || arg === '-o') {\n output = argv[++i] ?? '.';\n } else if (arg === '--split') {\n const val = argv[++i];\n if (val === 'single' || val === 'by-tag') split = val;\n } else if (!arg.startsWith('-')) {\n specPath = arg;\n }\n }\n\n return { specPath, output, split };\n}\n\nconst USAGE = `Usage: contractkit import-openapi <spec-path> [options]\n\nConvert an OpenAPI 2.0/3.0/3.1 YAML or JSON spec into .ck contract files.\n\nArguments:\n <spec-path> Path to the OpenAPI spec file\n\nOptions:\n -o, --output <dir> Output directory for .ck files (default: current directory)\n --split <mode> How to split output: \"by-tag\" (one file per tag) or \"single\" (default: by-tag)\n -h, --help Show this help message`;\n\nconst plugin: ContractKitPlugin = {\n name: 'import-openapi',\n command: {\n name: 'import-openapi',\n description: 'Convert an OpenAPI YAML/JSON spec to .ck contracts',\n usage: USAGE,\n async run(args: string[], _ctx: CommandContext): Promise<void> {\n const parsed = parseImportArgs(args);\n\n if (!parsed.specPath) {\n console.error(USAGE);\n process.exit(1);\n }\n\n console.log(`Converting ${parsed.specPath} → .ck files...`);\n\n const result = await convertOpenApiToCk({\n input: resolve(parsed.specPath),\n split: parsed.split,\n includeComments: true,\n onWarning: (w: Warning) => {\n const prefix = w.severity === 'warn' ? '⚠' : 'ℹ';\n console.warn(` ${prefix} ${w.path}: ${w.message}`);\n },\n });\n\n const outputDir = resolve(parsed.output);\n mkdirSync(outputDir, { recursive: true });\n\n for (const [filename, content] of result.files) {\n const outPath = join(outputDir, filename);\n writeFileSync(outPath, content, 'utf-8');\n console.log(` ✓ ${outPath}`);\n }\n\n if (result.warnings.length > 0) {\n console.log(`\\n${result.warnings.length} warning(s) during conversion.`);\n }\n\n console.log(`\\nGenerated ${result.files.size} file(s).`);\n },\n },\n};\n\nexport default plugin;\n"],"mappings":";;;;;;AAAA,SAASA,eAAeC,iBAAiB;AACzC,SAASC,SAASC,YAAY;AAW9B,SAASC,gBAAgBC,MAAc;AACnC,MAAIC,WAAW;AACf,MAAIC,SAAS;AACb,MAAIC,QAA6B;AAEjC,WAASC,IAAI,GAAGA,IAAIJ,KAAKK,QAAQD,KAAK;AAClC,UAAME,MAAMN,KAAKI,CAAAA;AACjB,QAAIE,QAAQ,cAAcA,QAAQ,MAAM;AACpCJ,eAASF,KAAK,EAAEI,CAAAA,KAAM;IAC1B,WAAWE,QAAQ,WAAW;AAC1B,YAAMC,MAAMP,KAAK,EAAEI,CAAAA;AACnB,UAAIG,QAAQ,YAAYA,QAAQ,SAAUJ,SAAQI;IACtD,WAAW,CAACD,IAAIE,WAAW,GAAA,GAAM;AAC7BP,iBAAWK;IACf;EACJ;AAEA,SAAO;IAAEL;IAAUC;IAAQC;EAAM;AACrC;AAlBSJ;AAoBT,IAAMU,QAAQ;;;;;;;;;;;AAYd,IAAMC,SAA4B;EAC9BC,MAAM;EACNC,SAAS;IACLD,MAAM;IACNE,aAAa;IACbC,OAAOL;IACP,MAAMM,IAAIC,MAAgBC,MAAoB;AAC1C,YAAMC,SAASnB,gBAAgBiB,IAAAA;AAE/B,UAAI,CAACE,OAAOjB,UAAU;AAClBkB,gBAAQC,MAAMX,KAAAA;AACdY,gBAAQC,KAAK,CAAA;MACjB;AAEAH,cAAQI,IAAI,cAAcL,OAAOjB,QAAQ,sBAAiB;AAE1D,YAAMuB,SAAS,MAAMC,mBAAmB;QACpCC,OAAOC,QAAQT,OAAOjB,QAAQ;QAC9BE,OAAOe,OAAOf;QACdyB,iBAAiB;QACjBC,WAAW,wBAACC,MAAAA;AACR,gBAAMC,SAASD,EAAEE,aAAa,SAAS,WAAM;AAC7Cb,kBAAQc,KAAK,KAAKF,MAAAA,KAAWD,EAAEI,IAAI,KAAKJ,EAAEK,OAAO,EAAE;QACvD,GAHW;MAIf,CAAA;AAEA,YAAMC,YAAYT,QAAQT,OAAOhB,MAAM;AACvCmC,gBAAUD,WAAW;QAAEE,WAAW;MAAK,CAAA;AAEvC,iBAAW,CAACC,UAAUC,OAAAA,KAAYhB,OAAOiB,OAAO;AAC5C,cAAMC,UAAUC,KAAKP,WAAWG,QAAAA;AAChCK,sBAAcF,SAASF,SAAS,OAAA;AAChCrB,gBAAQI,IAAI,aAAQmB,OAAAA,EAAS;MACjC;AAEA,UAAIlB,OAAOqB,SAASxC,SAAS,GAAG;AAC5Bc,gBAAQI,IAAI;EAAKC,OAAOqB,SAASxC,MAAM,gCAAgC;MAC3E;AAEAc,cAAQI,IAAI;YAAeC,OAAOiB,MAAMK,IAAI,WAAW;IAC3D;EACJ;AACJ;AAEA,IAAA,iBAAepC;","names":["writeFileSync","mkdirSync","resolve","join","parseImportArgs","argv","specPath","output","split","i","length","arg","val","startsWith","USAGE","plugin","name","command","description","usage","run","args","_ctx","parsed","console","error","process","exit","log","result","convertOpenApiToCk","input","resolve","includeComments","onWarning","w","prefix","severity","warn","path","message","outputDir","mkdirSync","recursive","filename","content","files","outPath","join","writeFileSync","warnings","size"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import { writeFileSync, mkdirSync } from 'node:fs';\nimport { resolve, join } from 'node:path';\nimport { convertOpenApiToCk } from './convert.js';\nimport type { Warning } from './types.js';\nimport type { ContractKitPlugin, CommandContext } from '@contractkit/core';\n\ninterface ImportArgs {\n specPath: string;\n output: string;\n split: 'single' | 'by-tag';\n includeComments: boolean;\n errorResponses: 'documented' | 'emitted';\n}\n\nfunction parseImportArgs(argv: string[]): ImportArgs {\n let specPath = '';\n let output = '.';\n let split: 'single' | 'by-tag' = 'by-tag';\n let includeComments = true;\n let errorResponses: 'documented' | 'emitted' = 'documented';\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]!;\n if (arg === '--output' || arg === '-o') {\n output = argv[++i] ?? '.';\n } else if (arg === '--split') {\n const val = argv[++i];\n if (val === 'single' || val === 'by-tag') split = val;\n } else if (arg === '--no-comments') {\n includeComments = false;\n } else if (arg === '--error-responses') {\n const val = argv[++i];\n if (val === 'documented' || val === 'emitted') errorResponses = val;\n } else if (!arg.startsWith('-')) {\n specPath = arg;\n }\n }\n\n return { specPath, output, split, includeComments, errorResponses };\n}\n\nconst USAGE = `Usage: contractkit import-openapi <spec-path> [options]\n\nConvert an OpenAPI 2.0/3.0/3.1 YAML or JSON spec into .ck contract files.\n\nArguments:\n <spec-path> Path to the OpenAPI spec file\n\nOptions:\n -o, --output <dir> Output directory for .ck files (default: current directory)\n --split <mode> How to split output: \"by-tag\" (one file per tag) or \"single\" (default: by-tag)\n --no-comments Skip OpenAPI descriptions instead of emitting them as # comments\n --error-responses <mode>\n How to import a 4xx/5xx that declares a body: \"documented\" (default)\n marks it \\`404(documented):\\`, so the SDK throws it and the generated\n router does not write it; \"emitted\" imports it as service-produced\n -h, --help Show this help message`;\n\nconst plugin: ContractKitPlugin = {\n name: 'import-openapi',\n command: {\n name: 'import-openapi',\n description: 'Convert an OpenAPI YAML/JSON spec to .ck contracts',\n usage: USAGE,\n async run(args: string[], _ctx: CommandContext): Promise<void> {\n const parsed = parseImportArgs(args);\n\n if (!parsed.specPath) {\n console.error(USAGE);\n process.exit(1);\n }\n\n console.log(`Converting ${parsed.specPath} → .ck files...`);\n\n const result = await convertOpenApiToCk({\n input: resolve(parsed.specPath),\n split: parsed.split,\n includeComments: parsed.includeComments,\n errorResponses: parsed.errorResponses,\n onWarning: (w: Warning) => {\n const prefix = w.severity === 'warn' ? '⚠' : 'ℹ';\n console.warn(` ${prefix} ${w.path}: ${w.message}`);\n },\n });\n\n const outputDir = resolve(parsed.output);\n mkdirSync(outputDir, { recursive: true });\n\n for (const [filename, content] of result.files) {\n const outPath = join(outputDir, filename);\n writeFileSync(outPath, content, 'utf-8');\n console.log(` ✓ ${outPath}`);\n }\n\n if (result.warnings.length > 0) {\n console.log(`\\n${result.warnings.length} warning(s) during conversion.`);\n }\n\n console.log(`\\nGenerated ${result.files.size} file(s).`);\n },\n },\n};\n\nexport default plugin;\n"],"mappings":";;;;;;AAAA,SAASA,eAAeC,iBAAiB;AACzC,SAASC,SAASC,YAAY;AAa9B,SAASC,gBAAgBC,MAAc;AACnC,MAAIC,WAAW;AACf,MAAIC,SAAS;AACb,MAAIC,QAA6B;AACjC,MAAIC,kBAAkB;AACtB,MAAIC,iBAA2C;AAE/C,WAASC,IAAI,GAAGA,IAAIN,KAAKO,QAAQD,KAAK;AAClC,UAAME,MAAMR,KAAKM,CAAAA;AACjB,QAAIE,QAAQ,cAAcA,QAAQ,MAAM;AACpCN,eAASF,KAAK,EAAEM,CAAAA,KAAM;IAC1B,WAAWE,QAAQ,WAAW;AAC1B,YAAMC,MAAMT,KAAK,EAAEM,CAAAA;AACnB,UAAIG,QAAQ,YAAYA,QAAQ,SAAUN,SAAQM;IACtD,WAAWD,QAAQ,iBAAiB;AAChCJ,wBAAkB;IACtB,WAAWI,QAAQ,qBAAqB;AACpC,YAAMC,MAAMT,KAAK,EAAEM,CA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AOoB,SAASvC,MAAM,gCAAgC;MAC3E;AAEAc,cAAQI,IAAI;YAAeC,OAAOgB,MAAMK,IAAI,WAAW;IAC3D;EACJ;AACJ;AAEA,IAAA,iBAAenC;","names":["writeFileSync","mkdirSync","resolve","join","parseImportArgs","argv","specPath","output","split","includeComments","errorResponses","i","length","arg","val","startsWith","USAGE","plugin","name","command","description","usage","run","args","_ctx","parsed","console","error","process","exit","log","result","convertOpenApiToCk","input","resolve","onWarning","w","prefix","severity","warn","path","message","outputDir","mkdirSync","recursive","filename","content","files","outPath","join","writeFileSync","warnings","size"]}
@@ -2,8 +2,20 @@ import type { ContractTypeNode, ModelNode } from '@contractkit/core';
2
2
  import type { NormalizedSchema } from './types.js';
3
3
  import type { WarningCollector } from './warnings.js';
4
4
  export interface SchemaContext {
5
- /** Schema names involved in circular references — use lazy() for these. */
5
+ /** Schema names involved in circular references — see {@link insideModel}. */
6
6
  circularRefs: Set<string>;
7
+ /**
8
+ * Whether the type being built sits inside a `contract` body. Default `true`.
9
+ *
10
+ * `lazy()` exists to break a definition cycle: `topoSortModels` in the TypeScript plugin
11
+ * emits dependencies before dependents and can only fall back to source order for a cycle,
12
+ * so a reference from one cycle member to another has to be deferred. A reference from an
13
+ * operation — a response body, request body, param, or response header — is not part of any
14
+ * such cycle: it names a model the generated module has already imported and fully
15
+ * evaluated. Wrapping it achieves nothing and makes every contract importing a
16
+ * self-referential schema noisier than it needs to be.
17
+ */
18
+ insideModel: boolean;
7
19
  /** Warning collector for unsupported features. */
8
20
  warnings: WarningCollector;
9
21
  /** Current JSON pointer path (for warnings). */
@@ -1 +1 @@
1
- {"version":3,"file":"schema-to-ast.d.ts","sourceRoot":"","sources":["../src/schema-to-ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,SAAS,EAA6B,MAAM,mBAAmB,CAAC;AAChH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE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;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAyFnI;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,GAAE,MAAc,GAAG,UAAU,CAShH"}
1
+ {"version":3,"file":"tag-splitter.d.ts","sourceRoot":"","sources":["../src/tag-splitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAiC,MAAM,mBAAmB,CAAC;AAE3G;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAyFnI;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,GAAE,MAAc,GAAG,UAAU,CAShH"}
package/dist/types.d.ts CHANGED
@@ -5,6 +5,20 @@ export interface ConvertOptions {
5
5
  split?: 'single' | 'by-tag';
6
6
  /** Emit OpenAPI descriptions as # comments. Default: true. */
7
7
  includeComments?: boolean;
8
+ /**
9
+ * How a 4xx/5xx response that declares a body is imported. Default: `'documented'`.
10
+ *
11
+ * OpenAPI cannot say whether the handler *returns* a status or merely documents it, but
12
+ * `.ck` distinguishes the two and every generator downstream depends on the answer. Writing
13
+ * `404: { … }` means the service produces it: the generated router writes it and the SDKs
14
+ * hand it back as a value. `404(documented): { … }` means the body is the error contract —
15
+ * the SDK throws it as an `SdkError` and the service is not responsible for returning it,
16
+ * which is what an error response almost always is.
17
+ *
18
+ * `'emitted'` reproduces the pre-existing behaviour, where every declared status was imported
19
+ * as service-produced.
20
+ */
21
+ errorResponses?: 'documented' | 'emitted';
8
22
  /** Called for each warning during conversion. */
9
23
  onWarning?: (warning: Warning) => void;
10
24
  }
@@ -50,6 +64,10 @@ export interface NormalizedSchema {
50
64
  maximum?: number;
51
65
  minItems?: number;
52
66
  maxItems?: number;
67
+ exclusiveMinimum?: number | boolean;
68
+ exclusiveMaximum?: number | boolean;
69
+ multipleOf?: number;
70
+ uniqueItems?: boolean;
53
71
  discriminator?: {
54
72
  propertyName?: string;
55
73
  mapping?: Record<string, string>;
@@ -70,6 +88,11 @@ export interface NormalizedDocument {
70
88
  components?: {
71
89
  schemas?: Record<string, NormalizedSchema>;
72
90
  securitySchemes?: Record<string, unknown>;
91
+ /** Reusable component objects, inlined by `dereferenceComponents` before conversion. */
92
+ parameters?: Record<string, NormalizedParameter>;
93
+ requestBodies?: Record<string, NormalizedRequestBody>;
94
+ responses?: Record<string, NormalizedResponse>;
95
+ headers?: Record<string, NormalizedHeader>;
73
96
  };
74
97
  security?: Record<string, string[]>[];
75
98
  servers?: {
@@ -122,6 +145,11 @@ export interface NormalizedRequestBody {
122
145
  }
123
146
  export interface NormalizedResponse {
124
147
  description?: string;
148
+ /**
149
+ * Set by `@contractkit/plugin-openapi` to carry the emitted-vs-documented distinction, which
150
+ * OpenAPI itself cannot express. Honoured ahead of the status-code heuristic on import.
151
+ */
152
+ 'x-contractkit-emit'?: 'documented';
125
153
  content?: Record<string, {
126
154
  schema?: NormalizedSchema;
127
155
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC3B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,+EAA+E;IAC/E,KAAK,CAAC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3.1) to Contract Kit .ck files",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,13 +28,12 @@
28
28
  "./plugin": "./dist/plugin.js"
29
29
  },
30
30
  "dependencies": {
31
- "@scalar/openapi-parser": "^0.26.1",
32
31
  "yaml": "^2.8.3",
33
- "@contractkit/core": "0.26.1"
32
+ "@contractkit/core": "0.27.0"
34
33
  },
35
34
  "devDependencies": {
36
- "@repo/config-typescript": "0.1.0",
37
- "@repo/config-eslint": "0.3.1"
35
+ "@repo/config-eslint": "0.3.1",
36
+ "@repo/config-typescript": "0.1.0"
38
37
  },
39
38
  "scripts": {
40
39
  "build": "tsup src/index.ts src/plugin.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration",