OpenPkg Specification
A machine-readable standard for describing package APIs
Abstract
The OpenPkg Specification defines a standard, language-service-independent interface description for TypeScript packages. An OpenPkg document describes the complete public surface of a package (its functions, classes, interfaces, type aliases, enums, and variables) as JSON Schema, allowing both humans and machines to discover and understand the capabilities of a package without access to its source code, its node_modules, or a TypeScript compiler.
An OpenPkg document can then be used by documentation generators to display the API, code-generation tools to consume it, diff tools to detect breaking changes between versions, and agents to reason about a package's capabilities.
Status of This Document
This is a draft of the 0.4.0 line of the specification. It is published for implementers and is subject to change. The canonical JSON Schema for validation is published with each release of @openpkg-ts/spec. Earlier document versions 0.2.0 and 0.3.0 remain valid; see § 9 Versioning.
1.Introduction
TypeScript's type system is the richest description of a JavaScript package's behavior, but that description is locked inside the compiler: consuming it requires source files, dependency installation, and a type checker. The OpenPkg Specification extracts that description into a single portable JSON document, in the same way the OpenAPI Specification extracts the description of an HTTP service out of its implementation.
A conforming document is self-contained. Every named type referenced by an exported symbol is either inlined as a schema or declared in the document's types section and referenced by a JSON Reference. Consumers never need to resolve anything outside the document.
2.Notational Conventions
The key words must, must not, required, shall, should, should not, recommended, may, and optional in this document are to be interpreted as described in [RFC2119].
Fields marked required in the tables below must be present. All other fields are optional. Producers must not emit fields whose value is undefined; omission and undefined are equivalent.
3.Format and Media Type
An OpenPkg document is a single JSON object encoded in UTF-8. The conventional filename is openpkg.json. Schema values within the document are expressed in a constrained profile of JSON Schema draft 2020-12 [JSON-SCHEMA], extended with the vendor fields defined in § 5.6.
A document may declare the meta-schema it validates against via the $schema field:
{ "$schema": "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json" }
4.Document Structure
The root of every OpenPkg document is the OpenPkg Object.
| Field | Type | Description |
|---|---|---|
| openpkg | required · string | The version of the OpenPkg Specification this document conforms to: "0.2.0", "0.3.0", or "0.4.0". |
| meta | required · Meta Object | Identity of the described package. |
| exports | required · [Export Object] | Every symbol exported from the package entry point, in declaration order. |
| types | [Type Object] | Named types referenced by exports. The target namespace for #/types/… references. |
| $schema | string | URI of the meta-schema for this document. |
| examples | [Example Object] | Package-level usage examples. |
| extensions | object | Specification extensions; see § 7. |
| generation | Generation Object | Provenance metadata describing how the document was produced. |
5.Object Definitions
5.1Meta Object
| Field | Type | Description |
|---|---|---|
| name | required · string | Package name as published (e.g. "@openpkg-ts/sdk"). |
| version | string | Package version the document was extracted from. |
| description | string | Short package description. |
| license | string | SPDX license identifier. |
| repository | string | Repository URL. |
| ecosystem | string | Source ecosystem. Producers targeting npm should emit "js/ts". |
5.2Export Object
Describes one exported symbol. The kind field determines which of the remaining fields are meaningful: callable kinds carry signatures, structural kinds carry members, and value kinds carry schema.
| Field | Type | Description |
|---|---|---|
| id | required · string | Document-unique identifier for the export. |
| name | required · string | The exported name. |
| kind | required · string | One of the kinds in Appendix A. |
| description | string | Documentation comment, with tags stripped. |
| signatures | [Signature Object] | Call signatures. One entry per overload; see overloadIndex. |
| members | [Member Object] | Properties, methods, accessors, and enum members. |
| schema | Schema Object | The symbol's type as a schema (variables, type aliases). |
| typeParameters | [TypeParameter Object] | Generic parameters: name, constraint, default, variance, const. |
| extends | string | Name of the extended class or interface. |
| implements | [string] | Implemented interface names. |
| source | Source Object | Where the symbol is declared. |
| deprecated | boolean | Whether the symbol carries a @deprecated tag. |
| deprecationReason | string | Text of the @deprecated tag, when present. |
| examples | [Example Object] | Code examples from @example tags. |
| tags | [Tag Object] | Remaining JSDoc tags: name, text, structured param. |
Note. Type aliases additionally carry typeAliasKind ("alias" · "conditional" · "mapped" · "template-literal" · "infer") with structural detail in conditionalType / mappedType, so consumers can render conditional and mapped types faithfully.
5.3Signature Object
| Field | Type | Description |
|---|---|---|
| parameters | [Parameter Object] | Ordered parameters: name, schema (required), required, default, rest, description. |
| returns | Return Object | schema (required) and optional description from @returns. |
| typeParameters | [TypeParameter Object] | Generic parameters scoped to this signature. |
| throws | [Throws Object] | Declared failure modes from @throws: type, description. |
| overloadIndex | integer | Zero-based position among overloads of the same symbol. |
| isImplementation | boolean | Marks the implementation signature of an overloaded function. |
| description | string | Per-overload documentation. |
| examples | [Example Object] | Per-overload examples. |
5.4Member Object
Describes one member of a class, interface, or enum. Fields mirror the Export Object where meaningful: name, kind, description, schema, signatures, tags, deprecated. Two fields are member-specific:
visibility"public"·"protected"·"private". Producers should omit private members unless explicitly configured otherwise.flags- Modifier map (e.g.
static,readonly,abstract,async,optional).
Members inherited from a base class are listed with an inheritedFrom field naming the ancestor, so consumers can render flattened or hierarchical views without re-walking the inheritance chain.
5.5Type Object
A named type declared in the document's types section. Type Objects are the targets of #/types/… references and use the same field vocabulary as Export Objects (id, name, kind, schema, members, source, extends, implements). Its kind is one of "class" · "interface" · "type" · "enum" · "external". Types resolved from a package's dependencies carry external: true together with a Source Object naming the providing package.
5.6Schema Object
Type shapes are expressed as JSON Schema draft 2020-12 vocabulary: type, properties, required, items, enum, additionalProperties, anyOf, allOf, oneOf, and $ref. TypeScript constructs with no JSON Schema equivalent are preserved through the following vendor extensions, which consumers may ignore without losing structural validity:
| Extension | Purpose |
|---|---|
| x-ts-type | Preserves the original TypeScript type where the JSON Schema mapping loses fidelity (bigint → integer, symbol → string, void, never, unknown, …). |
| x-ts-function | Marks a schema as a callable function type. |
| x-ts-signatures | Carries the Signature Objects of a callable type. |
| x-ts-type-arguments | Preserves generic instantiation on a $ref (e.g. Map<string, number>). |
| x-ts-type-predicate | Preserves type-guard narrowing: the parameter name and narrowed type of value is T. |
| x-ts-package | Names the providing package on an external type reference. |
Unions of literals collapse to enum. Optional properties are expressed by omission from required, never by | undefined in the schema. Tuples use items with minItems/maxItems. Index signatures map to additionalProperties.
5.7Source Object
| Field | Type | Description |
|---|---|---|
| file | string | Declaring file, relative to the package root. |
| line | integer | 1-based line of the declaration. |
| url | string | Permalink to the declaration, when a repository is known. |
| package | string | Providing package, for external types. |
| version | string | Version of the providing package. |
5.8Generation Object
Optional provenance for the document: generator (tool name and version), timestamp (ISO 8601), mode ("source" or "declaration-only"), known limitations of declaration-only extraction, and a skipped list naming exports the producer omitted and why ("filtered" · "no-declaration" · "internal" · "external-unresolved"). Consumers must not treat generation metadata as part of the described API.
6.Type References
A schema referencing a named type uses a JSON Reference whose target is the document's own types section:
{ "$ref": "#/types/ExtractOptions" }
The fragment must take the form #/types/{id}, where {id} matches the id of exactly one Type Object. Producers must emit a Type Object for every reference target (no dangling references) and must not reference targets outside the document. Generic instantiations attach x-ts-type-arguments beside the $ref rather than minting new type entries per instantiation.
7.Specification Extensions
Two extension surfaces exist. Schema-level extensions are the x- prefixed fields of § 5.6. Document-level extensions live under the root extensions object, which is an open map; the single field defined by this specification is presentation, a map from export id to display metadata (slug, displayName, category, importPath, alias) for documentation front ends. Unknown extension fields must be preserved by tools that rewrite documents.
8.Complete Example
A minimal, conforming document describing a package with one function and one referenced interface:
{
"$schema": "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json",
"openpkg": "0.4.0",
"meta": {
"name": "greeter",
"version": "1.0.0",
"ecosystem": "js/ts"
},
"exports": [
{
"id": "greet",
"name": "greet",
"kind": "function",
"description": "Render a greeting for a person.",
"signatures": [
{
"parameters": [
{ "name": "person", "required": true,
"schema": { "$ref": "#/types/Person" } }
],
"returns": { "schema": { "type": "string" } }
}
],
"source": { "file": "src/index.ts", "line": 12 }
}
],
"types": [
{
"id": "Person",
"name": "Person",
"kind": "interface",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
},
"required": ["name"]
},
"source": { "file": "src/index.ts", "line": 4 }
}
]
}
9.Versioning and Conformance
The specification is versioned by the root openpkg field. Recognized versions are 0.2.0, 0.3.0, and 0.4.0; each publishes its own JSON Schema. Within the 0.x line, minor versions may add fields but must not change the meaning of existing ones.
A document is conforming when it validates against the JSON Schema of its declared version and satisfies the prose constraints of this document (no dangling references, no undefined members in required, unique id values). A consumer is conforming when it accepts every conforming document of the versions it claims to support and ignores unrecognized x- fields rather than rejecting them.
Appendix A. Export Kinds
| Kind | Meaning |
|---|---|
| function | Callable export; carries signatures. |
| class | Class declaration; carries members, optionally extends / implements. |
| interface | Interface declaration; carries members. |
| type | Type alias; carries schema and optionally typeAliasKind. |
| enum | Enum declaration; carries members with constant values. |
| variable | Exported value; carries schema. |
| namespace | Namespace export; members are listed as their own exports. |
| module | Module re-export. |
| reference | Re-exported symbol declared elsewhere in the document. |
| external | Re-exported symbol originating in another package. |
Normative References
- [RFC2119]
- Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", RFC 2119, March 1997.
- [JSON-SCHEMA]
- "JSON Schema: A Media Type for Describing JSON Documents", draft 2020-12.
- [RFC8259]
- Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 8259, December 2017.