@funboxteam/blueprinter

中文文档
6.1.0发布于 2024/02/01Apache-2.0近 30 天下载 2080

Replacement of Aglio library for rendering generated AST as HTML page.

原始使用文档
文档目录19 节
  1. Rationale
  2. Features
  3. Installation
  4. Usage
  5. CLI options
  6. Run in Docker
  7. Docker and dev server mode
  8. Docker container in Windows
  9. Functional capabilities
  10. Quick access to groups, resources and actions
  11. Search via Ctrl/Cmd + F
  12. Save as PDF
  13. Development
  14. Dependency installation
  15. Run in dev mode
  16. Build
  17. i18n support
  18. Why API Blueprint
  19. Credits

@funboxteam/blueprinter

npm (scoped) Coverage Status

Blueprinter avatar

Blueprinter is an API Blueprint renderer. It uses API AST in the form of API Elements and generates an HTML page with documentation.

По-русски

Rationale

API Blueprint standard is mostly maintained by Apiary, which owns the official parser Drafter. Other enthusiasts help to develop some tools to work with API Blueprint, including renderers.

For a long time, our company had been using Drafter and aglio renderer as a standard set to work with APIB documentation. But we gradually started to understand that functionalities of these tools weren't enough for us.

Blueprinter appeared as a replacement for aglio, since its source code is difficult to read and maintain and used technologies are obsolete. The author of the project has abandoned it and does not accept new change requests. We also replaced Drafter with our own parser Crafter.

Our implementations are written in JavaScript and they are easy to maintain and develop by front-end developers.

Features

  • Modern design. Dark theme included!
  • Search in documentation. You can use part of URL or a title to find groups, resources or actions, and quickly access them.
  • Print version. This version removes all unnecessary content and leaves obligatory content in adapted mode.
  • One Of options selector. Our tool allows you to select different options of One Of element and generate response body dynamically.
  • Manual search page. You may found that the search field is not enough when it comes to finding a part of a description or a particular attribute. Manual search page allows you to use standard browser finder to search through text.
  • Information about parsing warnings and errors. Parsing warnings pop up as a notification. Parsing error which blocks page rendering shows up as a separate page with detailed information.

Installation

npm install --save @funboxteam/blueprinter

Usage

Add the next commands in package.json:

{
  "scripts": {
    "dev": "blueprinter -i doc.apib -s -p 3000",
    "doc": "blueprinter -i doc.apib -o index.html"
  }
}

dev script will run a live server with rendered docs at port 3000 and watch changes in source documentation. doc script will generate resulting HTML file with documentation and save it as index.html.

CLI options

  • -i, --input <file> — sets the source APIB file to render.
  • -o, --output <file> — sets the name of the output HTML file.
  • -s, --server — activates live server mode.
  • -h, --host <host> — sets live server host. Default value is 127.0.0.1.
  • -p, --port <port> — sets live server port. Default value is 3000.
  • --strict — enables parsing "strict" mode in which any warning will cause build error.
  • --css <file> — allows to specify path to a custom CSS file. Styles from this files will be attached to page. Any possible compatibility issues between relevant Blueprinter version and a custom CSS file remain on the conscience of the file developer.
  • --locale <locale> — sets a locale to be used as UI language. Default value is en. Available locales are en, ru.
  • --favicon <file> — allows to specify path to a custom favicon. Applicable only in build mode, not in dev mode. Accepts only PNG files.

Run in Docker

To run Blueprinter as a Docker container execute the next command in the directory with documentation:

docker run \
  --rm \
  -v $(pwd):/app \
  funbox/blueprinter -i doc.apib -o index.html

--rm option will automatically clean up and remove created container after render completion, and -v option will mount current host directory with documentation to some directory in the container.

The default working directory of the image is set to /app, therefore it is easier to mount a host directory into the /app as in the example above. In that case just the name you-doc-file.apib will work fine. Otherwise, you should specify path to the APIB file relative to the created in the container path.

Docker and dev server mode

To run Blueprinter in Docker as a dev server execute the next command in the directory with documentation:

