Code Monkey home page Code Monkey logo

dox's Introduction

Build Status Code Climate Test Coverage

Dox

Automate your documentation writing process! Dox generates API documentation from Rspec controller/request specs in a Rails application. It formats the tests output in the OpenApi format. Use the ReDoc renderer for generating and displaying the documentation as HTML.

Here's a demo app.

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'dox', require: false
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install dox

Usage

Require it

Require Dox in the rails_helper:

require 'dox'

Configure it

Set these optional options in the rails_helper:

Option Value Description
descriptions_location Pathname instance or fullpath string (can be an array) Folder containing markdown descriptions of resources.
schema_request_folder_path Pathname instance or fullpath string Folder with request schemas of resources.
schema_response_folder_path Pathname instance or fullpath string Folder with response schemas of resources.
schema_response_fail_file_path Pathname instance or fullpath string Json file that contains the default schema of a failed response.
openapi_version string Openapi version (default: '3.0.0' )
api_version string Api Version (default: '1.0')
title string Documentation title (default: 'API Documentation')
header_description Pathname instance or string Description (header) of the documentation (default: ''). If pathname ends with .md, the file is looked in descriptions_location folder
headers_whitelist Array of headers (strings) Requests and responses will by default list only Content-Type header. To list other http headers, you must whitelist them.

Example:

Dox.configure do |config|
  config.descriptions_location  = Rails.root.join('spec/docs/v1/descriptions')
  config.schema_request_folder_path = Rails.root.join('spec/docs/v1/schemas')
  config.schema_response_folder_path = Rails.root.join('spec/support/v1/schemas')
  config.schema_response_fail_file_path = Rails.root.join('spec/support/v1/schemas/error.json')
  config.headers_whitelist = ['Accept', 'X-Auth-Token']
  config.title = 'API'
  config.api_version = '2.0'
  config.header_description = 'api_description.md'
end

Basic example

Define a descriptor module for a resource using Dox DSL:

module Docs
  module V1
    module Bids
      extend Dox::DSL::Syntax

      # define common resource data for each action
      document :api do
        resource 'Bids' do
          group 'Bids'
          desc 'bids.md'
        end
      end

      # define data for specific action
      document :index do
        action 'Get bids'
      end
    end
  end
end

You can define the descriptors for example in specs/docs folder, just make sure you load them in the rails_helper.rb:

Dir[Rails.root.join('spec/docs/**/*.rb')].each { |f| require f }

Include the descriptor modules in a controller and tag the specs you want to document with dox:

describe Api::V1::BidsController, type: :controller do
  # include resource module
  include Docs::V1::Bids::Api

  describe 'GET #index' do
    # include action module
    include Docs::V1::Bids::Index

    it 'returns a list of bids', :dox do
      get :index
      expect(response).to have_http_status(:ok)
    end
  end
end

And generate the documentation.

Advanced options

Before running into any more details, here's roughly how the generated OpenApi document is structured:

  • openapi
  • info
  • paths
    • action 1
      • tag1
      • example 1
      • example 2
    • action 2
      • tag2
      • example 3
  • x-tagGroups - tags1 - tag 1 - tag 2 - tags2 - tag 3 - tag 4
  • tags
    • tag1
    • tag2

OpenApi and info are defined in a json file as mentioned before. Examples are concrete test examples (you can have multiple examples for both happy and fail paths). They are completely automatically generated from the request/response objects. And you can customize the following in the descriptors:

  • x-tagGroup (resourceGroup)
  • tag (resource)
  • action
  • example

ResourceGroup

ResourceGroup contains related resources and is defined with:

  • name (required)
  • desc (optional, inline string or relative filepath)

Example:

document :bids_group do
  group 'Bids' do
    desc 'Here are all bid related resources'
  end
end

You can omit defining the resource group, if you don't have any description for it. Related resources will be linked in a group by the group option at the resource definition.

Resource

Resource contains actions and is defined with:

  • name (required)
  • group (required; to associate it with the related group)
  • desc (optional; inline string or relative filepath)

Example:

