grape-swagger 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +48 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +118 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +58 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/grape-swagger.gemspec +104 -0
- data/lib/grape-swagger.rb +124 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/grape-swagger_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +223 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p125@grape-swagger"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.14.3 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'grape'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "shoulda", ">= 0"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.8.4"
|
15
|
+
# jquery-rails is used by the dummy application
|
16
|
+
gem "jquery-rails"
|
17
|
+
gem "rails", "~> 3.2"
|
18
|
+
gem "sqlite3"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.6)
|
5
|
+
actionpack (= 3.2.6)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.6)
|
8
|
+
activemodel (= 3.2.6)
|
9
|
+
activesupport (= 3.2.6)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.1)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.6)
|
18
|
+
activesupport (= 3.2.6)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.6)
|
21
|
+
activemodel (= 3.2.6)
|
22
|
+
activesupport (= 3.2.6)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.6)
|
26
|
+
activemodel (= 3.2.6)
|
27
|
+
activesupport (= 3.2.6)
|
28
|
+
activesupport (3.2.6)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
33
|
+
erubis (2.7.0)
|
34
|
+
git (1.2.5)
|
35
|
+
grape (0.2.1)
|
36
|
+
hashie (~> 1.2)
|
37
|
+
multi_json
|
38
|
+
multi_xml
|
39
|
+
rack
|
40
|
+
rack-mount
|
41
|
+
hashie (1.2.0)
|
42
|
+
hike (1.2.1)
|
43
|
+
i18n (0.6.0)
|
44
|
+
jeweler (1.8.4)
|
45
|
+
bundler (~> 1.0)
|
46
|
+
git (>= 1.2.5)
|
47
|
+
rake
|
48
|
+
rdoc
|
49
|
+
journey (1.0.4)
|
50
|
+
jquery-rails (2.0.2)
|
51
|
+
railties (>= 3.2.0, < 5.0)
|
52
|
+
thor (~> 0.14)
|
53
|
+
json (1.7.3)
|
54
|
+
mail (2.4.4)
|
55
|
+
i18n (>= 0.4.0)
|
56
|
+
mime-types (~> 1.16)
|
57
|
+
treetop (~> 1.4.8)
|
58
|
+
mime-types (1.19)
|
59
|
+
multi_json (1.3.6)
|
60
|
+
multi_xml (0.5.1)
|
61
|
+
polyglot (0.3.3)
|
62
|
+
rack (1.4.1)
|
63
|
+
rack-cache (1.2)
|
64
|
+
rack (>= 0.4)
|
65
|
+
rack-mount (0.8.3)
|
66
|
+
rack (>= 1.0.0)
|
67
|
+
rack-ssl (1.3.2)
|
68
|
+
rack
|
69
|
+
rack-test (0.6.1)
|
70
|
+
rack (>= 1.0)
|
71
|
+
rails (3.2.6)
|
72
|
+
actionmailer (= 3.2.6)
|
73
|
+
actionpack (= 3.2.6)
|
74
|
+
activerecord (= 3.2.6)
|
75
|
+
activeresource (= 3.2.6)
|
76
|
+
activesupport (= 3.2.6)
|
77
|
+
bundler (~> 1.0)
|
78
|
+
railties (= 3.2.6)
|
79
|
+
railties (3.2.6)
|
80
|
+
actionpack (= 3.2.6)
|
81
|
+
activesupport (= 3.2.6)
|
82
|
+
rack-ssl (~> 1.3.2)
|
83
|
+
rake (>= 0.8.7)
|
84
|
+
rdoc (~> 3.4)
|
85
|
+
thor (>= 0.14.6, < 2.0)
|
86
|
+
rake (0.9.2.2)
|
87
|
+
rdoc (3.12)
|
88
|
+
json (~> 1.4)
|
89
|
+
shoulda (3.1.1)
|
90
|
+
shoulda-context (~> 1.0)
|
91
|
+
shoulda-matchers (~> 1.2)
|
92
|
+
shoulda-context (1.0.0)
|
93
|
+
shoulda-matchers (1.2.0)
|
94
|
+
activesupport (>= 3.0.0)
|
95
|
+
sprockets (2.1.3)
|
96
|
+
hike (~> 1.2)
|
97
|
+
rack (~> 1.0)
|
98
|
+
tilt (~> 1.1, != 1.3.0)
|
99
|
+
sqlite3 (1.3.6)
|
100
|
+
thor (0.15.4)
|
101
|
+
tilt (1.3.3)
|
102
|
+
treetop (1.4.10)
|
103
|
+
polyglot
|
104
|
+
polyglot (>= 0.3.1)
|
105
|
+
tzinfo (0.3.33)
|
106
|
+
|
107
|
+
PLATFORMS
|
108
|
+
ruby
|
109
|
+
|
110
|
+
DEPENDENCIES
|
111
|
+
bundler (> 1.0.0)
|
112
|
+
grape
|
113
|
+
jeweler (~> 1.8.4)
|
114
|
+
jquery-rails
|
115
|
+
rails (~> 3.2)
|
116
|
+
rdoc (~> 3.12)
|
117
|
+
shoulda
|
118
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Tim Vandecasteele
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# grape-swagger
|
2
|
+
|
3
|
+
## What is grape-swagger?
|
4
|
+
grape-swagger provides an autogenerated documentation for your [grape](https://github.com/intridea/grape)-API. The generated documentation is Swagger-compliant, meaning it can easily be discovered in [Swagger UI](https://github.com/wordnik/swagger-ui)
|
5
|
+
|
6
|
+
## Related projects
|
7
|
+
* [Grape](https://github.com/intridea/grape)
|
8
|
+
* [Swagger UI](https://github.com/wordnik/swagger-ui)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
grape-swagger is available as a gem, install it simply via the commandline:
|
12
|
+
|
13
|
+
```gem install grape-swagger```
|
14
|
+
|
15
|
+
or add to your Gemfile:
|
16
|
+
|
17
|
+
```gem 'grape-swagger'```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
Once you have the gem installed, mount all your different APIs (with ```Grape::API``` superclass) on a root node. In the root class definition, also include ```add_swagger_documentation```, this sets up the system and registers the documentation on '/swagger_doc.json'. Setup done, you can restart your local server now.
|
21
|
+
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'grape-swagger'
|
25
|
+
|
26
|
+
module API
|
27
|
+
class Root < Grape::API
|
28
|
+
mount API::Cats
|
29
|
+
mount API::Dogs
|
30
|
+
mount API::Pirates
|
31
|
+
add_swagger_documentation
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
To explore your API, either download [Swagger UI](https://github.com/wordnik/swagger-ui) and set it up yourself or go to the [online swagger demo](http://petstore.swagger.wordnik.com/) and enter your localhost url documentation root in the url field (probably something in the line of http://localhost:3000/swagger_doc.json)
|
37
|
+
|
38
|
+
## Configure
|
39
|
+
You can pass a hash with some configuration possibilities to ```add_swagger_documentation```, all of these are optional:
|
40
|
+
* ```:mount_path``` The path were the API documentation is loaded, default '/swagger_doc'
|
41
|
+
* ```:api_version``` Version of the API that's being exposed
|
42
|
+
* ```:base_path``` Basepath of the API that's being exposed
|
43
|
+
|
44
|
+
## Contributing to grape-swagger
|
45
|
+
|
46
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
47
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
48
|
+
* Fork the project.
|
49
|
+
* Start a feature/bugfix branch.
|
50
|
+
* Commit and push until you are happy with your contribution.
|
51
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
52
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
53
|
+
|
54
|
+
## Copyright
|
55
|
+
|
56
|
+
Copyright (c) 2012 Tim Vandecasteele. See LICENSE.txt for
|
57
|
+
further details.
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "grape-swagger"
|
18
|
+
gem.homepage = "http://github.com/tim-vandecasteele/grape-swagger"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Add swagger compliant documentation to your grape API}
|
21
|
+
gem.description = %Q{A simple way to add proper auto generated documentation - that can be displayed with swagger - to your inline described grape API}
|
22
|
+
gem.email = "tim.vandecasteele@gmail.com"
|
23
|
+
gem.authors = ["Tim Vandecasteele"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
Bundler::GemHelper.install_tasks
|
31
|
+
|
32
|
+
require 'rake/testtask'
|
33
|
+
|
34
|
+
Rake::TestTask.new(:test) do |t|
|
35
|
+
t.libs << 'lib'
|
36
|
+
t.libs << 'test'
|
37
|
+
t.pattern = 'test/**/*_test.rb'
|
38
|
+
t.verbose = false
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "grape-swagger"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tim Vandecasteele"]
|
12
|
+
s.date = "2012-07-19"
|
13
|
+
s.description = "A simple way to add proper auto generated documentation - that can be displayed with swagger - to your inline described grape API"
|
14
|
+
s.email = "tim.vandecasteele@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.markdown",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"grape-swagger.gemspec",
|
29
|
+
"lib/grape-swagger.rb",
|
30
|
+
"test/dummy/README.rdoc",
|
31
|
+
"test/dummy/Rakefile",
|
32
|
+
"test/dummy/app/assets/javascripts/application.js",
|
33
|
+
"test/dummy/app/assets/stylesheets/application.css",
|
34
|
+
"test/dummy/app/controllers/application_controller.rb",
|
35
|
+
"test/dummy/app/helpers/application_helper.rb",
|
36
|
+
"test/dummy/app/mailers/.gitkeep",
|
37
|
+
"test/dummy/app/models/.gitkeep",
|
38
|
+
"test/dummy/app/views/layouts/application.html.erb",
|
39
|
+
"test/dummy/config.ru",
|
40
|
+
"test/dummy/config/application.rb",
|
41
|
+
"test/dummy/config/boot.rb",
|
42
|
+
"test/dummy/config/database.yml",
|
43
|
+
"test/dummy/config/environment.rb",
|
44
|
+
"test/dummy/config/environments/development.rb",
|
45
|
+
"test/dummy/config/environments/production.rb",
|
46
|
+
"test/dummy/config/environments/test.rb",
|
47
|
+
"test/dummy/config/initializers/backtrace_silencers.rb",
|
48
|
+
"test/dummy/config/initializers/inflections.rb",
|
49
|
+
"test/dummy/config/initializers/mime_types.rb",
|
50
|
+
"test/dummy/config/initializers/secret_token.rb",
|
51
|
+
"test/dummy/config/initializers/session_store.rb",
|
52
|
+
"test/dummy/config/initializers/wrap_parameters.rb",
|
53
|
+
"test/dummy/config/locales/en.yml",
|
54
|
+
"test/dummy/config/routes.rb",
|
55
|
+
"test/dummy/lib/assets/.gitkeep",
|
56
|
+
"test/dummy/log/.gitkeep",
|
57
|
+
"test/dummy/public/404.html",
|
58
|
+
"test/dummy/public/422.html",
|
59
|
+
"test/dummy/public/500.html",
|
60
|
+
"test/dummy/public/favicon.ico",
|
61
|
+
"test/dummy/script/rails",
|
62
|
+
"test/grape-swagger_test.rb",
|
63
|
+
"test/test_helper.rb"
|
64
|
+
]
|
65
|
+
s.homepage = "http://github.com/tim-vandecasteele/grape-swagger"
|
66
|
+
s.licenses = ["MIT"]
|
67
|
+
s.require_paths = ["lib"]
|
68
|
+
s.rubygems_version = "1.8.24"
|
69
|
+
s.summary = "Add swagger compliant documentation to your grape API"
|
70
|
+
|
71
|
+
if s.respond_to? :specification_version then
|
72
|
+
s.specification_version = 3
|
73
|
+
|
74
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
75
|
+
s.add_runtime_dependency(%q<grape>, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
79
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
80
|
+
s.add_development_dependency(%q<jquery-rails>, [">= 0"])
|
81
|
+
s.add_development_dependency(%q<rails>, ["~> 3.2"])
|
82
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
83
|
+
else
|
84
|
+
s.add_dependency(%q<grape>, [">= 0"])
|
85
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
87
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
89
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
90
|
+
s.add_dependency(%q<rails>, ["~> 3.2"])
|
91
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
92
|
+
end
|
93
|
+
else
|
94
|
+
s.add_dependency(%q<grape>, [">= 0"])
|
95
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
96
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
97
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
98
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
99
|
+
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
100
|
+
s.add_dependency(%q<rails>, ["~> 3.2"])
|
101
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Grape
|
2
|
+
class API
|
3
|
+
class << self
|
4
|
+
attr_reader :combined_routes
|
5
|
+
|
6
|
+
alias original_mount mount
|
7
|
+
|
8
|
+
def mount(mounts)
|
9
|
+
original_mount mounts
|
10
|
+
@combined_routes ||= {}
|
11
|
+
@combined_routes[mounts.name.split('::').last.downcase] = mounts::routes
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_swagger_documentation(options={})
|
15
|
+
documentation_class = create_documentation_class
|
16
|
+
|
17
|
+
documentation_class.setup({:target_class => self}.merge(options))
|
18
|
+
mount(documentation_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def create_documentation_class
|
24
|
+
Class.new(Grape::API) do
|
25
|
+
class << self
|
26
|
+
def name
|
27
|
+
@@class_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.setup(options)
|
32
|
+
defaults = {
|
33
|
+
:target_class => nil,
|
34
|
+
:mount_path => '/swagger_doc',
|
35
|
+
:base_path => nil,
|
36
|
+
:api_version => '0.1',
|
37
|
+
}
|
38
|
+
options = defaults.merge(options)
|
39
|
+
|
40
|
+
@@target_class = options[:target_class]
|
41
|
+
@@mount_path = options[:mount_path]
|
42
|
+
@@class_name = options[:class_name] || options[:mount_path].gsub('/','')
|
43
|
+
@@api_version = options[:api_version]
|
44
|
+
@@base_path = options[:base_path]
|
45
|
+
|
46
|
+
desc 'Swagger compatible API description'
|
47
|
+
get @@mount_path do
|
48
|
+
header['Access-Control-Allow-Origin'] = '*'
|
49
|
+
header['Access-Control-Request-Method'] = '*'
|
50
|
+
routes = @@target_class::combined_routes
|
51
|
+
|
52
|
+
routes_array = routes.keys.map do |route|
|
53
|
+
{ :path => "#{@@mount_path}/#{route}.{format}" }
|
54
|
+
end
|
55
|
+
{
|
56
|
+
apiVersion: @@api_version,
|
57
|
+
swaggerVersion: "1.1",
|
58
|
+
basePath: @@base_path || "http://#{env['HTTP_HOST']}",
|
59
|
+
operations:[],
|
60
|
+
apis: routes_array
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Swagger compatible API description for specific API', :params =>
|
65
|
+
{
|
66
|
+
"name" => { :desc => "Class name of mounted API", :type => "string", :required => true },
|
67
|
+
}
|
68
|
+
get "#{@@mount_path}/:name" do
|
69
|
+
header['Access-Control-Allow-Origin'] = '*'
|
70
|
+
header['Access-Control-Request-Method'] = '*'
|
71
|
+
routes = @@target_class::combined_routes[params[:name]]
|
72
|
+
routes_array = routes.map do |route|
|
73
|
+
{
|
74
|
+
:path => parse_path(route.route_path),
|
75
|
+
:operations => [{
|
76
|
+
:notes => route.route_notes,
|
77
|
+
:summary => route.route_description || '',
|
78
|
+
:nickname => Random.rand(1000000),
|
79
|
+
:httpMethod => route.route_method,
|
80
|
+
:parameters => parse_params(route.route_params)
|
81
|
+
}]
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
{
|
86
|
+
apiVersion: @@api_version,
|
87
|
+
swaggerVersion: "1.1",
|
88
|
+
basePath: @@base_path || "http://#{env['HTTP_HOST']}",
|
89
|
+
resourcePath: "",
|
90
|
+
apis: routes_array
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
helpers do
|
97
|
+
def parse_params(params)
|
98
|
+
params.map do |param, value|
|
99
|
+
dataType = value.is_a?(Hash) ? value[:type]||'String' : 'String'
|
100
|
+
description = value.is_a?(Hash) ? value[:desc] : ''
|
101
|
+
required = value.is_a?(Hash) ? !!value[:required] : false
|
102
|
+
paramType = 'path'
|
103
|
+
{
|
104
|
+
paramType: paramType,
|
105
|
+
name: param,
|
106
|
+
description: description,
|
107
|
+
dataType: "String",
|
108
|
+
required: required
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def parse_path(path)
|
114
|
+
# adapt format to swagger format
|
115
|
+
parsed_path = path.gsub('(.:format)', '.{format}')
|
116
|
+
# adapt params to swagger format
|
117
|
+
parsed_path.gsub(/:([a-z]+)/, '{\1}')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|