百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

autodoc

> 编程语言
开源

从您的机架应用程序和请求规范生成文档

379 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

从您的机架应用程序和请求规范生成文档

Autodoc

Generate documentation from your rack application & request-spec.

Installation

ruby
gem "autodoc", group: :test

If you want to generate toc_html, you should install redcarpet gem (optional).

ruby
gem "redcarpet", group: :test

Usage

Run rspec with AUTODOC=1 to generate documents for your request-specs tagged with :autodoc. example: Autodoc generates doc/recipes.md and doc/toc.md from spec/requests/recipes_spec.rb.

bash
# shell-command
AUTODOC=1 rspec

Examples

For any Rack application with rack-test

ruby
# spec/requests/entries_spec.rb
describe "Entries" do
  include Rack::Test::Methods

  let(:app) do
    MyRackApplication
  end

  describe "GET /entries", autodoc: true do
    it "returns entries" do
      get "/entries"
      last_response.status.should == 200
    end
  end
end

For Rails application with rspec-rails

ruby
# spec/requests/recipes_spec.rb
describe "Recipes" do
  describe "POST /recipes", autodoc: true do
    it "creates a new recipe" do
      post "/recipes", name: "alice", type: 1
      response.status.should == 201
    end
  end
end

Custom description

You can write more detailed descriptions with let(:description).

ruby
describe "Recipes" do
  describe "PUT /recipes/:id", autodoc: true do
    let(:description) do
      "Updates a recipe. `name` parameter is required."
    end

    it "updates a recipe" do
      put "/recipes/#{recipe.id}", name: "Bob"
      response.status.should == 204
    end
  end
end

Configuration

You can configure Autodoc.configuration to change its behavior:

  • path - [String] location to put files (default: ./doc)
  • suppressed_request_header - [Strings] filtered request header keys
  • suppressed_response_header - [Strings] filtered response header keys
  • template - [String] ERB template for each document (default: document.md.erb)
  • toc_template - [String] ERB template for ToC (default: toc.md.erb)
  • toc - [Boolean] whether to generate toc.md (default: false)
  • toc_html_template - [String] ERB template for html ToC (default: toc.html.erb)
  • toc_html - [Boolean] whether to generate toc.html - a single page documentation with a toc (default: false)
  • document_path_from_example - [Proc] specify a Proc to change the naming rule of document file paths
ruby
Autodoc.configuration.path = "doc/api"
Autodoc.configuration.toc = true
Autodoc.configuration.toc_html = true
Autodoc.configuration.template = File.read(File.expand_path("../autodoc/templates/document.md.erb", __FILE__))
Autodoc.configuration.document_path_from_example = -> (example) do
  example.file_path.gsub(%r, '\1.md')
end

WeakParameters integration

If your app uses WeakParameters to define parameters schema in your controller, autodoc scans them and provides ### Parameters section to generated docs.

rb
class RecipesController < ApplicationController
  validates :create do
    string :name, required: true, except: ["charlie", "dave"]
    integer :type, only: 1..3
  end

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyrspec

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言