OpenPkg Specification

A machine-readable standard for describing package APIs

Version
0.4.0
Status
Draft
This document
12 July 2026
Schema
openpkg.schema.json (JSON Schema draft 2020-12) · npm mirror
Editor
Ryan Waits
Reference implementation
openpkg-ts (TypeScript): @openpkg-ts/spec · @openpkg-ts/sdk · @openpkg-ts/cli
License
MIT

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.

Table 1. OpenPkg Object, top-level fields
FieldTypeDescription
openpkgrequired · stringThe version of the OpenPkg Specification this document conforms to: "0.2.0", "0.3.0", or "0.4.0".
metarequired · Meta ObjectIdentity of the described package.
exportsrequired · [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.
$schemastringURI of the meta-schema for this document.
examples[Example Object]Package-level usage examples.
extensionsobjectSpecification extensions; see § 7.
generationGeneration ObjectProvenance metadata describing how the document was produced.

5.Object Definitions

5.1Meta Object

Table 2. Meta Object
FieldTypeDescription
namerequired · stringPackage name as published (e.g. "@openpkg-ts/sdk").
versionstringPackage version the document was extracted from.
descriptionstringShort package description.
licensestringSPDX license identifier.
repositorystringRepository URL.
ecosystemstringSource 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.

Table 3. Export Object
FieldTypeDescription
idrequired · stringDocument-unique identifier for the export.
namerequired · stringThe exported name.
kindrequired · stringOne of the kinds in Appendix A.
descriptionstringDocumentation comment, with tags stripped.
signatures[Signature Object]Call signatures. One entry per overload; see overloadIndex.
members[Member Object]Properties, methods, accessors, and enum members.
schemaSchema ObjectThe symbol's type as a schema (variables, type aliases).
typeParameters[TypeParameter Object]Generic parameters: name, constraint, default, variance, const.
extendsstringName of the extended class or interface.
implements[string]Implemented interface names.
sourceSource ObjectWhere the symbol is declared.
deprecatedbooleanWhether the symbol carries a @deprecated tag.
deprecationReasonstringText 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

Table 4. Signature Object
FieldTypeDescription
parameters[Parameter Object]Ordered parameters: name, schema (required), required, default, rest, description.
returnsReturn Objectschema (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.
overloadIndexintegerZero-based position among overloads of the same symbol.
isImplementationbooleanMarks the implementation signature of an overloaded function.
descriptionstringPer-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:

Table 5. Schema Object vendor extensions
ExtensionPurpose
x-ts-typePreserves the original TypeScript type where the JSON Schema mapping loses fidelity (bigintinteger, symbolstring, void, never, unknown, …).
x-ts-functionMarks a schema as a callable function type.
x-ts-signaturesCarries the Signature Objects of a callable type.
x-ts-type-argumentsPreserves generic instantiation on a $ref (e.g. Map<string, number>).
x-ts-type-predicatePreserves type-guard narrowing: the parameter name and narrowed type of value is T.
x-ts-packageNames 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

Table 6. Source Object
FieldTypeDescription
filestringDeclaring file, relative to the package root.
lineinteger1-based line of the declaration.
urlstringPermalink to the declaration, when a repository is known.
packagestringProviding package, for external types.
versionstringVersion 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

Table 7. kind values for Export Objects
KindMeaning
functionCallable export; carries signatures.
classClass declaration; carries members, optionally extends / implements.
interfaceInterface declaration; carries members.
typeType alias; carries schema and optionally typeAliasKind.
enumEnum declaration; carries members with constant values.
variableExported value; carries schema.
namespaceNamespace export; members are listed as their own exports.
moduleModule re-export.
referenceRe-exported symbol declared elsewhere in the document.
externalRe-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.