document :bids do
  resource 'Bids' do
    group 'Bids'
    desc 'bids/bids.md'
  end
end

Usually you'll want to define resourceGroup and resource together, so you don't have to include 2 modules with common data per spec file:

document :bids_common do
  group 'Bids' do
    desc 'Here are all bid related resources'
  end

  resource 'Bids' do
    group 'Bids'
    desc 'bids/bids.md'
  end
end

Action

Action contains examples and is defined with:

  • name (required)
  • path* (optional)
  • verb* (optional)
  • params (optional; depricated)
  • query_params (optional; more info)
  • desc (optional; inline string or relative filepath)
  • request_schema (optional; inline string or relative filepath)
  • response_schema_success (optional; inline string or relative filepath)
  • response_schema_fail (optional; inline string or relative filepath)

* these optional attributes are guessed (if not defined) from the request object of the test example and you can override them.

Example:

show_params = { id: { type: :number, required: :required, value: 1, description: 'bid id' } }
query_params = [ {
  "in": "query",
  "name": "filter",
  "required": false,
  "style": "deepObject",
  "explode": true,
  "schema": {
    "type": "object",
    "required": ["updated_at_gt"],
    "example": {
      "updated_at_gt": "2018-02-03 10:30:00"
    },
    "properties": {
      "updated_at_gt": {
        "type": "string",
        "title": "date"
      }
    }
  }
]

document :action do
  action 'Get bid' do
    path '/bids/{id}'
    verb 'GET'
    params show_params
    query_params query_params
    desc 'Some description for get bid action'
    request_schema 'namespace/bids'
    response_schema_success 'namespace/bids_s'
    response_schema_fail 'namespace/bids_f'
  end
end

Generate documentation

Documentation is generated in 2 steps:

  1. generate OpenApi json file: bundle exec rspec --tag apidoc -f Dox::Formatter --order defined --tag dox --out spec/api_doc/v1/schemas/docs.json

  2. render HTML with Redoc: redoc-cli bundle -o public/api/docs/v2/docs.html spec/api_doc/v1/schemas/docs.json

Use rake tasks

It's recommendable to write a few rake tasks to make things easier. Here's an example:

namespace :dox do
  desc 'Generate API documentation markdown'

  task :json, [:version, :docs_path, :host] => :environment do |_, args|
    require 'rspec/core/rake_task'
    version = args[:version] || :v1

    RSpec::Core::RakeTask.new(:api_spec) do |t|
      t.pattern = "spec/requests/api/#{version}"
      t.rspec_opts =
        "-f Dox::Formatter --tag dox --order defined --out spec/docs/#{version}/apispec.json"
    end

    Rake::Task['api_spec'].invoke
  end

  task :html, [:version, :docs_path, :host] => :json do |_, args|
    version = args[:version] || :v1
    docs_path = args[:docs_path] || "api/#{version}/docs"

    `yarn run redoc-cli bundle -o public/#{docs_path}/index.html spec/docs/#{version}/apispec.json`
  end

  task :open, [:version, :docs_path, :host] => :html do |_, args|
    version = args[:version] || :v1
    docs_path = args[:docs_path] || "api/#{version}/docs"

    `open public/#{docs_path}/index.html`
  end
end

Renderers

You can render the HTML yourself with ReDoc:

Common issues

You might experience some strange issues when generating the documentation. Here are a few examples of what we've encountered so far.

Uninitialized constant errors

There seems to be a problem with rspec-rails versions 3.7 and later not automatically requiring the project's rails_helper.rb when run with the --format flag.

To fix this issue, generate your documentation with --require rails_helper:

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/infinum/dox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Credits

Dox is maintained and sponsored by Infinum.

Infinum

License

The gem is available as open source under the terms of the MIT License.

dox's People

Contributors

cilim avatar d4be4st avatar damirsvrtan avatar dariodaich avatar jasonkarns avatar manuraj17 avatar melcha avatar murjax avatar nikajukic avatar raymondboswel avatar vkuzina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dox's Issues

I think headers_whitelist does not work

When i add ['Accpet'] to headers_whitelist this is what i get:

    + Headers

            Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
            Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
            Content-Type: application/x-www-form-urlencoded

grape api and request specs

Reverse the logic to whitelisting examples that should be documented

Right now, every example is by default included in the generated documentation, and blacklisting examples is done with :nodoc option.

This is a problem when you have a lot of "it" blocks for each action - documentation gets bloated.

This should be dropped in the new version and tests that should be documented should be whitelisted with :doc or similar option.

Dox::Entities::Action - ArgumentError: wrong number of arguments (0 for 1)

Hitting an exception on this line:

@verb = details[:action_verb] || request.method

https://github.com/infinum/dox/blob/master/lib/dox/entities/action.rb#L11

In my app, request is a Proc and Proc#method expects a symbol as an argument: https://ruby-doc.org/core-2.2.0/Object.html#method-i-method

Some context:

# ./spec/requests/groups/show_spec.rb
describe %(get '/api/groups/:id'), type: :request do
  include Docs::Groups::Api
  let!(:path) { %(/api/groups/#{group.id}) }
  let!(:user) { create(:user_with_groups) }
  let!(:group) { user.groups.last }
  
  context 'when a user is signed in' do
    before { sign_in user }
    before { get path }
    after { sign_out user }

    it 'returns http success (2xx)', :dox do
      include Docs::Groups::Show
      expect(response).to have_http_status(:success)
    end
  end

end

# ./spec/docs/groups.rb
module Docs
  module Groups
    extend Dox::DSL::Syntax

    # define common resource data for each action
    document :api do
      resource 'Groups' do
        endpoint '/groups'
        group 'Groups'
      end
    end

    # define data for specific action
    document :index do
      action 'Get groups'
    end

    document :show do
      action 'Get a group'
    end

  end
end

Error when content-type and accept headers are not application/json

When content-type and accept headers on request are not application/json, e.g. they're set to application/vnd.api+json I get a JSON::ParserError: 784: unexpected token when trying to generate documentation.

When response returns application/vnd.api+json in the headers, documentation can be generated.

Show all response headers

Eventually add a config option to ignore certain headers (a blacklist), but I can live without having that option for now.

Can not override action params to be empty

There are only internal params for an action that we use as route default params, but do not want to show in documentation.
I would expect that using

params({})

within an action should remove all the params, but it shows the default ones (that are passed within example request) instead.
Is this expected for some reason on needs a fix?

The current ugly workaround for me is

params(Struct.new(:presence).new({}))

as the gem is using presence internally.

Multipart/form-data support

I run into an issue with generating documentation for next test case:

describe 'Success' do
  let(:headers) { { Authorization: 'auth token' } }
  let(:params) { { image: fixture_file_upload('files/image.jpeg', 'image/jpg') } }

  before do
    put '/api/v1/company/logo', params: params, headers: headers
  end

  it 'renders with updated image' do
    expect(response).to be_ok
    expect(response).to match_json_schema('image/update')
  end
end

My config in rails_helper.rb:

require 'dox'

...

Dox.configure do |config|
  config.header_file_path = Rails.root.join('spec', 'api_doc', 'v1', 'descriptions', 'header.md')
  config.desc_folder_path = Rails.root.join('spec', 'api_doc', 'v1', 'descriptions')
  config.headers_whitelist = ['Accept', 'X-Refresh-Token']
end

config.after(:each, :dox) do |example|
  example.metadata[:request] = request
  example.metadata[:response] = response
end

The error trace:

Traceback (most recent call last):
         6: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/action_printer.rb:9:in `print'
         5: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/action_printer.rb:9:in `each'
         4: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/action_printer.rb:10:in `block in print'
         3: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/example_printer.rb:8:in `print'
         2: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/example_printer.rb:21:in `print_example_request'
         1: from /Users/user/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/example_printer.rb:21:in `puts'
/Users/alexandr/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/dox-1.1.0/lib/dox/printers/example_printer.rb:21:in `write': "\xFF" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

As it can be seen while debugging it stumbles upon raw image data in request's body.

Header parameters are not generated according to openapi spec

Thank you for this amazing gem!

The schema option need to be added for header parameters. According to open api 3.0.0, parameters should have a schema property.

...
paths:
  /post:
    post:
      parameters:
        - in: header
          name: X-username
          schema:
            type: string
            example: user12345

Currently headers don't have schema property.

paths:
  /post:
    post:
      parameters:
        - in: header
          name: X-username
          example: user12345

Can you please address this issue ?

Uninitialized constant Dox::Formatter::Forwardable

When I run rspec -f Dox::Formatter I get:

Traceback (most recent call last):
        17: from /usr/local/bundle/bin/rspec:23:in `<main>'
        16: from /usr/local/bundle/bin/rspec:23:in `load'
        15: from /usr/local/bundle/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
        14: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
        13: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
        12: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:86:in `run'
        11: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:99:in `setup'
        10: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:23:in `configure'
         9: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `load_formatters_into'
         8: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `each'
         7: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `block in load_formatters_into'
         6: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:878:in `add_formatter'
         5: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:146:in `add'
         4: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:177:in `find_formatter'
         3: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:225:in `custom_formatter'
         2: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:225:in `inject'
         1: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:225:in `each'
/usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:225:in `block in custom_formatter': uninitialized constant Dox (NameError)
        17: from /usr/local/bundle/bin/rspec:23:in `<main>'
        16: from /usr/local/bundle/bin/rspec:23:in `load'
        15: from /usr/local/bundle/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
        14: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
        13: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
        12: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:86:in `run'
        11: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:99:in `setup'
        10: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:23:in `configure'
         9: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `load_formatters_into'
         8: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `each'
         7: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `block in load_formatters_into'
         6: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:878:in `add_formatter'
         5: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:146:in `add'
         4: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:177:in `find_formatter'
         3: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:224:in `custom_formatter'
         2: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:227:in `rescue in custom_formatter'
         1: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- dox/formatter (LoadError)
        21: from /usr/local/bundle/bin/rspec:23:in `<main>'
        20: from /usr/local/bundle/bin/rspec:23:in `load'
        19: from /usr/local/bundle/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
        18: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
        17: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
        16: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:86:in `run'
        15: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:99:in `setup'
        14: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:23:in `configure'
        13: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `load_formatters_into'
        12: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `each'
        11: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration_options.rb:117:in `block in load_formatters_into'
        10: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:878:in `add_formatter'
         9: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:146:in `add'
         8: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:177:in `find_formatter'
         7: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:224:in `custom_formatter'
         6: from /usr/local/bundle/gems/rspec-core-3.7.1/lib/rspec/core/formatters.rb:227:in `rescue in custom_formatter'
         5: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
         4: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
         3: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
         2: from /usr/local/bundle/gems/dox-1.1.0/lib/dox/formatter.rb:5:in `<top (required)>'
         1: from /usr/local/bundle/gems/dox-1.1.0/lib/dox/formatter.rb:6:in `<module:Dox>'
/usr/local/bundle/gems/dox-1.1.0/lib/dox/formatter.rb:7:in `<class:Formatter>': uninitialized constant Dox::Formatter::Forwardable (NameError)

I have this in rails_helper.rb:

RSpec.configure do |config|
  config.include FeatureMacros

  config.infer_spec_type_from_file_location!
  config.filter_rails_from_backtrace!

  config.after(:each, :dox) do |example|
    example.metadata[:request] = request
    example.metadata[:response] = response
  end
end

Dox.configure do |config|
  config.header_file_path = Rails.root.join('spec/docs/v2/descriptions/header.md')
  config.desc_folder_path = Rails.root.join('spec/docs/v2/descriptions')
  config.headers_whitelist = %w[Email Password Password-Confirmation
                                Ahoy-Visit Ahoy-Visitor Access-Token
                                Token-Type Client Expiry UID Profile-ID
                                Birth-date Reg-Number Document]
end

Editing the gem folder and adding require 'forwardable' in lib/dox/formatter.rb seems to solve the problem.

Content-Type header in request sample section is different than the actual request Content-Type header

The Content-Type header in request sample section does not match actual content type in the request:
image

The cause of this issue is in the

headers.find { |key, _| key == 'Accept' }&.last || 'any'

because it reads Accept header instead of Content-Type header.

When the line is changed to this:

headers.find { |key, _| key == 'Content-Type' }&.last || 'any'

then the out looks correct:
image

headers_whitelist does not seem to be working

Hello, I'm using rails 5.2.2 with dox 1.1.0, I'm using request specs to generate documentation.
The headers included in the documentation are only 'Accept' and 'Content-Type'.

I added this to an initializer.

Dox.configure do |config|
  config.headers_whitelist = ['access-token', 'token-type', 'client', 'expiry', 'uid']
end

But this is not working, when I try and debug it and check the contents of full_headers_whitelist only shows 'Accept' and 'Content-Type'.
Am I missing something here?

Thanks

Feature Request: Support Open API Extensions for branding purposes

Thanks for this great library! ๐Ÿ™

Open API Extensions are supported by some doc generators like Redoc and allow us to add branding, e.g. x-logo. It would be great if we can add this in the Dox configuration, perhaps namespaced under extensions or similar, for example:

Dox.configure do |config|
  # ...

  config.extensions['x-logo'] = {
    "url": "https://example.com/logo.png",
    "backgroundColor": "#ff3399"
  }

  # ...
end

I was able to add support for automated branding afterwards with the following script:

#!/usr/local/bin/ruby
require 'json'

docs = File.read('spec/api_doc/v1/schemas/docs.json')
docs_json = JSON.parse(docs)

docs_json['info']['x-logo'] = {
  "url": "https://example.com/logo.png",
  "backgroundColor": "#ff3399"
}

updated_docs = JSON.pretty_generate(docs_json)

File.write('spec/api_doc/v1/schemas/docs.json', updated_docs)

Script reference

Thanks again for all your great work on this library.

Support for capturing request body

Some of our POST endpoints have a JSON body and I would like to include that in our documentation.

It seems that for the request, just the header information is grabbed. Is there support for request bodies? Could it be added?

Using tags other than :dox

Hi folks,

This is a fantastic gem!

I have a question on tagging specs to be used in documentation generation. Currently, I have it working as you mention in the readme, tagging specs with :dox and then running the output through the Dox::Formatter.

I was wondering if we could use another tag? The reason for this is I would like to figure out how to seperate public API documentation from private, perhaps by tagging specs as public_dox and private_dox. I tried changing my tags in the specs to private_dox and then reconfiguring the rails_helper.rb configuration as below, but I cannot seem to get the documentation to generate.

  config.after(:each, :private_dox) do |example|
    example.metadata[:request] = request
    example.metadata[:response] = response
  end

Does this use of different tags sound possible? And if so, any idea on what I might be missing to get this different tag working?


Also, this is how I am running the specs to produce the documentation:

bundle exec rspec spec/controllers/api/auth_controller_spec.rb -f Dox::Formatter --order defined --tag private_dox --out docs.md

Undefined method resource_groups inside document block

When I try to use the resource_group method inside the document block I get a

NoMethodError: undefined method 'resource_group' for #<Dox::DSL::Documentation:0x007fafb218fe20>

e.g inside

document :api do
  resource 'Foo' do
    endpoint '/foo'
    group 'Foo'
  end

  resource_group 'bar' do
  end
end

OpenAPI bug - description in action block

There seems to be a bug on feature/openapi branch โ€” descriptions added to action block are never rendered.

Steps to reproduce:

  1. Add action block with desc
document :create do
  action 'Create smth' do
    desc 'hello'
  end
end
  1. Generate documentation

The action will be rendered in the generated documentation, but the description is missing. I've tried to pass both inline descriptions and markdown files, but none of them were rendered.

I think the bug is in lib/dox/printers/action_printer.rb file โ€” https://github.com/infinum/dox/pull/46/files#diff-87105a834429cb75e9b69541c6dc3d68. There used to be code there which handled rendering descriptions, but it was removed.

Is this project still active?

Curious if this is still an active project that just hasn't needed anything, or if it's gone dormant? Doing a survey of options to document my Rails API, and key is if the project is healthy or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.