jmoses_apipie-rails 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +11 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/APACHE-LICENSE-2.0 +202 -0
  5. data/CHANGELOG +55 -0
  6. data/Gemfile +3 -0
  7. data/MIT-LICENSE +20 -0
  8. data/NOTICE +4 -0
  9. data/README.rst +938 -0
  10. data/Rakefile +13 -0
  11. data/apipie-rails.gemspec +26 -0
  12. data/app/controllers/apipie/apipies_controller.rb +105 -0
  13. data/app/public/apipie/javascripts/apipie.js +6 -0
  14. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +138 -0
  15. data/app/public/apipie/javascripts/bundled/bootstrap.js +1726 -0
  16. data/app/public/apipie/javascripts/bundled/jquery-1.7.2.js +9404 -0
  17. data/app/public/apipie/javascripts/bundled/prettify.js +28 -0
  18. data/app/public/apipie/stylesheets/application.css +20 -0
  19. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +12 -0
  20. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +689 -0
  21. data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
  22. data/app/views/apipie/apipies/_disqus.html.erb +11 -0
  23. data/app/views/apipie/apipies/_params.html.erb +29 -0
  24. data/app/views/apipie/apipies/_params_plain.html.erb +16 -0
  25. data/app/views/apipie/apipies/apipie_404.html.erb +12 -0
  26. data/app/views/apipie/apipies/getting_started.html.erb +4 -0
  27. data/app/views/apipie/apipies/index.html.erb +43 -0
  28. data/app/views/apipie/apipies/method.html.erb +71 -0
  29. data/app/views/apipie/apipies/plain.html.erb +70 -0
  30. data/app/views/apipie/apipies/resource.html.erb +98 -0
  31. data/app/views/apipie/apipies/static.html.erb +101 -0
  32. data/app/views/layouts/apipie/apipie.html.erb +26 -0
  33. data/lib/apipie-rails.rb +15 -0
  34. data/lib/apipie/apipie_module.rb +62 -0
  35. data/lib/apipie/application.rb +334 -0
  36. data/lib/apipie/client/generator.rb +135 -0
  37. data/lib/apipie/configuration.rb +128 -0
  38. data/lib/apipie/dsl_definition.rb +379 -0
  39. data/lib/apipie/error_description.rb +25 -0
  40. data/lib/apipie/errors.rb +38 -0
  41. data/lib/apipie/extractor.rb +151 -0
  42. data/lib/apipie/extractor/collector.rb +113 -0
  43. data/lib/apipie/extractor/recorder.rb +124 -0
  44. data/lib/apipie/extractor/writer.rb +367 -0
  45. data/lib/apipie/helpers.rb +52 -0
  46. data/lib/apipie/markup.rb +48 -0
  47. data/lib/apipie/method_description.rb +191 -0
  48. data/lib/apipie/param_description.rb +204 -0
  49. data/lib/apipie/railtie.rb +9 -0
  50. data/lib/apipie/resource_description.rb +102 -0
  51. data/lib/apipie/routing.rb +15 -0
  52. data/lib/apipie/see_description.rb +39 -0
  53. data/lib/apipie/static_dispatcher.rb +59 -0
  54. data/lib/apipie/validator.rb +310 -0
  55. data/lib/apipie/version.rb +3 -0
  56. data/lib/generators/apipie/install/README +6 -0
  57. data/lib/generators/apipie/install/install_generator.rb +25 -0
  58. data/lib/generators/apipie/install/templates/initializer.rb.erb +7 -0
  59. data/lib/tasks/apipie.rake +166 -0
  60. data/rel-eng/packages/.readme +3 -0
  61. data/rel-eng/packages/rubygem-apipie-rails +1 -0
  62. data/rel-eng/tito.props +5 -0
  63. data/spec/controllers/api/v1/architectures_controller_spec.rb +30 -0
  64. data/spec/controllers/api/v2/architectures_controller_spec.rb +12 -0
  65. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +11 -0
  66. data/spec/controllers/apipies_controller_spec.rb +141 -0
  67. data/spec/controllers/concerns_controller_spec.rb +42 -0
  68. data/spec/controllers/users_controller_spec.rb +473 -0
  69. data/spec/dummy/Rakefile +7 -0
  70. data/spec/dummy/app/controllers/api/base_controller.rb +4 -0
  71. data/spec/dummy/app/controllers/api/v1/architectures_controller.rb +42 -0
  72. data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
  73. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +30 -0
  74. data/spec/dummy/app/controllers/api/v2/base_controller.rb +11 -0
  75. data/spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb +30 -0
  76. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +33 -0
  77. data/spec/dummy/app/controllers/application_controller.rb +6 -0
  78. data/spec/dummy/app/controllers/concerns/sample_controller.rb +39 -0
  79. data/spec/dummy/app/controllers/concerns_controller.rb +8 -0
  80. data/spec/dummy/app/controllers/twitter_example_controller.rb +302 -0
  81. data/spec/dummy/app/controllers/users_controller.rb +251 -0
  82. data/spec/dummy/app/views/layouts/application.html.erb +21 -0
  83. data/spec/dummy/config.ru +4 -0
  84. data/spec/dummy/config/application.rb +45 -0
  85. data/spec/dummy/config/boot.rb +10 -0
  86. data/spec/dummy/config/database.yml +21 -0
  87. data/spec/dummy/config/environment.rb +8 -0
  88. data/spec/dummy/config/environments/development.rb +25 -0
  89. data/spec/dummy/config/environments/production.rb +49 -0
  90. data/spec/dummy/config/environments/test.rb +35 -0
  91. data/spec/dummy/config/initializers/apipie.rb +102 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/inflections.rb +10 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  95. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  96. data/spec/dummy/config/initializers/session_store.rb +8 -0
  97. data/spec/dummy/config/locales/en.yml +5 -0
  98. data/spec/dummy/config/routes.rb +22 -0
  99. data/spec/dummy/db/.gitkeep +0 -0
  100. data/spec/dummy/doc/apipie_examples.yml +28 -0
  101. data/spec/dummy/public/404.html +26 -0
  102. data/spec/dummy/public/422.html +26 -0
  103. data/spec/dummy/public/500.html +26 -0
  104. data/spec/dummy/public/favicon.ico +0 -0
  105. data/spec/dummy/public/javascripts/application.js +2 -0
  106. data/spec/dummy/public/javascripts/controls.js +965 -0
  107. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  108. data/spec/dummy/public/javascripts/effects.js +1123 -0
  109. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  110. data/spec/dummy/public/javascripts/rails.js +202 -0
  111. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  112. data/spec/dummy/script/rails +6 -0
  113. data/spec/lib/application_spec.rb +38 -0
  114. data/spec/lib/method_description_spec.rb +30 -0
  115. data/spec/lib/param_description_spec.rb +174 -0
  116. data/spec/lib/param_group_spec.rb +45 -0
  117. data/spec/lib/resource_description_spec.rb +30 -0
  118. data/spec/lib/validator_spec.rb +46 -0
  119. data/spec/spec_helper.rb +32 -0
  120. metadata +337 -0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ .idea
