Installing ApiDOM
The @speclynx/apidom-reference package is one of the main entry points for working with ApiDOM. Among other capabilities, it can parse any supported API specification into a semantic data model.
npm install @speclynx/apidom-reference
Requires Node.js >=16.14.2. The package ships with TypeScript type definitions out of the box.
Try it out
Parse an API specification and access its data model right away:
import { parse } from '@speclynx/apidom-reference';
import FileResolver from '@speclynx/apidom-reference/resolve/resolvers/file';
import { toValue } from '@speclynx/apidom-core';
const result = await parse('/path/to/openapi.json', {
resolve: { resolvers: [new FileResolver({ fileAllowList: ['*.json'] })] },
});
toValue(result.api.info.title); // document title
toValue(result.api.info.version); // document version
Local file access is allow-listed for safety: pass a FileResolver with patterns matching the files it may read. Parsing straight from a URL needs no extra configuration: await parse('https://example.com/openapi.json').
parse() returns a data model of typed elements; toValue() from @speclynx/apidom-core turns any element back into its plain JavaScript value. See The Data Model for the full shape of what comes back, or the Parsing page for source maps, style preservation, and parsing from strings.