
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@openpkg-ts/extract
Advanced tools
TypeScript API extraction library. Generates OpenPkg specs from TypeScript source code with JSON Schema 2020-12 output.
npm install @openpkg-ts/extract
# Extract API spec from entry point
tspec src/index.ts -o openpkg.json
# With runtime schema extraction (Zod, Valibot, etc.)
tspec src/index.ts --runtime
# With options
tspec src/index.ts --max-depth 4 --verbose
import { extract } from '@openpkg-ts/extract';
const result = await extract({
entryFile: 'src/index.ts',
maxTypeDepth: 4,
resolveExternalTypes: true,
});
console.log(`Extracted ${result.spec.exports.length} exports`);
console.log(`Found ${result.spec.types?.length ?? 0} types`);
// Check for diagnostics
for (const diag of result.diagnostics) {
console.warn(`${diag.severity}: ${diag.message}`);
}
| Option | Type | Default | Description |
|---|---|---|---|
entryFile | string | required | Entry point file path |
baseDir | string | cwd | Base directory for resolution |
maxTypeDepth | number | 4 | Max depth for type traversal |
resolveExternalTypes | boolean | true | Resolve types from node_modules |
schemaExtraction | 'static' | 'hybrid' | 'static' | Schema extraction mode |
schemaTarget | 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | 'draft-2020-12' | Target JSON Schema dialect |
only | string[] | - | Only extract these exports (supports * wildcards) |
ignore | string[] | - | Ignore these exports (supports * wildcards) |
All schema output is normalized to valid JSON Schema 2020-12. This ensures consistency between static TypeScript analysis and runtime schema extraction from libraries like Zod and Valibot.
Interfaces and classes include a schema property containing a JSON Schema object representation:
{
"kind": "interface",
"name": "User",
"schema": {
"type": "object",
"properties": {
"id": { "type": "string" },
"age": { "type": "number" },
"email": { "type": "string" }
},
"required": ["id", "email"]
},
"members": [...]
}
x-ts-*)TypeScript constructs that don't map directly to JSON Schema are preserved using extension fields:
| Extension | Purpose | Example |
|---|---|---|
x-ts-type | Preserves original TypeScript type | { "type": "integer", "x-ts-type": "bigint" } |
x-ts-function | Marks function types | { "x-ts-function": true, "x-ts-signatures": [...] } |
x-ts-signatures | Function/method signatures | Array of signature objects with parameters and returns |
x-ts-type-arguments | Generic type arguments | { "$ref": "#/types/Promise", "x-ts-type-arguments": [{ "type": "string" }] } |
x-ts-accessor | Getter/setter markers | { "type": "string", "x-ts-accessor": "getter" } |
| TypeScript Type | JSON Schema Output |
|---|---|
void | { "type": "null" } |
never | { "not": {} } |
any | {} |
unknown | {} |
undefined | { "type": "null" } |
bigint | { "type": "integer", "x-ts-type": "bigint" } |
symbol | { "type": "string", "x-ts-type": "symbol" } |
[T, U] (tuple) | { "type": "array", "prefixedItems": [...], "minItems": 2, "maxItems": 2 } |
() => T (function) | { "x-ts-function": true, "x-ts-signatures": [...] } |
Promise<T> | { "$ref": "#/types/Promise", "x-ts-type-arguments": [<T schema>] } |
{
"kind": "function",
"name": "fetchUser",
"signatures": [{
"parameters": [{
"name": "id",
"schema": { "type": "string" },
"required": true
}],
"returns": {
"schema": {
"$ref": "#/types/Promise",
"x-ts-type-arguments": [{ "$ref": "#/types/User" }]
}
}
}]
}
{
"kind": "interface",
"name": "Repository",
"schema": {
"type": "object",
"properties": {
"id": { "type": "string" },
"find": {
"x-ts-function": true,
"x-ts-signatures": [{
"parameters": [{ "name": "query", "schema": { "type": "string" } }],
"returns": { "schema": { "type": "array", "items": { "$ref": "#/types/Item" } } }
}]
}
},
"required": ["id", "find"]
}
}
extract(options) - Main extraction functiongetModuleExports - Get exports from a moduleresolveExportTarget - Resolve re-exports to sourceTypeRegistry - Track and dedupe extracted typesserializeType - Convert TS types to schemanormalizeSchema(schema, options) - Convert SpecSchema to JSON Schema 2020-12normalizeExport(exp, options) - Normalize a SpecExport including nested schemasnormalizeType(type, options) - Normalize a SpecType including nested schemasnormalizeMembers(members, options) - Convert members array to JSON Schema propertiesZodAdapter, ValibotAdapter - Runtime schema extractionMIT
FAQs
TypeScript export extraction to OpenPkg spec
We found that @openpkg-ts/extract demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.