apipie-rails 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +3 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/APACHE-LICENSE-2.0 +202 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +115 -0
- data/MIT-LICENSE +20 -0
- data/NOTICE +4 -0
- data/README.rdoc +365 -0
- data/Rakefile +13 -0
- data/apipie-rails.gemspec +27 -0
- data/app/controllers/apipie/apipies_controller.rb +60 -0
- data/app/public/apipie/javascripts/apipie.js +6 -0
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +138 -0
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1726 -0
- data/app/public/apipie/javascripts/bundled/jquery-1.7.2.js +9404 -0
- data/app/public/apipie/javascripts/bundled/prettify.js +28 -0
- data/app/public/apipie/stylesheets/application.css +7 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +12 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +689 -0
- data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie/apipies/_params.html.erb +22 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +16 -0
- data/app/views/apipie/apipies/index.html.erb +36 -0
- data/app/views/apipie/apipies/method.html.erb +63 -0
- data/app/views/apipie/apipies/plain.html.erb +70 -0
- data/app/views/apipie/apipies/resource.html.erb +82 -0
- data/app/views/apipie/apipies/static.html.erb +101 -0
- data/app/views/layouts/apipie/apipie.html.erb +37 -0
- data/lib/apipie-rails.rb +12 -0
- data/lib/apipie/apipie_module.rb +105 -0
- data/lib/apipie/application.rb +225 -0
- data/lib/apipie/client/generator.rb +105 -0
- data/lib/apipie/client/template/Gemfile.tt +5 -0
- data/lib/apipie/client/template/README.tt +3 -0
- data/lib/apipie/client/template/base.rb.tt +33 -0
- data/lib/apipie/client/template/bin.rb.tt +110 -0
- data/lib/apipie/client/template/cli.rb.tt +25 -0
- data/lib/apipie/client/template/cli_command.rb.tt +129 -0
- data/lib/apipie/client/template/client.rb.tt +10 -0
- data/lib/apipie/client/template/resource.rb.tt +17 -0
- data/lib/apipie/dsl_definition.rb +139 -0
- data/lib/apipie/error_description.rb +21 -0
- data/lib/apipie/extractor.rb +143 -0
- data/lib/apipie/extractor/collector.rb +113 -0
- data/lib/apipie/extractor/recorder.rb +122 -0
- data/lib/apipie/extractor/writer.rb +356 -0
- data/lib/apipie/helpers.rb +24 -0
- data/lib/apipie/markup.rb +45 -0
- data/lib/apipie/method_description.rb +150 -0
- data/lib/apipie/param_description.rb +87 -0
- data/lib/apipie/railtie.rb +9 -0
- data/lib/apipie/resource_description.rb +83 -0
- data/lib/apipie/routing.rb +13 -0
- data/lib/apipie/static_dispatcher.rb +60 -0
- data/lib/apipie/validator.rb +292 -0
- data/lib/apipie/version.rb +3 -0
- data/lib/tasks/apipie.rake +156 -0
- data/rel-eng/packages/.readme +3 -0
- data/rel-eng/tito.props +5 -0
- data/rubygem-apipie-rails.spec +72 -0
- data/spec/controllers/apipies_controller_spec.rb +132 -0
- data/spec/controllers/users_controller_spec.rb +390 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +6 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +302 -0
- data/spec/dummy/app/controllers/users_controller.rb +223 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +25 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/apipie.rb +64 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +21 -0
- data/spec/dummy/doc/apipie_examples.yml +28 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +202 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/spec_helper.rb +32 -0
- metadata +312 -0
data/.autotest
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7@apipie
|
data/.travis.yml
ADDED
data/APACHE-LICENSE-2.0
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
apipie-rails (0.0.6)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
RedCloth (4.2.9)
|
10
|
+
actionmailer (3.2.6)
|
11
|
+
actionpack (= 3.2.6)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.6)
|
14
|
+
activemodel (= 3.2.6)
|
15
|
+
activesupport (= 3.2.6)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.1)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.1.3)
|
23
|
+
activemodel (3.2.6)
|
24
|
+
activesupport (= 3.2.6)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.6)
|
27
|
+
activemodel (= 3.2.6)
|
28
|
+
activesupport (= 3.2.6)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.6)
|
32
|
+
activemodel (= 3.2.6)
|
33
|
+
activesupport (= 3.2.6)
|
34
|
+
activesupport (3.2.6)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.0)
|
39
|
+
diff-lcs (1.1.3)
|
40
|
+
erubis (2.7.0)
|
41
|
+
hike (1.2.1)
|
42
|
+
i18n (0.6.0)
|
43
|
+
journey (1.0.4)
|
44
|
+
json (1.7.3)
|
45
|
+
mail (2.4.4)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.19)
|
50
|
+
minitest (3.2.0)
|
51
|
+
multi_json (1.3.6)
|
52
|
+
polyglot (0.3.3)
|
53
|
+
rack (1.4.1)
|
54
|
+
rack-cache (1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-ssl (1.3.2)
|
57
|
+
rack
|
58
|
+
rack-test (0.6.1)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.2.6)
|
61
|
+
actionmailer (= 3.2.6)
|
62
|
+
actionpack (= 3.2.6)
|
63
|
+
activerecord (= 3.2.6)
|
64
|
+
activeresource (= 3.2.6)
|
65
|
+
activesupport (= 3.2.6)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.2.6)
|
68
|
+
railties (3.2.6)
|
69
|
+
actionpack (= 3.2.6)
|
70
|
+
activesupport (= 3.2.6)
|
71
|
+
rack-ssl (~> 1.3.2)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (>= 0.14.6, < 2.0)
|
75
|
+
rake (0.9.2.2)
|
76
|
+
rdoc (3.12)
|
77
|
+
json (~> 1.4)
|
78
|
+
redcarpet (2.1.1)
|
79
|
+
rspec (2.11.0)
|
80
|
+
rspec-core (~> 2.11.0)
|
81
|
+
rspec-expectations (~> 2.11.0)
|
82
|
+
rspec-mocks (~> 2.11.0)
|
83
|
+
rspec-core (2.11.1)
|
84
|
+
rspec-expectations (2.11.1)
|
85
|
+
diff-lcs (~> 1.1.3)
|
86
|
+
rspec-mocks (2.11.1)
|
87
|
+
rspec-rails (2.11.0)
|
88
|
+
actionpack (>= 3.0)
|
89
|
+
activesupport (>= 3.0)
|
90
|
+
railties (>= 3.0)
|
91
|
+
rspec (~> 2.11.0)
|
92
|
+
sprockets (2.1.3)
|
93
|
+
hike (~> 1.2)
|
94
|
+
rack (~> 1.0)
|
95
|
+
tilt (~> 1.1, != 1.3.0)
|
96
|
+
sqlite3 (1.3.6)
|
97
|
+
thor (0.15.4)
|
98
|
+
tilt (1.3.3)
|
99
|
+
treetop (1.4.10)
|
100
|
+
polyglot
|
101
|
+
polyglot (>= 0.3.1)
|
102
|
+
tzinfo (0.3.33)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
ruby
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
RedCloth
|
109
|
+
apipie-rails!
|
110
|
+
minitest
|
111
|
+
rails (>= 3.0.10)
|
112
|
+
rake
|
113
|
+
redcarpet
|
114
|
+
rspec-rails
|
115
|
+
sqlite3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Pavel Pokorný
|
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/NOTICE
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
= API Documentation Tool {<img src="https://secure.travis-ci.org/Pajk/apipie-rails.png?branch=master" alt="Build Status" />}[http://travis-ci.org/Pajk/apipie-rails]
|
2
|
+
|
3
|
+
== What?
|
4
|
+
|
5
|
+
Every API needs a documentation otherwise no one know how to use it.
|
6
|
+
It is not easy to maintain such documentation always up to date if it
|
7
|
+
develops over time. Additionaly to this most programmers don't like writing
|
8
|
+
documentation and so it could happen that your API is useless because
|
9
|
+
of outdated documentation. If the documentation is just text completely
|
10
|
+
separated from code then there is no simple way to verify its correctness.
|
11
|
+
|
12
|
+
This gem adds some new methods to Rails controllers that can be used
|
13
|
+
to describe resources which are exposed by our API. It is meant to
|
14
|
+
be used for {RESTful}[http://cs.wikipedia.org/wiki/Representational_State_Transfer]
|
15
|
+
web services and because we are talking about Rails you probably know
|
16
|
+
what it is all about.
|
17
|
+
|
18
|
+
Informations you entered with provided DSL are used to generate
|
19
|
+
online documentation and validate values of incoming requests parameters.
|
20
|
+
|
21
|
+
== Why?
|
22
|
+
|
23
|
+
Documentation will be closer to your code and thus less prone to become
|
24
|
+
obsolete. You get documentation frontend without effort. And if you want your
|
25
|
+
own design you can do it anytime because json API for your API documentation
|
26
|
+
is provided. There are no limits on how to use those informations, the
|
27
|
+
builtin web interface is only one of possible options.
|
28
|
+
|
29
|
+
Request parameters will be validated before they will get in touch with yours
|
30
|
+
controller action or model code. And you inform API users about expected
|
31
|
+
parameters values. This information will be always actual because otherwise
|
32
|
+
your tests fail (of course you have tests!).
|
33
|
+
|
34
|
+
This is how the web interface look like. Try it live on
|
35
|
+
http://restapi-likes.rhcloud.com. Example users resource
|
36
|
+
description are taken from Twitter(c) API.
|
37
|
+
|
38
|
+
https://img.skitch.com/20120428-nruk3e87xs2cu4ydsjujdh11fq.png
|
39
|
+
|
40
|
+
https://img.skitch.com/20120428-bni2cmq5cyhjuw1jkd78e3qjxn.png
|
41
|
+
|
42
|
+
== How?
|
43
|
+
|
44
|
+
=== Gemfile
|
45
|
+
|
46
|
+
Add +apipie+ gem to your gemfile and run bundle.
|
47
|
+
|
48
|
+
gem 'apipie-rails'
|
49
|
+
|
50
|
+
For bleeding edge version use GitHub version
|
51
|
+
|
52
|
+
gem 'apipie-rails', :git => 'git://github.com/Pajk/apipie-rails.git'
|
53
|
+
|
54
|
+
=== Config file
|
55
|
+
|
56
|
+
Create configuration file in e.g. */config/initializers/apipie.rb*.
|
57
|
+
You can set application name, footer text, API and documentation base URL
|
58
|
+
and turn off validations. You can also choose your favorite markup language
|
59
|
+
of full descriptions.
|
60
|
+
|
61
|
+
[app_name] Name of your application used in breadcrumbs navigation.
|
62
|
+
[copyright] Copyright information (shown in page footer).
|
63
|
+
[doc_base_url] Documentation frontend base url.
|
64
|
+
[api_base_url] Base url of your API, most probably /api.
|
65
|
+
[validate] Parameters validation is turned off when set to false.
|
66
|
+
[app_info] Application long description.
|
67
|
+
[reload_controllers] Set to enable/disable reloading controllers (and the documentation with it), by default enabled in development.
|
68
|
+
[api_controllers_matcher] For reloading to work properly you need to specify where your API controllers are.
|
69
|
+
[markup] You can choose markup language for descriptions of your application,
|
70
|
+
resources and methods. RDoc is the default but you can choose from
|
71
|
+
Apipie::Markup::Markdown.new or Apipie::Markup::Textile.new.
|
72
|
+
In order to use Markdown you need Redcarpet gem and for Textile you
|
73
|
+
need RedCloth. Add those to your gemfile and run bundle if you
|
74
|
+
want to use them. You can also add any other markup language
|
75
|
+
processor.
|
76
|
+
|
77
|
+
Example:
|
78
|
+
|
79
|
+
Apipie.configure do |config|
|
80
|
+
config.app_name = "Test app"
|
81
|
+
config.copyright = "© 2012 Pavel Pokorny"
|
82
|
+
config.doc_base_url = "/apidoc"
|
83
|
+
config.api_base_url = "/api"
|
84
|
+
config.validate = false
|
85
|
+
config.markup = Apipie::Markup::Markdown.new
|
86
|
+
config.reload_controllers = true
|
87
|
+
config.api_controllers_matcher = File.join(Rails.root, "app", "controllers", "**","*.rb")
|
88
|
+
config.app_info = <<-DOC
|
89
|
+
This is where you can inform user about your application and API
|
90
|
+
in general.
|
91
|
+
DOC
|
92
|
+
end
|
93
|
+
|
94
|
+
=== Routes
|
95
|
+
|
96
|
+
Add +apipie+ to your *routes.rb*, that's all.
|
97
|
+
|
98
|
+
|
99
|
+
=== Resource Description
|
100
|
+
|
101
|
+
Resource can be described in corresponding controller by calling +resource_description+ method with block. Parameters described here are used
|
102
|
+
for every method unless they are overridden with NilValidator.
|
103
|
+
Parameters are inherited in controller hierarchy. So for example you can define
|
104
|
+
in base ApplicationController parameters for authentication and they will
|
105
|
+
be checked in every request.
|
106
|
+
|
107
|
+
[name] You can force resource to display under some alias.
|
108
|
+
[short] One line short description.
|
109
|
+
[path] Relative URL path of this resource.
|
110
|
+
[version] Version of this resource API, use arbitrary string.
|
111
|
+
[param] The very same parameter description as you will use method
|
112
|
+
description. Generally use this for parameters that apply
|
113
|
+
to every method in the controller (such as :user hash).
|
114
|
+
It is possible to hide it for individual methods by setting
|
115
|
+
it's validator to nil.
|
116
|
+
[description] The full multiline description of the resource and
|
117
|
+
yours API options
|
118
|
+
|
119
|
+
Example:
|
120
|
+
|
121
|
+
class UsersController < ApplicationController
|
122
|
+
|
123
|
+
resource_description do
|
124
|
+
name 'Members'
|
125
|
+
short 'Site members'
|
126
|
+
path '/users'
|
127
|
+
version '1.0 - 3.4.2012'
|
128
|
+
param :id, Fixnum, :desc => "User ID", :required => false
|
129
|
+
param :user, Hash, :desc => 'Param description for all methods' do
|
130
|
+
param :username, String, :required => true,
|
131
|
+
:desc => "Username for login"
|
132
|
+
param :password, String, :required => true,
|
133
|
+
:desc => "Password for login"
|
134
|
+
end
|
135
|
+
description <<-DOC
|
136
|
+
Full description of this resource.
|
137
|
+
DOC
|
138
|
+
end
|
139
|
+
#...
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
=== Method Description
|
144
|
+
|
145
|
+
Then describe methods available to your API.
|
146
|
+
|
147
|
+
[api] Say how is this method exposed and provide short description.
|
148
|
+
The first parameter is HTTP method (one of :GET/:POST/:PUT/:DELETE).
|
149
|
+
The second parameter is relative URL path which is mapped to this
|
150
|
+
method. The last parameter is methods short description.
|
151
|
+
You can use this +api+ method more than once for one method. It could
|
152
|
+
be useful when there are more routes mapped to it.
|
153
|
+
[param] Look at Parameter description section for details.
|
154
|
+
[error] Describe each possible error that can happend what calling this
|
155
|
+
method. HTTP response code and description can be provided.
|
156
|
+
[description] Full method description which will be converted to HTML by
|
157
|
+
choosen markup language processor.
|
158
|
+
[example] Provide example of server response, whole communication or response type.
|
159
|
+
It will be formatted as code.
|
160
|
+
[see] Provide reference to another method, this has to be string with
|
161
|
+
controller_name#method_name.
|
162
|
+
|
163
|
+
Example:
|
164
|
+
|
165
|
+
api :GET, "/users/:id", "Show user profile"
|
166
|
+
error :code => 401, :desc => "Unauthorized"
|
167
|
+
error :code => 404, :desc => "Not Found"
|
168
|
+
param :session, String, :desc => "user is logged in", :required => true
|
169
|
+
param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
|
170
|
+
param :array_param, [100, "one", "two", 1, 2], :desc => "array validator"
|
171
|
+
param :boolean_param, [true, false], :desc => "array validator with boolean"
|
172
|
+
param :proc_param, lambda { |val|
|
173
|
+
val == "param value" ? true : "The only good value is 'param value'."
|
174
|
+
}, :desc => "proc validator"
|
175
|
+
description "method description"
|
176
|
+
example " 'user': {...} "
|
177
|
+
see "users#showme"
|
178
|
+
def show
|
179
|
+
#...
|
180
|
+
end
|
181
|
+
|
182
|
+
== Parameter Description
|
183
|
+
|
184
|
+
Use +param+ to describe every possible parameter. You can use Hash validator
|
185
|
+
in cooperation with block given to param method to describe nested parameters.
|
186
|
+
|
187
|
+
[name] The first argument is parameter name as a symbol.
|
188
|
+
[validator] Second parameter is parameter validator, choose one from section
|
189
|
+
Validators.
|
190
|
+
[desc] Parameter description.
|
191
|
+
[required] Set this true/false to make it required/optional.
|
192
|
+
Default is optional
|
193
|
+
|
194
|
+
Example:
|
195
|
+
|
196
|
+
param :user, Hash, :desc => "User info" do
|
197
|
+
param :username, String, :desc => "Username for login", :required => true
|
198
|
+
param :password, String, :desc => "Password for login", :required => true
|
199
|
+
param :membership, ["standard","premium"], :desc => "User membership"
|
200
|
+
end
|
201
|
+
def create
|
202
|
+
#...
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
== Validators
|
207
|
+
|
208
|
+
Every parameter needs to have associated validator. For now there are some
|
209
|
+
basic validators. You can always provide your own to reach complex
|
210
|
+
results.
|
211
|
+
If validations are enabled (default state) the parameters of every
|
212
|
+
request are validated. If the value is wrong a +ArgumentError+ exception
|
213
|
+
is raised and can be rescued and processed. It contains some description
|
214
|
+
of parameter value expectations. Validations can be turned off
|
215
|
+
in configuration file.
|
216
|
+
|
217
|
+
=== TypeValidator
|
218
|
+
|
219
|
+
Check the parameter type. Only String, Hash and Array are supported
|
220
|
+
for the sake of simplicity. Read more to to find out how to add
|
221
|
+
your own validator.
|
222
|
+
|
223
|
+
param :session, String, :desc => "user is logged in", :required => true
|
224
|
+
param :facts, Hash, :desc => "Additional optional facts about the user"
|
225
|
+
|
226
|
+
=== RegexpValidator
|
227
|
+
|
228
|
+
Check parameter value against given regular expression.
|
229
|
+
|
230
|
+
param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
|
231
|
+
|
232
|
+
=== ArrayValidator
|
233
|
+
|
234
|
+
Check if parameter value is included given array.
|
235
|
+
|
236
|
+
param :array_param, [100, "one", "two", 1, 2], :desc => "array validator"
|
237
|
+
|
238
|
+
=== ProcValidator
|
239
|
+
|
240
|
+
If you need more complex validation and you know you won't reuse it you
|
241
|
+
can use Proc/lambda validator. Provide your own Proc taking value
|
242
|
+
of parameter as the only argument. Return true if value pass validation
|
243
|
+
or return some text about what is wrong. _Don't use the keyword *return*
|
244
|
+
if you provide instance of Proc (with lambda it is ok), just use the last
|
245
|
+
statement return property of ruby_.
|
246
|
+
|
247
|
+
param :proc_param, lambda { |val|
|
248
|
+
val == "param value" ? true : "The only good value is 'param value'."
|
249
|
+
}, :desc => "proc validator"
|
250
|
+
|
251
|
+
=== HashValidator
|
252
|
+
|
253
|
+
You can describe hash parameters in depth if you provide a block with
|
254
|
+
description of nested values.
|
255
|
+
|
256
|
+
param :user, Hash, :desc => "User info" do
|
257
|
+
param :username, String, :desc => "Username for login", :required => true
|
258
|
+
param :password, String, :desc => "Password for login", :required => true
|
259
|
+
param :membership, ["standard","premium"], :desc => "User membership"
|
260
|
+
end
|
261
|
+
|
262
|
+
=== NilValidator
|
263
|
+
|
264
|
+
In fact there is any NilValidator but setting it to nil can be used to
|
265
|
+
override parameters described on resource level.
|
266
|
+
|
267
|
+
Example:
|
268
|
+
|
269
|
+
param :user, nil
|
270
|
+
def destroy
|
271
|
+
#...
|
272
|
+
end
|
273
|
+
|
274
|
+
=== Adding custom validator
|
275
|
+
|
276
|
+
Only basic validators are included but it is really easy to add your own.
|
277
|
+
Create new initializer with subclass of Apipie::Validator::BaseValidator.
|
278
|
+
Two methods are required to implement - instance method
|
279
|
+
<tt>validate(value)</tt> and class method
|
280
|
+
<tt>build(param_description, argument, options, block)</tt>.
|
281
|
+
|
282
|
+
When searching for validator +build+ method of every subclass of
|
283
|
+
Apipie::Validator::BaseValidator is called. The first one whitch return
|
284
|
+
constructed validator object is used.
|
285
|
+
|
286
|
+
Example: Adding IntegerValidator
|
287
|
+
|
288
|
+
We want to check if parameter value is an integer like this:
|
289
|
+
|
290
|
+
param :id, Integer, :desc => "Company ID"
|
291
|
+
|
292
|
+
So we create apipie_validators.rb initializer with this content:
|
293
|
+
|
294
|
+
class IntegerValidator < Apipie::Validator::BaseValidator
|
295
|
+
|
296
|
+
def initialize(param_description, argument)
|
297
|
+
super(param_description)
|
298
|
+
@type = argument
|
299
|
+
end
|
300
|
+
|
301
|
+
def validate(value)
|
302
|
+
return false if value.nil?
|
303
|
+
!!(value.to_s =~ \/^[-+]?[0-9]+$/)
|
304
|
+
end
|
305
|
+
|
306
|
+
def self.build(param_description, argument, options, block)
|
307
|
+
if argument == Integer || argument == Fixnum
|
308
|
+
self.new(param_description, argument)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def error
|
313
|
+
"Parameter \#{@param_name} expecting to be \#{@type.name},
|
314
|
+
got: \#{@error_value.class.name}"
|
315
|
+
end
|
316
|
+
|
317
|
+
def description
|
318
|
+
"Parameter has to be #{@type}."
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
Parameters of the build method:
|
323
|
+
|
324
|
+
[param_description] Instance of Apipie::ParamDescription contains all
|
325
|
+
given informations about validated parameter.
|
326
|
+
[argument] Specified validator, in our example it is +Integer+
|
327
|
+
[options] Hash with specified options, for us just
|
328
|
+
<tt>{:desc => "Company ID"}</tt>
|
329
|
+
[block] Block converted into Proc, use it as you desire. In this example nil.
|
330
|
+
|
331
|
+
|
332
|
+
== Markup
|
333
|
+
|
334
|
+
The default markup language is {RDoc}[http://rdoc.rubyforge.org/RDoc/Markup.html]. It can be changed in
|
335
|
+
config file (config.markup=) to one of these:
|
336
|
+
[Markdown] Use Apipie::Markup::Markdown.new. You need Redcarpet gem.
|
337
|
+
[Textile] Use Apipie::Markup::Textile.new. You need RedCloth gem.
|
338
|
+
|
339
|
+
Or provide you own object with <tt>to_html(text)</tt> method.
|
340
|
+
For inspiration this is how Textile look like:
|
341
|
+
|
342
|
+
class Textile
|
343
|
+
def initialize
|
344
|
+
require 'RedCloth'
|
345
|
+
end
|
346
|
+
def to_html(text)
|
347
|
+
RedCloth.new(text).to_html
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
== Static page
|
352
|
+
|
353
|
+
To generate static version of documentation run <tt>rake apipie:static</tt> task.
|
354
|
+
It will create folder with one-page documentation in your public directory. Rename
|
355
|
+
or delete it if you want to use 'normal' dynamic version again.
|
356
|
+
|
357
|
+
== {CLI client}[https://github.com/Pajk/apipie-rails/wiki/CLI-client]
|
358
|
+
|
359
|
+
== {Extractor}[https://github.com/Pajk/apipie-rails/wiki/Extractor]
|
360
|
+
|
361
|
+
== Future features
|
362
|
+
|
363
|
+
* Dynamic CLI client (read info from documentation API)
|
364
|
+
* Add documentation json API description to readme
|
365
|
+
* Possibility to create requests from web documentation and check responses
|