8
+ Gemfile.lock
9
+ .rvmrc
10
+
11
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
@@ -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/CHANGELOG ADDED
@@ -0,0 +1,55 @@
1
+ ===========
2
+ Changelog
3
+ ===========
4
+
5
+ v0.0.22
6
+ -------
7
+
8
+ * fix "named_resources" option
9
+ * fix generating static files when concerns used
10
+
11
+ v0.0.21
12
+ -------
13
+
14
+ * fix RDoc 4.0 compatibility issue
15
+ * ``validate_value`` and ``validate_presence`` options for better
16
+ validation granularity
17
+
18
+ v0.0.20
19
+ -------
20
+
21
+ * namespaced resources - prevent collisions when one resource defined
22
+ in more modules
23
+ * ``Apipie::DSL::Concern`` for being able to use the DSL in module
24
+ that is included into controllers
25
+
26
+ v0.0.19
27
+ -------
28
+
29
+ * fix examples recording when resource_id is set
30
+ * use safe_yaml for loading examples file when available
31
+
32
+ v0.0.18
33
+ -------
34
+
35
+ * ``param_group`` and ``def_param_group`` keywords
36
+ * ``:action_aware`` options for reusing param groups for create/update actions
37
+
38
+ v0.0.17
39
+ -------
40
+
41
+ * support for multiple see links at action and ability to provide
42
+ description of see links
43
+
44
+ v0.0.16
45
+ -------
46
+
47
+ * Fix getting started being rendered even when documentation was available
48
+
49
+ v0.0.15
50
+ -------
51
+
52
+ * Fix case when there is no documentation yet: with link to how to
53
+ start
54
+ * Fix handling bad requests when cache is on
55
+ * Fix params extractor in case there is already some documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
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
@@ -0,0 +1,4 @@
1
+ This gem is released under MIT license. Copy is included in file MIT-LICENSE.
2
+
3
+ Twitter Bootstrap and google-code-prettify are licensed under Apache License
4
+ 2.0. Copy is included in file APACHE-LICENSE-2.0.
data/README.rst ADDED
@@ -0,0 +1,938 @@
1
+ ========================
2
+ API Documentation Tool
3
+ ========================
4
+
5
+ .. image:: https://travis-ci.org/Pajk/apipie-rails.png?branch=master
6
+ :target: https://travis-ci.org/Pajk/apipie-rails
7
+
8
+ Apipie-rails is a DSL and Rails engine for documenting you RESTful
9
+ API. Instead of traditional use of ``#comments``, Apipie let's you
10
+ describe the code by code. This brings advantages like:
11
+
12
+ * no need to learn yet another syntax, you already know Ruby, right?
13
+ * possibility reuse the doc for other purposes (such as validation)
14
+ * easier to extend and maintain (no string parsing involved)
15
+ * possibility to use other sources for documentation purposes (such as
16
+ routes etc.)
17
+
18
+ The documentation is available right in your app (by default under
19
+ ``/apipie`` path. In development mode, you can see the changes as you
20
+ go. It's markup language agnostic and even provides an API for reusing
21
+ the documentation data in form of JSON.
22
+
23
+ Getting started
24
+ ---------------
25
+
26
+ The easiest way to get Apipie up and running with your app is:
27
+
28
+ .. code::
29
+
30
+ $ echo "gem 'apipie-rails'" >> Gemfile
31
+ $ bundle install
32
+ $ rails g apipie:install
33
+
34
+ Now you can start documenting your resources and actions (see
35
+ `DSL Reference`_ for more info:
36
+
37
+ .. code:: ruby
38
+
39
+ api :GET, '/users/:id'
40
+ param :id, :number
41
+ def show
42
+ # ...
43
+ end
44
+
45
+
46
+ Run your application and see the result at
47
+ ``http://localhost:3000/apipie``. For it's further processing, you can
48
+ use ``http://localhost:3000/apipie.json``.
49
+
50
+ For more comprehensive getting started guide, see
51
+ `this demo <https://github.com/iNecas/apipie-demo>`_, that includes
52
+ features such as generating documenation from tests, recording examples etc.
53
+
54
+ Screenshots
55
+ -----------
56
+
57
+ .. image:: https://img.skitch.com/20120428-nruk3e87xs2cu4ydsjujdh11fq.png
58
+ .. image:: https://img.skitch.com/20120428-bni2cmq5cyhjuw1jkd78e3qjxn.png
59
+
60
+ Authors
61
+ -------
62
+
63
+ `Pajk <https://github.com/Pajk>`_ and `iNecas <https://github.com/iNecas>`_
64
+
65
+ Contributors
66
+ ------------
67
+
68
+ See `Contributors page <https://github.com/Pajk/apipie-rails/graphs/contributors>`_. Special thanks to all of them!
69
+
70
+ License
71
+ -------
72
+
73
+ Apipie-rails is released under the `MIT License <http://opensource.org/licenses/MIT>`_
74
+
75
+ ===============
76
+ Documentation
77
+ ===============
78
+
79
+ .. contents:: `Table Of Contents`
80
+ :depth: 2
81
+
82
+ ===============
83
+ DSL Reference
84
+ ===============
85
+
86
+ Resource Description
87
+ --------------------
88
+
89
+ You can describe a resource on controller level. The description is introduced by calling
90
+ ``resource_description do ... end``.
91
+
92
+ Inheritance is supported, so you can specify common params for group of controllers in their parent
93
+ class.
94
+
95
+ The following keywords are available (all are optional):
96
+
97
+ resource_id
98
+ How will the resource be referenced in Apipie (paths, ``see`` command etc.), by default `controller_name.downcase` is used.
99
+
100
+ name
101
+ Human readable name of resource. By default ``class.name.humanize`` is used.
102
+
103
+ short (also short_description)
104
+ Short description of the resource (it's shown on both list of resources and resource details)
105
+
106
+ desc (also description and full_description)
107
+ Full description of the resource (shown only in resource details)
108
+
109
+ param
110
+ Common params for all methods defined in controller/child controllers.
111
+
112
+ api_base_url
113
+ What url is the resource available under.
114
+
115
+ api_versions (also api_version)
116
+ What versions does the controller define the resource. (See `Versioning`_ for details.)
117
+
118
+ formats
119
+ request / response formats.
120
+
121
+ error
122
+ Describe every possible error that can happen what calling all
123
+ methods defined in controller. HTTP response code and description can be provided.
124
+
125
+ app_info
126
+ In case of versioning, this sets app info description on per_version basis.
127
+
128
+ Example:
129
+ ~~~~~~~~
130
+
131
+ .. code:: ruby
132
+
133
+ resource_description do
134
+ short 'Site members'
135
+ formats ['json']
136
+ param :id, Fixnum, :desc => "User ID", :required => false
137
+ param :resource_param, Hash, :desc => 'Param description for all methods' do
138
+ param :ausername, String, :desc => "Username for login", :required => true
139
+ param :apassword, String, :desc => "Password for login", :required => true
140
+ end
141
+ api_version "development"
142
+ error 404, "Missing"
143
+ error 500, "Server crashed for some <%= reason %>"
144
+ description <<-EOS
145
+ == Long description
146
+ Example resource for rest api documentation
147
+ These can now be accessed in <tt>shared/header</tt> with:
148
+ Headline: <%= headline %>
149
+ First name: <%= person.first_name %>
150
+
151
+ If you need to find out whether a certain local variable has been
152
+ assigned a value in a particular render call, you need to use the
153
+ following pattern:
154
+
155
+ <% if local_assigns.has_key? :headline %>
156
+ Headline: <%= headline %>
157
+ <% end %>
158
+
159
+ Testing using <tt>defined? headline</tt> will not work. This is an
160
+ implementation restriction.
161
+
162
+ === Template caching
163
+
164
+ By default, Rails will compile each template to a method in order
165
+ to render it. When you alter a template, Rails will check the
166
+ file's modification time and recompile it in development mode.
167
+ EOS
168
+ end
169
+
170
+
171
+ Method Description
172
+ ------------------
173
+
174
+ Then describe methods available to your API.
175
+
176
+ api
177
+ Say how is this method exposed and provide short description.
178
+ The first parameter is HTTP method (one of :GET/:POST/:PUT/:DELETE).
179
+ The second parameter is relative URL path which is mapped to this
180
+ method. The last parameter is methods short description.
181
+ You can use this +api+ method more than once for one method. It could
182
+ be useful when there are more routes mapped to it.
183
+
184
+ api_versions (also api_version)
185
+ What version(s) does the action belong to. (See `Versioning`_ for details.)
186
+
187
+ param
188
+ Look at Parameter description section for details.
189
+
190
+ formats
191
+ Method level request / response formats.
192
+
193
+ error
194
+ Describe each possible error that can happen what calling this
195
+ method. HTTP response code and description can be provided.
196
+
197
+ description
198
+ Full method description which will be converted to HTML by
199
+ chosen markup language processor.
200
+
201
+ example
202
+ Provide example of server response, whole communication or response type.
203
+ It will be formatted as code.
204
+
205
+ see
206
+ Provide reference to another method, this has to be string with
207
+ controller_name#method_name.
208
+
209
+ Example:
210
+ ~~~~~~~~
211
+
212
+ .. code:: ruby
213
+
214
+ api :GET, "/users/:id", "Show user profile"
215
+ error :code => 401, :desc => "Unauthorized"
216
+ error :code => 404, :desc => "Not Found"
217
+ param :session, String, :desc => "user is logged in", :required => true
218
+ param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
219
+ param :array_param, [100, "one", "two", 1, 2], :desc => "array validator"
220
+ param :boolean_param, [true, false], :desc => "array validator with boolean"
221
+ param :proc_param, lambda { |val|
222
+ val == "param value" ? true : "The only good value is 'param value'."
223
+ }, :desc => "proc validator"
224
+ description "method description"
225
+ formats ['json', 'jsonp', 'xml']
226
+ example " 'user': {...} "
227
+ see "users#showme", "link description"
228
+ see :link => "users#update", :desc => "another link description"
229
+ def show
230
+ #...
231
+ end
232
+
233
+
234
+ Parameter Description
235
+ ---------------------
236
+
237
+ Use ``param`` to describe every possible parameter. You can use Hash validator
238
+ in cooperation with block given to param method to describe nested parameters.
239
+
240
+ name
241
+ The first argument is parameter name as a symbol.
242
+
243
+ validator
244
+ Second parameter is parameter validator, choose one from section `Validators`_
245
+
246
+ desc
247
+ Parameter description.
248
+
249
+ required
250
+ Set this true/false to make it required/optional. Default is optional
251
+
252
+ allow_nil
253
+ Set true is ``nil`` can be passed for this param.
254
+
255
+ Example:
256
+ ~~~~~~~~
257
+
258
+ .. code:: ruby
259
+
260
+ param :user, Hash, :desc => "User info" do
261
+ param :username, String, :desc => "Username for login", :required => true
262
+ param :password, String, :desc => "Password for login", :required => true
263
+ param :membership, ["standard","premium"], :desc => "User membership"
264
+ end
265
+ def create
266
+ #...
267
+ end
268
+
269
+ DRY with param_group
270
+ --------------------
271
+
272
+ Often, params occur together in more actions. Typically, most of the
273
+ params for ``create`` and ``update`` actions are common for both of
274
+ them.
275
+
276
+ This params can be extracted with ``def_param_group`` and
277
+ ``param_group`` keywords.
278
+
279
+ The definition is looked up in the scope of the controller. If the
280
+ group is defined in a different controller, it might be referenced by
281
+ specifying the second argument.
282
+
283
+ Example:
284
+ ~~~~~~~~
285
+
286
+ .. code:: ruby
287
+
288
+ # v1/users_controller.rb
289
+ def_param_group :address do
290
+ param :street, String
291
+ param :number, Integer
292
+ param :zip, String
293
+ end
294
+
295
+ def_param_group :user do
296
+ param :user, Hash do
297
+ param :name, String, "Name of the user"
298
+ param_group :address
299
+ end
300
+ end
301
+
302
+ api :POST, "/users", "Create an user"
303
+ param_group :user
304
+ def create
305
+ # ...
306
+ end
307
+
308
+ api :PUT, "/users/:id", "Update an user"
309
+ param_group :user
310
+ def update
311
+ # ...
312
+ end
313
+
314
+ # v2/users_controller.rb
315
+ api :POST, "/users", "Create an user"
316
+ param_group :user, V1::UsersController
317
+ def create
318
+ # ...
319
+ end
320
+
321
+ Action Aware params
322
+ -------------------
323
+
324
+ In CRUD operations, this pattern occurs quite often: params that need
325
+ to be set are:
326
+
327
+ * for create action: ``required => true`` and ``allow_nil => false``
328
+ * for update action: ``required => false`` and ``allow_nil => false``
329
+
330
+ This makes it hard to share the param definitions across theses
331
+ actions. Therefore, you can make the description a bit smarter by
332
+ setting ``:action_aware => true``.
333
+
334
+ You can specify explicitly how the param group should be evaluated
335
+ with ``:as`` option (either :create or :update)
336
+
337
+ Example
338
+ ~~~~~~~
339
+
340
+ .. code:: ruby
341
+
342
+ def_param_group :user do
343
+ param :user, Hash, :action_aware => true do
344
+ param :name, String, :required => true
345
+ param :description, :String
346
+ end
347
+ end
348
+
349
+ api :POST, "/users", "Create an user"
350
+ param_group :user
351
+ def create
352
+ # ...
353
+ end
354
+
355
+ api :PUT, "/users/admin", "Create an admin"
356
+ param_group :user, :as => :create
357
+ def create_admin
358
+ # ...
359
+ end
360
+
361
+ api :PUT, "/users/:id", "Update an user"
362
+ param_group :user
363
+ def update
364
+ # ...
365
+ end
366
+
367
+ In this case, ``user[name]`` will be not be allowed nil for all
368
+ actions and required only for ``create`` and ``create_admin``. Params
369
+ with ``allow_nil`` set explicitly don't have this value changed.
370
+
371
+ Action awareness is being inherited from ancestors (in terms of
372
+ nested params).
373
+
374
+ Concerns
375
+ --------
376
+
377
+ Sometimes, the actions are not defined in the controller class
378
+ directly but included from a module instead. You can load the Apipie
379
+ DSL into the module by extending it with ``Apipie::DSL::Concern``.
380
+
381
+ The module can be used in more controllers. Therefore there is a way
382
+ how to substitute parts of the documentation in the module with controller
383
+ specific values. The substitutions can be stated explicitly with
384
+ ``apipie_concern_subst(:key => "value")`` (needs to be called before
385
+ the module is included to take effect). The substitutions are
386
+ performed in paths and descriptions of APIs and names and descriptions
387
+ of params.
388
+
389
+ There are some default substitutions available:
390
+
391
+ :controller_path
392
+ value of ``controller.controller_path``, e.g. ``api/users`` for
393
+ ``Api::UsersController``
394
+
395
+ :resource_id
396
+ Apipie identifier of the resource, e.g. ``users`` for
397
+ ``Api::UsersController`` or set by ``resource_id``
398
+
399
+ Example
400
+ ~~~~~~~
401
+
402
+ .. code:: ruby
403
+
404
+ # users_module.rb
405
+ module UsersModule
406
+ extend Apipie::DSL::Concern
407
+
408
+ api :GET, '/:controller_path', 'List :resource_id'
409
+ def index
410
+ # ...
411
+ end
412
+
413
+ api :GET, '/:resource_id/:id', 'Show a :resource'
414
+ def show
415
+ # ...
416
+ end
417
+
418
+ api :POST, '/:resource_id', "Create a :resource"
419
+ param :concern, Hash, :required => true
420
+ param :name, String, 'Name of a :resource'
421
+ param :resource_type, ['standard','vip']
422
+ end
423
+ def create
424
+ # ...
425
+ end
426
+
427
+ api :GET, '/:resource_id/:custom_subst'
428
+ def custom
429
+ # ...
430
+ end
431
+ end
432
+
433
+ # users_controller.rb
434
+ class UsersController < ApplicationController
435
+
436
+ resource_description { resource_id 'customers' }
437
+
438
+ apipie_concern_subst(:custom_subst => 'custom', :resource => 'customer')
439
+ include UsersModule
440
+
441
+ # the following paths are documented
442
+ # api :GET, '/users'
443
+ # api :GET, '/customers/:id', 'Show a customer'
444
+ # api :POST, '/customers', 'Create a customer'
445
+ # param :customer, :required => true do
446
+ # param :name, String, 'Name of a customer'
447
+ # param :customer_type, ['standard', 'vip']
448
+ # end
449
+ # api :GET, '/customers/:custom'
450
+ end
451
+
452
+
453
+
454
+ =========================
455
+ Configuration Reference
456
+ =========================
457
+
458
+ Create configuration file in e.g. ``/config/initializers/apipie.rb``.
459
+ You can set application name, footer text, API and documentation base URL
460
+ and turn off validations. You can also choose your favorite markup language
461
+ of full descriptions.
462
+
463
+ app_name
464
+ Name of your application used in breadcrumbs navigation.
465
+
466
+ copyright
467
+ Copyright information (shown in page footer).
468
+
469
+ doc_base_url
470
+ Documentation frontend base url.
471
+
472
+ api_base_url
473
+ Base url of your API, most probably /api.
474
+
475
+ default_version
476
+ Default API version to be used (1.0 by default)
477
+
478
+ validate
479
+ Parameters validation is turned off when set to false.
480
+
481
+ validate_value
482
+ Check the value of params against specified validators (true by
483
+ default)
484
+
485
+ validate_presence
486
+ Check the params presence against the documentation.
487
+
488
+ app_info
489
+ Application long description.
490
+
491
+ reload_controllers
492
+ Set to enable/disable reloading controllers (and the documentation with it), by default enabled in development.
493
+
494
+ api_controllers_matcher
495
+ For reloading to work properly you need to specify where your API controllers are.
496
+
497
+ markup
498
+ You can choose markup language for descriptions of your application,
499
+ resources and methods. RDoc is the default but you can choose from
500
+ Apipie::Markup::Markdown.new or Apipie::Markup::Textile.new.
501
+ In order to use Markdown you need Redcarpet gem and for Textile you
502
+ need RedCloth. Add those to your gemfile and run bundle if you
503
+ want to use them. You can also add any other markup language
504
+ processor.
505
+
506
+ layout
507
+ Name of a layout template to use instead of Apipie's layout. You can use
508
+ Apipie.include_stylesheets and Apipie.include_javascripts helpers to include
509
+ Apipie's stylesheets and javascripts.
510
+
511
+ ignored
512
+ An array of controller names (strings) (might include actions as well)
513
+ to be ignored when generationg the documentation
514
+ e.g. ``%w[Api::CommentsController Api::PostsController#post]``
515
+
516
+ namespaced_resources
517
+ Use controller paths instead of controller names as resource id.
518
+ This prevents same named controllers overwriting each other.
519
+
520
+
521
+ Example:
522
+
523
+ .. code:: ruby
524
+
525
+ Apipie.configure do |config|
526
+ config.app_name = "Test app"
527
+ config.copyright = "&copy; 2012 Pavel Pokorny"
528
+ config.doc_base_url = "/apidoc"
529
+ config.api_base_url = "/api"
530
+ config.validate = false
531
+ config.markup = Apipie::Markup::Markdown.new
532
+ config.reload_controllers = true
533
+ config.api_controllers_matcher = File.join(Rails.root, "app", "controllers", "**","*.rb")
534
+ config.app_info = "
535
+ This is where you can inform user about your application and API
536
+ in general.
537
+ ", '1.0'
538
+ end
539
+
540
+
541
+ ============
542
+ Validators
543
+ ============
544
+
545
+ Every parameter needs to have associated validator. For now there are some
546
+ basic validators. You can always provide your own to reach complex
547
+ results.
548
+
549
+ If validations are enabled (default state) the parameters of every
550
+ request are validated. If the value is wrong a +ArgumentError+ exception
551
+ is raised and can be rescued and processed. It contains some description
552
+ of parameter value expectations. Validations can be turned off
553
+ in configuration file.
554
+
555
+
556
+ TypeValidator
557
+ -------------
558
+ Check the parameter type. Only String, Hash and Array are supported
559
+ for the sake of simplicity. Read more to to find out how to add
560
+ your own validator.
561
+
562
+ .. code:: ruby
563
+
564
+ param :session, String, :desc => "user is logged in", :required => true
565
+ param :facts, Hash, :desc => "Additional optional facts about the user"
566
+
567
+
568
+ RegexpValidator
569
+ ---------------
570
+ Check parameter value against given regular expression.
571
+
572
+ .. code:: ruby
573
+
574
+ param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
575
+
576
+
577
+ ArrayValidator
578
+ --------------
579
+
580
+ Check if parameter value is included given array.
581
+
582
+ .. code:: ruby
583
+
584
+ param :array_param, [100, "one", "two", 1, 2], :desc => "array validator"
585
+
586
+
587
+ ProcValidator
588
+ -------------
589
+
590
+ If you need more complex validation and you know you won't reuse it you
591
+ can use Proc/lambda validator. Provide your own Proc taking value
592
+ of parameter as the only argument. Return true if value pass validation
593
+ or return some text about what is wrong. _Don't use the keyword *return*
594
+ if you provide instance of Proc (with lambda it is ok), just use the last
595
+ statement return property of ruby.
596
+
597
+ .. code:: ruby
598
+
599
+ param :proc_param, lambda { |val|
600
+ val == "param value" ? true : "The only good value is 'param value'."
601
+ }, :desc => "proc validator"
602
+
603
+
604
+ HashValidator
605
+ -------------
606
+
607
+ You can describe hash parameters in depth if you provide a block with
608
+ description of nested values.
609
+
610
+ .. code:: ruby
611
+
612
+ param :user, Hash, :desc => "User info" do
613
+ param :username, String, :desc => "Username for login", :required => true
614
+ param :password, String, :desc => "Password for login", :required => true
615
+ param :membership, ["standard","premium"], :desc => "User membership"
616
+ end
617
+
618
+
619
+ NilValidator
620
+ ------------
621
+
622
+ In fact there is any NilValidator but setting it to nil can be used to
623
+ override parameters described on resource level.
624
+
625
+ .. code:: ruby
626
+
627
+ param :user, nil
628
+ def destroy
629
+ #...
630
+ end
631
+
632
+
633
+ Adding custom validator
634
+ -----------------------
635
+
636
+ Only basic validators are included but it is really easy to add your own.
637
+ Create new initializer with subclass of Apipie::Validator::BaseValidator.
638
+ Two methods are required to implement - instance method
639
+ <tt>validate(value)</tt> and class method
640
+ <tt>build(param_description, argument, options, block)</tt>.
641
+
642
+ When searching for validator +build+ method of every subclass of
643
+ Apipie::Validator::BaseValidator is called. The first one whitch return
644
+ constructed validator object is used.
645
+
646
+ Example: Adding IntegerValidator
647
+
648
+ We want to check if parameter value is an integer like this:
649
+
650
+ .. code:: ruby
651
+
652
+ param :id, Integer, :desc => "Company ID"
653
+
654
+ So we create apipie_validators.rb initializer with this content:
655
+
656
+ .. code:: ruby
657
+
658
+ class IntegerValidator < Apipie::Validator::BaseValidator
659
+
660
+ def initialize(param_description, argument)
661
+ super(param_description)
662
+ @type = argument
663
+ end
664
+
665
+ def validate(value)
666
+ return false if value.nil?
667
+ !!(value.to_s =~ /^[-+]?[0-9]+$/)
668
+ end
669
+
670
+ def self.build(param_description, argument, options, block)
671
+ if argument == Integer || argument == Fixnum
672
+ self.new(param_description, argument)
673
+ end
674
+ end
675
+
676
+ def description
677
+ "Must be #{@type}."
678
+ end
679
+ end
680
+
681
+ Parameters of the build method:
682
+
683
+ param_description
684
+ Instance of Apipie::ParamDescription contains all
685
+ given informations about validated parameter.
686
+
687
+ argument
688
+ Specified validator, in our example it is +Integer+
689
+
690
+ options
691
+ Hash with specified options, for us just ``{:desc => "Company ID"}``
692
+
693
+ block
694
+ Block converted into Proc, use it as you desire. In this example nil.
695
+
696
+
697
+ ============
698
+ Versioning
699
+ ============
700
+
701
+ Every resource/method can belong to one or more versions. The version is
702
+ specified with the `api_version` DSL keyword. When not specified,
703
+ the resource belong to `config.default_version` ("1.0" by default)
704
+
705
+ .. code:: ruby
706
+
707
+ resource_description do
708
+ api_versions "1", "2"
709
+ end
710
+
711
+ api :GET, "/api/users/"
712
+ api_version "1"
713
+ def index
714
+ # ...
715
+ end
716
+
717
+ In the example above we say the whole controller/resource is defined
718
+ for versions "1" and "2", but we override this with explicitly saying
719
+ `index` belongs only to version "1". Also inheritance works (therefore
720
+ we can specify the api_version for the parent controller and all
721
+ children will know about that).
722
+
723
+ From the Apipie API perspective, the resources belong to version.
724
+ With versioning, there are paths like this provided by apipie:
725
+
726
+ .. code::
727
+
728
+ /apipie/1/users/index
729
+ /apipie/2/users/index
730
+
731
+ When not specifying the version explicitly in the path (or in dsl),
732
+ default version (`Apipie.configuration.default_version`) is used
733
+ instead ("1.0" by default). Therefore, the application that doesn't
734
+ need versioning should work as before.
735
+
736
+ The static page generator takes version parameter (or uses default).
737
+
738
+ You can specify the versions for the examples, with `versions`
739
+ keyword. It specifies the versions the example is used for. When not
740
+ specified, it's shown in all versions with given method.
741
+
742
+ When referencing or quering the resource/method descripion, this
743
+ format should be used: "verson#resource#method". When not specified,
744
+ the default version is used instead.
745
+
746
+
747
+ ========
748
+ Markup
749
+ ========
750
+
751
+ The default markup language is `RDoc
752
+ <http://rdoc.rubyforge.org/RDoc/Markup.html>`_. It can be changed in
753
+ config file (``config.markup=``) to one of these:
754
+
755
+ Markdown
756
+ Use Apipie::Markup::Markdown.new. You need Maruku gem.
757
+
758
+ Textile
759
+ Use Apipie::Markup::Textile.new. You need RedCloth gem.
760
+
761
+ Or provide you own object with ``to_html(text)`` method.
762
+ For inspiration this is how Textile markup usage looks like:
763
+
764
+ .. code:: ruby
765
+
766
+ class Textile
767
+ def initialize
768
+ require 'RedCloth'
769
+ end
770
+ def to_html(text)
771
+ RedCloth.new(text).to_html
772
+ end
773
+ end
774
+
775
+
776
+ ==============
777
+ Static files
778
+ ==============
779
+
780
+ To generate static version of documentation (perhaps to put it on
781
+ project site or something) run ``rake apipie:static`` task. It will
782
+ create set of html files (multi-pages, single-page, plain) in your doc
783
+ directory. By default the documentation for default API version is
784
+ used, you can specify the version with ``rake apipie:static[2.0]``
785
+
786
+ When you want to avoid any unnecessary computation in production mode,
787
+ you can generate a cache with ``rake apipie:cache`` and configure the
788
+ app to use it in production with ``config.use_cache = Rails.env.production?``
789
+
790
+ ===================
791
+ Tests Integration
792
+ ===================
793
+
794
+ Apipie integrates with automated testing in two ways. *Documentation
795
+ bootstrapping* and *examples recording*.
796
+
797
+ Documentation Bootstrapping
798
+ ---------------------------
799
+
800
+ Let's say you have an application without REST API documentation.
801
+ However you have a set of tests that are run against this API. A lot
802
+ of information is already included in this tests, it just needs to be
803
+ extracted somehow. Luckily, Apipie provides such a feature.
804
+
805
+ When running the tests, set the ``APIPIE_RECORD=params`` environment
806
+ variable. You can either use it with functional tests
807
+
808
+ .. code::
809
+
810
+ APIPIE_RECORD=params rake test:functionals
811
+
812
+ or you can run your server with this param, in case you run the tests
813
+ against running server
814
+
815
+ .. code::
816
+
817
+ APIPIE_RECORD=params rails server
818
+
819
+ When the process quits, the data from requests/responses are used to
820
+ determine the documentation. It's quite raw, but it makes the initial
821
+ phase much easier.
822
+
823
+ Examples Recording
824
+ ------------------
825
+
826
+ You can also use the tests to generate up-to-date examples for your
827
+ code. Similarly to the bootstrapping, you can use it with functional
828
+ tests or a running server, setting ``APIPIE_RECORD=examples``
829
+
830
+ .. code::
831
+
832
+ APIPIE_RECORD=examples rake test:functionals
833
+ APIPIE_RECORD=examples rails server
834
+
835
+ The data is written into ``doc/apipie_examples.yml``. By default,
836
+ only the first example is shown for each action. You can customize
837
+ this by setting ``show_in_doc`` attribute at each example.
838
+
839
+ .. code::
840
+
841
+ --- !omap
842
+ - announcements#index:
843
+ - !omap
844
+ - verb: :GET
845
+ - path: /api/blabla/1
846
+ - versions:
847
+ - '1.0'
848
+ - query:
849
+ - request_data:
850
+ - response_data:
851
+ ...
852
+ - code: 200
853
+ - show_in_doc: 1 # If 1, show. If 0, do not show.
854
+ - recorded: true
855
+
856
+ In RSpec you can add metadata to examples. We can use that feature
857
+ to mark selected examples – the ones that perform the requests that we want to
858
+ show as examples in the documentation.
859
+
860
+ For example, we can add ``show_in_doc`` to examples, like this:
861
+
862
+ .. code:: ruby
863
+
864
+ describe "This is the correct path" do
865
+ it "some test", :show_in_doc do
866
+ ....
867
+ end
868
+ end
869
+
870
+ context "These are edge cases" do
871
+ it "Can't authenticate" do
872
+ ....
873
+ end
874
+
875
+ it "record not found" do
876
+ ....
877
+ end
878
+ end
879
+
880
+ And then configure RSpec in this way:
881
+
882
+ .. code:: ruby
883
+
884
+ RSpec.configure do |config|
885
+ config.treat_symbols_as_metadata_keys_with_true_values = true
886
+ config.filter_run :show_in_doc => true if ENV['APIPIE_RECORD']
887
+ end
888
+
889
+ This way, when running in recording mode, only the tests that has been marked with the
890
+ ``:show_in_doc`` metadata will be ran, and hence only those will be used as examples.
891
+
892
+ ====================
893
+ Bindings Generator
894
+ ====================
895
+
896
+ In earlier versions (<= 0.0.13), there was a simple client generator
897
+ as a part of Apipie gem. As more features and users came to Apipie,
898
+ more and more there was a need for changes on per project basis. It's
899
+ hard (or even impossible) to provide a generic solution for the client
900
+ code. We also don't want to tell you what's the rigth way to do it
901
+ (what gems to use, how the API should look like etc.).
902
+
903
+ Therefore you can't generate a client code directly by a rake task in
904
+ further versions.
905
+
906
+ There is, however, even better and more flexible way to reuse your API
907
+ documentation for this purpose: using the API the Apipie
908
+ provides in the generator code. You can inspire by
909
+ `Foreman API bindings <https://github.com/mbacovsky/foreman_api>`_ that
910
+ use exactly this approach. You also don't need to run the service,
911
+ provided it uses Apipie as a backend.
912
+
913
+ And if you write one on your own, don't hesitate to share it with us!
914
+
915
+ ====================
916
+ Disqus Integration
917
+ ====================
918
+
919
+ You can get a `Disqus <http://www.disqus.com>`_ discussion for the
920
+ right into your documentation. Just set the credentials in Apipie
921
+ configuration:
922
+
923
+ .. code:: ruby
924
+
925
+ config.disqus_shortname = "MyProjectDoc"
926
+
927
+ =====================
928
+ External References
929
+ =====================
930
+
931
+ * `Getting started tutorial <https://github.com/iNecas/apipie-demo>`_ -
932
+ including examples of using the tests integration and versioning.
933
+
934
+ * `Real-world application usage <https://github.com/Katello/katello>`_
935
+
936
+ * `Read-world application usage with versioning <https://github.com/theforeman/foreman>`_
937
+
938
+ * `Using Apipie API to generate bindings <https://github.com/mbacovsky/foreman_api>`_