Skip to content

Commit

Permalink
Adds API Blueprint
Browse files Browse the repository at this point in the history
This commit adds API Blueprint (APIB) to this gem. A few highlights:

* APIB groups entities, resources, routes, HTTP verbs and requests
  differently than what the gem currently uses. Because of that I had to
  override more methods than usual in the `Markup` classes.

  APIB has the following structure:
    1. resource (e.g "Group Orders")
    2. route (e.g "Orders Collection [/orders]")
    3. HTTP method (e.g "Loads all orders [GET]")
    4. Requests. Here, we show all different requests which means that
       we don't have the repetition of GET for each example. All
       examples stay under one, unified HTTP method header.
* APIB differentiates parameters (values used in the URLs) from
  attributes (values used in the actual request body). You can use
  `attributes` in your texts.
* APIB has a `route` header, which means we had to add a new RSpec block
  called `route()` which wraps HTTP methods, like the following:

  ```ruby
  route "/orders", "Orders Collection" do
    get "Returns all orders" do
      # ...
    end

    delete "Deletes all orders" do
      # ...
    end
  end
  ```

  If you don't use `route`, then param in `get(param)` should be an URL.

* APIB is not navigable like HTML, so generating an index file makes no
  sense. Because of that, we are generating just one file, `index.apib`.
* We are omitting some APIB features in this version so we can get up
  and running sooner. Examples are object grouping, arrays objects and a
  few description points.

Unrelated to APIB:

* FakeFS was being used _globally_ in test mode, which means that
  nothing would load file systems, not even a simple `~/.pry_history`, which
  made debugging impossible. I moved the usage of this gem to the places
  where it is used.

Closes #235.
  • Loading branch information
kurko committed Nov 16, 2016
1 parent 470da85 commit 33a6dcb
Show file tree
Hide file tree
Showing 20 changed files with 1,027 additions and 52 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ RspecApiDocumentation.configure do |config|

# An array of output format(s).
# Possible values are :json, :html, :combined_text, :combined_json,
# :json_iodocs, :textile, :markdown, :append_json, :slate
# :json_iodocs, :textile, :markdown, :append_json, :slate,
# :api_blueprint
config.format = [:html]

# Location of templates
Expand Down Expand Up @@ -170,6 +171,7 @@ end
* **json_iodocs**: Generates [I/O Docs](http://www.mashery.com/product/io-docs) style documentation.
* **textile**: Generates an index file and example files in Textile.
* **markdown**: Generates an index file and example files in Markdown.
* **api_blueprint**: Generates an index file and example files in [APIBlueprint](https://apiblueprint.org).
* **append_json**: Lets you selectively run specs without destroying current documentation. See section below.

### append_json
Expand Down Expand Up @@ -204,7 +206,32 @@ rake docs:generate:append[spec/acceptance/orders_spec.rb]

This will update the current index's examples to include any in the `orders_spec.rb` file. Any examples inside will be rewritten.

### api_blueprint

This [format](https://apiblueprint.org) (APIB) has additional functions:

* `route`: APIB groups URLs together and then below them are HTTP verbs.

```ruby
route "/orders", "Orders Collection" do
get "Returns all orders" do
# ...
end

delete "Deletes all orders" do
# ...
end
end
```

If you don't use `route`, then param in `get(param)` should be an URL as
states in the rest of this documentation.

* `attribute`: APIB has attributes besides parameters. Use attributes exactly
like you'd use `parameter` (see documentation below).

## Filtering and Exclusion

rspec_api_documentation lets you determine which examples get outputted into the final documentation.
All filtering is done via the `:document` metadata key.
You tag examples with either a single symbol or an array of symbols.
Expand Down
Loading

0 comments on commit 33a6dcb

Please sign in to comment.