@funboxteam/crafter

中文文档
6.0.2发布于 2023/06/30Apache-2.0CommonJS近 30 天下载 2980

JavaScript replacement of Drafter library for parsing API Blueprint documentation format

原始使用文档
文档目录12 节
  1. Rationale
  2. Features
  3. Installation
  4. Usage
  5. Node.js
  6. CLI
  7. Options
  8. Run tests
  9. Run in Docker
  10. Docker container in Windows
  11. Why API Blueprint
  12. Credits

@funboxteam/crafter

npm (scoped) Coverage Status

Crafter avatar

Crafter is an API Blueprint parser written in pure JavaScript. It is a replacement for Drafter library with some handy features added.

По-русски

Rationale

Drafter is written in C++, so the code is pretty complicated and obscure while containing a lot of bugs and legacy. It is hard to understand how some of its parts work. And if bug fixes are welcomed by maintainers, adding a new feature could become an obstacle.

Our company has a tiny percent of C++ projects, so almost none of the developers can maintain Drafter.

That is why we decided to create own JavaScript replacement which eliminates all previously described limitations, is easy to maintain, and allows us to add all needed features.

Features

Compared to Drafter, this library can offer some important features:

  • Modules. Now it is possible to split one giant file into parts and inject APIB files into each other, which makes documentation easy to use.
  • Resource Prototypes allow you to set up common responses in one place and reuse them through the documentation.
  • Support of arrays in query strings.
  • JSON Schema based types. In case of complex types it is possible to describe them directly as JSON Schema.
  • String validation attributes that describe the expected length of parameters and regular expressions they should match.
  • Describe a non-HTTP interaction (as WebSocket) by means of Message section.

Additional information about how the library works is placed in the docs directory.

Installation

Global install:

npm install -g @funboxteam/crafter

Local install:

npm install --save @funboxteam/crafter

Usage

Node.js

Parse a file:

const crafter = require('@funboxteam/crafter');

const apibFile = 'doc.apib';
const ast = (await crafter.parseFile(apibFile))[0].toRefract();

Or provide a string variable containing APIB documentation:

const crafter = require('@funboxteam/crafter');

const source = '# My API\n\n## List users [GET /users]\n\n+ Response 200';
const ast = (await crafter.parse(source))[0].toRefract();

CLI

To parse a file named doc.apib run the next command:

crafter [options] doc.apib

Options

  • -f, --format <format> — set output format of the parse result. Available formats: json, yaml. Default is yaml.
  • -s, --sourcemap — export source maps in the parse result.
  • -d, --debug — enable debugging mode, which disables catching some of the exceptions.
  • -l, --langserver — enable tolerant mode, which is used in language server.
  • -h, --help — output usage information.

Run tests

npm test

Run in Docker

To run @funboxteam/crafter as a Docker container execute the next command in the directory with documentation:

docker run \
  --rm \
  -v $(pwd):/app \
  funbox/crafter -f json doc-file.apib

The default working directory of the image is set to /app, therefore it is easier to mount a host directory into the /app. Then just a filename as a parameter will do.

Docker container in Windows

To run a container in Windows, add a slash (/) before pwd. The command will look like this:

docker run \
  --rm \
  -v /$(pwd):/app/doc \
  funbox/crafter -f json doc/doc-file.apib

There is a chance that the mounted directory is empty. In this case, check that your hard drive is marked as shared. This setting can be found in the settings of Docker Desktop for Windows, Shared Drives section. If the disk is not shared, mark it as shared, apply changes, and restart Docker Desktop.

Why API Blueprint

We use JSON API widely in the company, so each day our developers face such issues as describing and approving API documentation, tracking changes, distributing documentation among partners, and so on. That is why we felt a strong need for convenient tools to work with documentation.

Historically, the battle was between API Blueprint and Swagger. We chose API Blueprint for two reasons. Firstly, the source code of documentation that is described using API Blueprint is more readable to humans. Secondly, at the time of research conducted, Swagger lacked several important features, as One Of support.

Credits

Awesome logo for the project was made by Igor Garybaldi.

Sponsored by FunBox

版本与发布记录

@funboxteam/crafter 共发布 10 个版本,首次发布于 2022/03/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.2latest2023/06/303 年前
6.0.12023/06/283 年前
6.0.02023/06/053 年前
5.0.12023/04/293 年前
5.0.02023/02/283 年前
4.1.22023/02/273 年前

关于 @funboxteam/crafter 的常见问题

@funboxteam/crafter 是什么?

JavaScript replacement of Drafter library for parsing API Blueprint documentation format

如何安装 @funboxteam/crafter?

在项目目录运行 npm install @funboxteam/crafter,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 crafter,可以用 npx crafter 直接运行。

@funboxteam/crafter 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/funboxteam__crafter 是否存在。

@funboxteam/crafter 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@funboxteam/crafter 可以商用吗?

@funboxteam/crafter 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@funboxteam/crafter 的下载量有多少?

根据 npm 官方下载统计,@funboxteam/crafter 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,980 次,日均约 99 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@funboxteam/crafter 还在维护吗?

最新版本 6.0.2 发布于 2023/06/30(3 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/03/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。