JSPM

  • Created
  • Published
  • Downloads 3989903
  • Score
    100M100P100Q215298F
  • License MIT

A helper library for loading and saving the .api.json files created by API Extractor

Package Exports

  • @microsoft/api-extractor-model
  • @microsoft/api-extractor-model/lib/aedoc/AedocDefinitions
  • @microsoft/api-extractor-model/lib/aedoc/ReleaseTag
  • @microsoft/api-extractor-model/lib/index
  • @microsoft/api-extractor-model/lib/items/ApiDeclaredItem
  • @microsoft/api-extractor-model/lib/items/ApiDocumentedItem
  • @microsoft/api-extractor-model/lib/items/ApiItem
  • @microsoft/api-extractor-model/lib/items/ApiPropertyItem
  • @microsoft/api-extractor-model/lib/mixins/ApiAbstractMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiExportedMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiInitializerMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiItemContainerMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiNameMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiOptionalMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiParameterListMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiProtectedMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiReadonlyMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiReleaseTagMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiReturnTypeMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiStaticMixin
  • @microsoft/api-extractor-model/lib/mixins/ApiTypeParameterListMixin
  • @microsoft/api-extractor-model/lib/mixins/Excerpt
  • @microsoft/api-extractor-model/lib/mixins/IFindApiItemsResult
  • @microsoft/api-extractor-model/lib/mixins/Mixin
  • @microsoft/api-extractor-model/lib/model/ApiCallSignature
  • @microsoft/api-extractor-model/lib/model/ApiClass
  • @microsoft/api-extractor-model/lib/model/ApiConstructSignature
  • @microsoft/api-extractor-model/lib/model/ApiConstructor
  • @microsoft/api-extractor-model/lib/model/ApiEntryPoint
  • @microsoft/api-extractor-model/lib/model/ApiEnum
  • @microsoft/api-extractor-model/lib/model/ApiEnumMember
  • @microsoft/api-extractor-model/lib/model/ApiFunction
  • @microsoft/api-extractor-model/lib/model/ApiIndexSignature
  • @microsoft/api-extractor-model/lib/model/ApiInterface
  • @microsoft/api-extractor-model/lib/model/ApiMethod
  • @microsoft/api-extractor-model/lib/model/ApiMethodSignature
  • @microsoft/api-extractor-model/lib/model/ApiModel
  • @microsoft/api-extractor-model/lib/model/ApiNamespace
  • @microsoft/api-extractor-model/lib/model/ApiPackage
  • @microsoft/api-extractor-model/lib/model/ApiProperty
  • @microsoft/api-extractor-model/lib/model/ApiPropertySignature
  • @microsoft/api-extractor-model/lib/model/ApiTypeAlias
  • @microsoft/api-extractor-model/lib/model/ApiVariable
  • @microsoft/api-extractor-model/lib/model/Deserializer
  • @microsoft/api-extractor-model/lib/model/DeserializerContext
  • @microsoft/api-extractor-model/lib/model/HeritageType
  • @microsoft/api-extractor-model/lib/model/ModelReferenceResolver
  • @microsoft/api-extractor-model/lib/model/Parameter
  • @microsoft/api-extractor-model/lib/model/SourceLocation
  • @microsoft/api-extractor-model/lib/model/TypeParameter
  • @microsoft/api-extractor-model/package.json

Readme

@microsoft/api-extractor-model

Use this library to read and write *.api.json files as defined by the API Extractor tool. These files are used to generate a documentation website for your TypeScript package. The files store the API signatures and doc comments that were extracted from your package.

API documentation for this package: https://api.rushstack.io/pages/api-extractor-model/

Example Usage

The following code sample shows how to load example.api.json, which would be generated by API Extractor when it analyzes a hypothetical NPM package called example:

import { ApiModel, ApiPackage } from '@microsoft/api-extractor-model';

const apiModel: ApiModel = new ApiModel();
const apiPackage: ApiPackage = apiModel.loadPackage('example.api.json');

for (const member of apiPackage.members) {
  console.log(member.displayName);
}

The ApiModel is acts as a container for various packages that are loaded and operated on as a group. For example, a documentation tool may need to resolve @link references across different packages. In this case we would load the various packages into the ApiModel, and then use the ApiModel.resolveDeclarationReference() to resolve the @link targets.

The data structure forms a tree of various classes that start with the Api prefix. The nesting hierarchy might look like this:

- ApiModel
  - ApiPackage
    - ApiEntryPoint
      - ApiClass
        - ApiMethod
        - ApiProperty
      - ApiEnum
        - ApiEnumMember
      - ApiInterface
        - ApiMethodSignature
        - ApiPropertySignature
      - ApiNamespace
        - (ApiClass, ApiEnum, ApiInterface, ...)

You can use the ApiItem.members property to traverse this tree.

Note that the non-abstract classes (e.g. ApiClass, ApiEnum, ApiInterface, etc.) use TypeScript "mixin" functions (e.g. ApiDeclaredItem, ApiItemContainerMixin, etc.) to add various features that cannot be represented as a normal inheritance chain (since TypeScript does not allow a child class to extend more than one base class). The "mixin" is a TypeScript merged declaration with three components: the function that generates a subclass, an interface that describes the members of the subclass, and a namespace containing static members of the class.

For a complete project that uses these APIs to generate an API reference web site, see the @microsoft/api-documenter source code.

API Extractor is part of the Rush Stack family of projects.