docker run \
  --rm \
  -v $(pwd):/app \
  -p 3000:3000 \
  funbox/blueprinter -i doc.apib -s -p 3000

If you specify -p parameter for Blueprint which differs from 3000, don't forget to open access to this port from your host system and modify Docker option -p port:port.

Attention! When you stop a dev server process via Ctrl/Cmd + C, the process just detaches from a terminal but the container itself still stays running.

To stop container use the next commands:

docker ps # get ID of the running container
docker stop <container> # stop container with specific ID

Docker container in Windows

To run a container in Windows, add a slash (/) before pwd:

docker run \
  --rm \
  -v /$(pwd):/app \
  funbox/blueprinter -i doc.apib -o index.html

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.

Functional capabilities

Quick access to groups, resources and actions

HTML page with rendered documentation has a field to search certain resources. You can set focus on the search field with / key.

The search is performed on the following entities:

  • Titles and descriptions of groups, resources and actions.
  • href of actions.

Search result appear in the next order:

  1. Matching of href of actions.
  2. Matching of titles of groups, resources and actions.
  3. Matching of descriptions of groups, resources and actions.

If a simple search query as empl of /list is not enough, you can apply search modifiers (filters). The general form of a query is modType:modValue query where query is the desired search query. You can filter results by resource type and by HTTP method.

  • To filter by type use type:action query. Available values are type:group query, type:resource query, type:action query.
  • To filter by method use method:METHOD query where METHOD is one of HTTP methods (GET, POST, DELETE, and so on). Both lowercase and uppercase will do.

So, to list only GET requests with href containing employ, type in the search field:

method:get employ

To apply modifier, search query should start with modType. It means that if you need to find in doc the phrase method:get - filter example, you can use whitespace as the first symbol of the query ( method:get - filter example). In this case no modifiers will be applied, leading whitespace won't be considered, and search will be performed exactly on the phrase method:get - filter example.

Search via Ctrl/Cmd + F

APIB documentation can contain a lot of diverse entities, so the search field probably won't be helpful in some cases where you need to find an attribute value or a URI parameter. To find something manually we added a separate page with sequential list of all content of a documentation. To access this page, press icon button right to the search field.

The page contains all groups, resources, requests, and responses outputted consequently. All attributes in Attributes sections are expanded. Therefore, you can search through documentation by browser means, e.g. using Ctrl + F key combination.

Save as PDF

PDF-version of a documentation is optimized for easy viewing. List of content at the beginning of a doc provides easy access to the selected section. All blocks with JSON schemas are hidden.

To save documentation as PDF in Chrome browsers, follow the next steps:

  • navigate to the manual search page via icon button next to the search field;
  • in browser context menu select print option;
  • in the print dialog select destination "Save as PDF" and layout mode "Portrait";
  • save documentation with selected settings.

Development

Dependency installation

npm install

Run in dev mode

npm start

Default dev server address is http://localhost:8080.

Build

To build project locally run

npm run build

i18n support

This project supports multiple locales for UI texts (for now, English and Russian languages are provided).

To mark text as translated, use t or Trans from @lingui/macro. To make translation appear in the actual interface, the next steps should be done:

  • run npm run extract to update JSON translations catalogs (see src/locales/{locale}/messages);
  • fill in missed translations for new texts;
  • run npm run compile to compile translation catalogs to JavaScript files;
  • commit all changes.

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/blueprinter 共发布 14 个版本,首次发布于 2022/07/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.1.0latest2024/02/012 年前
6.0.02023/06/063 年前
5.4.22023/05/273 年前
5.4.12023/05/253 年前
5.4.02023/05/203 年前
5.3.22023/05/123 年前

关于 @funboxteam/blueprinter 的常见问题

@funboxteam/blueprinter 是什么?

Replacement of Aglio library for rendering generated AST as HTML page.

如何安装 @funboxteam/blueprinter?

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

@funboxteam/blueprinter 支持 TypeScript 吗?

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

@funboxteam/blueprinter 可以商用吗?

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

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

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

@funboxteam/blueprinter 还在维护吗?

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