Generate beautiful static API documentation from OpenAPI/Swagger specifications directly in your Rails app.
This gem wraps spectacle-docs to provide Rake tasks and configuration for generating API docs as part of your Rails workflow.
- Node.js >= 20
- npm
Add to your Gemfile:
gem 'spectacle'Then install the spectacle-docs npm package:
rake spectacle:install
# or: npm install -g spectacle-docsCreate an initializer at config/initializers/spectacle.rb:
Spectacle::Config.spec_file = Rails.root.join('public/openapi.yaml').to_s
Spectacle::Config.output_dir = Rails.root.join('public/docs').to_s
# Optional
Spectacle::Config.logo = Rails.root.join('app/assets/images/logo.png').to_s
Spectacle::Config.embeddable = true # Strip <html>/<body> tags for embedding
Spectacle::Config.single_file = true # Bundle everything into one HTML file| Option | Default |
|---|---|
spec_file |
public/openapi.yaml |
output_dir |
public/docs |
logo |
nil |
embeddable |
false |
single_file |
false |
spectacle_bin |
npx spectacle |
rake spectacle:generateThis reads your OpenAPI spec and writes index.html, spectacle.css, and spectacle.js to the output directory.
rake spectacle:validaterake spectacle:install- OpenAPI 3.0 / 3.1
- Swagger 2.0 (auto-converted to OpenAPI 3.0)
- JSON or YAML format
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
MIT