Skip to content

Commit

Permalink
Merge pull request #356 from prikha/master
Browse files Browse the repository at this point in the history
Add common api description before resources sections (closes #354)
  • Loading branch information
oestrich authored Aug 23, 2017
2 parents 3ad1ab7 + ed281e8 commit 9201f69
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ RspecApiDocumentation.configure do |config|

# Change the name of the API on index pages
config.api_name = "API Documentation"

# Change the description of the API on index pages
config.api_explanation = "API Description"

# Redefine what method the DSL thinks is the client
# This is useful if you need to `let` your own client, most likely a model.
Expand Down
1 change: 1 addition & 0 deletions example/spec/acceptance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
config.format = [:json, :combined_text, :html]
config.curl_host = 'http://localhost:3000'
config.api_name = "Example App API"
config.api_explanation = "API Example Description"
end
1 change: 1 addition & 0 deletions features/api_blueprint_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Feature: Generate API Blueprint documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "Example API Description"
config.format = :api_blueprint
config.request_body_formatter = :json
config.request_headers_to_include = %w[Content-Type Host]
Expand Down
7 changes: 7 additions & 0 deletions features/html_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: Generate HTML documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "<p>Example API Description</p>"
config.request_headers_to_include = %w[Cookie]
config.response_headers_to_include = %w[Content-Type]
end
Expand Down Expand Up @@ -66,6 +67,12 @@ Feature: Generate HTML documentation from test examples
| Greetings |
And I should see the api name "Example API"

Scenario: Create an index with proper description
When I open the index
Then I should see the following resources:
| Greetings |
And I should see the api explanation "Example API Description"

Scenario: Example HTML documentation includes the parameters
When I open the index
And I navigate to "Greeting your favorite gem"
Expand Down
2 changes: 2 additions & 0 deletions features/json_iodocs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: Json Iodocs
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "app"
config.api_explanation = "desc"
config.format = :json_iodocs
config.io_docs_protocol = "https"
end
Expand Down Expand Up @@ -70,6 +71,7 @@ Feature: Json Iodocs
{
"app" : {
"name" : "app",
"description": "desc",
"protocol" : "https",
"publicPath" : "",
"baseURL" : null
Expand Down
2 changes: 2 additions & 0 deletions features/markdown_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Feature: Generate Markdown documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "Example API Description"
config.format = :markdown
config.request_headers_to_include = %w[Content-Type Host]
config.response_headers_to_include = %w[Content-Type Content-Length]
Expand Down Expand Up @@ -148,6 +149,7 @@ Feature: Generate Markdown documentation from test examples
Then the file "doc/api/index.markdown" should contain exactly:
"""
# Example API
Example API Description
## Help
Expand Down
1 change: 1 addition & 0 deletions features/slate_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Feature: Generate Slate documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "Description"
config.format = :slate
config.curl_host = 'http://localhost:3000'
config.request_headers_to_include = %w[Content-Type Host]
Expand Down
2 changes: 2 additions & 0 deletions features/textile_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Feature: Generate Textile documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "Example API Description"
config.format = :textile
config.request_headers_to_include = %w[Content-Type Host]
config.response_headers_to_include = %w[Content-Type Content-Length]
Expand Down Expand Up @@ -148,6 +149,7 @@ Feature: Generate Textile documentation from test examples
Then the file "doc/api/index.textile" should contain exactly:
"""
h1. Example API
Example API Description
h2. Help
Expand Down
1 change: 1 addition & 0 deletions lib/rspec_api_documentation/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def self.add_setting(name, opts = {})
add_setting :curl_host, :default => nil
add_setting :keep_source_order, :default => false
add_setting :api_name, :default => "API Documentation"
add_setting :api_explanation, :default => nil
add_setting :io_docs_protocol, :default => "http"
add_setting :request_headers_to_include, :default => nil
add_setting :response_headers_to_include, :default => nil
Expand Down
6 changes: 2 additions & 4 deletions lib/rspec_api_documentation/views/markup_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
module RspecApiDocumentation
module Views
class MarkupIndex < Mustache
delegate :api_name, :api_explanation, to: :@configuration, prefix: false

def initialize(index, configuration)
@index = index
@configuration = configuration
self.template_path = configuration.template_path
end

def api_name
@configuration.api_name
end

def sections
RspecApiDocumentation::Writers::IndexHelper.sections(examples, @configuration)
end
Expand Down
1 change: 1 addition & 0 deletions lib/rspec_api_documentation/writers/json_iodocs_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def as_json(opts = nil)
{
@api_key.to_sym => {
:name => @configuration.api_name,
:description => @configuration.api_explanation,
:protocol => @configuration.io_docs_protocol,
:publicPath => "",
:baseURL => @configuration.curl_host
Expand Down
1 change: 1 addition & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
its(:curl_host) { should be_nil }
its(:keep_source_order) { should be_falsey }
its(:api_name) { should == "API Documentation" }
its(:api_explanation) { should be_nil }
its(:client_method) { should == :client }
its(:io_docs_protocol) { should == "http" }
its(:request_headers_to_include) { should be_nil }
Expand Down
2 changes: 1 addition & 1 deletion templates/rspec_api_documentation/html_index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<body>
<div class="container">
<h1>{{ api_name }}</h1>

{{{ api_explanation }}}
{{# sections }}
<div class="article">
<h2>{{ resource_name }}</h2>
Expand Down
1 change: 1 addition & 0 deletions templates/rspec_api_documentation/markdown_index.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# {{ api_name }}
{{{ api_explanation }}}

{{# sections }}
## {{ resource_name }}
Expand Down
1 change: 1 addition & 0 deletions templates/rspec_api_documentation/textile_index.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
h1. {{ api_name }}
{{{ api_explanation }}}

{{# sections }}
h2. {{ resource_name }}
Expand Down

0 comments on commit 9201f69

Please sign in to comment.