# @spec2ts/core

> Core module for @spec2ts modules, includes codegen helpers and common parsing methods

Latest version **4.1.1** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @spec2ts/core
pnpm add @spec2ts/core
yarn add @spec2ts/core
bun add @spec2ts/core
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2026-09-07 |
| First published | 2020-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 32.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Touchify |
| Maintainers | mluce, mtrimolet |
| Keywords | ast, compile, compiler, interface, share, spec, spec2ts, transpile, typescript, typing |

## Links

- npm: https://www.npmjs.com/package/@spec2ts/core
- Repository: https://github.com/touchifyapp/spec2ts
- Homepage: https://github.com/touchifyapp/spec2ts#readme
- Issues: https://github.com/touchifyapp/spec2ts/issues
- npm.io page: https://npm.io/package/@spec2ts/core

## Dependencies (2)

- [glob](https://npm.io/package/glob.md) ^13.0.6
- [typescript](https://npm.io/package/typescript.md) ^6.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.1.1 (latest) — 2026-09-07
- 4.1.0 — 2026-09-07
- 4.0.1 — 2026-07-09
- 4.0.0 — 2026-07-09
- 3.0.2 — 2023-10-03
- 3.0.1 — 2023-09-25
- 3.0.0 — 2023-09-12
- 2.0.0 — 2023-09-08
- 2.0.0-beta.3 — 2022-09-21
- 2.0.0-beta.2 — 2022-01-27
- 2.0.0-beta.1 — 2021-10-23
- 2.0.0-beta.0 — 2020-11-13
- 1.2.2 — 2020-10-26
- 2.0.0-alpha.0 — 2020-10-17
- 1.2.1 — 2020-05-27
- … 4 more at https://npm.io/package/@spec2ts/core/versions

## README

# spec2ts

![CI](https://github.com/touchifyapp/spec2ts/workflows/CI/badge.svg)

`spec2ts` is an utility to create TypeScript types from JSON schemas and OpenAPI v3 specifications. Unlike other code generators `spec2ts` does not use templates to generate code but uses TypeScript's built-in API to generate and pretty-print an abstract syntax tree (AST).

## Features

- **AST-based:** Unlike other code generators `spec2ts` does not use templates to generate code but uses TypeScript's built-in API to generate and pretty-print an abstract syntax tree.
- **Tree-shakeable:** Individually exported types allows you to bundle only the ones you actually use.
- **YAML or JSON:** Use YAML or JSON for your or OpenAPI Specifications and JSON Schemas.
- **External references:** Resolves automatically external references and bundle or import them in generated files.
- **Implementation agnostic:** Use generated types in any projet or framework.

## Components

- `@spec2ts/core`: Helpers methods to generate TypeScript code.
- `@spec2ts/jsonschema`: Utility to generate types from JSON schemas. [More details](https://github.com/touchifyapp/spec2ts/blob/master/packages/jsonschema/README.md).
- `@spec2ts/openapi`: Utility to generate types from Open API v3 specifications. [More details](https://github.com/touchifyapp/spec2ts/blob/master/packages/openapi/README.md).
- `@spec2ts/openapi-client`: Utility to generate HTTP Client from Open API v3 specifications. [More details](https://github.com/touchifyapp/spec2ts/blob/master/packages/openapi-client/README.md).
- `@spec2ts/cli`: CLI wrapper to generate types from Open API v3 specifications and JSON schemas. [More details](https://github.com/touchifyapp/spec2ts/blob/master/packages/cli/README.md).

## Installation

Install in your project:

```bash
npm install @spec2ts/cli
```

## CLI Usage

```bash
# Generate TypeScript types from JSON Schemas
spec2ts jsonschema -o path/to/output path/to/my/*.schema.json

# Generate TypeScript types from Open API specification
spec2ts openapi -o path/to/output path/to/my/specification.yml

# Generate TypeScript HTTP Client from Open API specification
spec2ts openapi-client -o path/to/output.ts path/to/my/specification.yml
```

You can find more details in the `@spec2ts` [documentation](https://github.com/touchifyapp/spec2ts/blob/master/packages/jsonschema/README.md).

## Programmatic Usage

#### Generate TypeScript types from JSON Schemas

```typescript
import { printer } from "@spec2ts/core";
import { parseSchema, JSONSchema } from "@spec2ts/jsonschema";

async function generateSchema(schema: JSONSchema): Promise<string> {
    const result = await parseSchema(schema);
    return printer.printNodes(result);
}
```

#### Generate TypeScript types from OpenAPI Specifications

```typescript
import { printer } from "@spec2ts/core";
import { parseOpenApiFile } from "@spec2ts/openapi";

async function generateSpec(path: string): Promise<string> {
    const result = await parseOpenApiFile(path);
    return printer.printNodes(result);
}
```

#### Generate TypeScript Client types from OpenAPI Specifications

```typescript
import { printer } from "@spec2ts/core";
import { generateClientFile } from "@spec2ts/openapi-client";

async function generateClient(path: string): Promise<string> {
    const result = await generateClientFile(path);
    return printer.printNodes(result);
}
```

## Compatibility Matrix

| TypeScript version | spec2ts version |
| ------------------ | --------------- |
| v3.x.x             | v1              |
| v4.x.x             | v2              |
| v5.x.x             | v3              |
| v6.x.x             | v4              |

## License

This project is under MIT License. See the [LICENSE](LICENSE) file for the full license text.

---
_Source: https://npm.io/package/@spec2ts/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
