Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@contractkit/openapi-to-ck

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contractkit/openapi-to-ck

Convert OpenAPI specs (2.0/3.0/3.1) to Contract Kit .ck files

latest
Source
npmnpm
Version
0.8.2
Version published
Weekly downloads
58
41.46%
Maintainers
1
Weekly downloads
 
Created
Source

@contractkit/openapi-to-ck

Convert OpenAPI specs (2.0, 3.0, 3.1) into ContractKit .ck files. Useful for adopting ContractKit in projects that already have an OpenAPI document, or for round-tripping a spec through CK.

Installation

pnpm add -D @contractkit/openapi-to-ck

Use as a CLI subcommand

When the package is installed, the @contractkit/cli binary picks up an openapi-to-ck subcommand:

contractkit openapi-to-ck --input openapi.yaml --output contracts/
FlagDescription
--input <path>Path to an OpenAPI YAML or JSON file.
--output <dir>Directory to write .ck files into.
--split <single | by-tag>Output mode. by-tag (default) writes one file per OpenAPI tag; single writes one combined file.
--no-commentsDon't emit OpenAPI descriptions as # comments.

Programmatic use

import { convertOpenApiToCk } from '@contractkit/openapi-to-ck';

const { files, warnings } = await convertOpenApiToCk({
    input: 'openapi.yaml',          // file path, JSON/YAML string, or pre-parsed object
    split: 'by-tag',                // 'single' | 'by-tag'  (default: 'by-tag')
    includeComments: true,          // emit OpenAPI descriptions as # comments (default: true)
    onWarning: w => console.warn(w),
});

// `files` is a Map<filename, ckSource>
for (const [filename, source] of files) {
    await fs.writeFile(filename, source);
}

Warning entries carry a JSON-pointer-style path into the OpenAPI spec, a human-readable message, and a severity of 'info' | 'warn'.

What's converted

OpenAPI.ck
pathsoperation /path: { ... } blocks
components.schemascontract Name: { ... } declarations
parameters (path / query / header)params: { ... } / query: { ... } / headers: { ... } blocks
requestBody.content[mime].schemarequest: { mime: Type }
responses[code].content[mime].schemaresponse: { code: { mime: Type } }
responses[code].headersper-status headers: { name: type }
allOf& intersection on contract declarations
oneOf + discriminatordiscriminated(by=field, A | B)
oneOf / anyOf (no discriminator)| union
enum, pattern, minimum/maximum, minLength/maxLengthtype constraint args

Other exports

For tools that want to operate on the intermediate AST rather than emit .ck source:

import {
    schemasToModels,        // OpenAPI schemas → ContractKit ModelNode[]
    pathsToRoutes,          // OpenAPI paths   → ContractKit OpRouteNode[]
    splitByTag,             // group routes by OpenAPI tag
    mergeIntoSingle,        // collapse roots into one
    detectCircularRefs,     // find $ref cycles
    extractRefName,         // "#/components/schemas/Foo" → "Foo"
    sanitizeName,           // turn an arbitrary string into a valid CK identifier
    normalize,              // upgrade 2.0/3.0 → 3.1 + dereference
    astToCk,                // ContractKit AST → `.ck` source string
    serializeType,          // ContractTypeNode → `.ck` type expression
} from '@contractkit/openapi-to-ck';

Keywords

contractkit

FAQs

Package last updated on 15 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts