apipie-rails 0.3.6 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +67 -0
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +37 -0
  6. data/.rubocop_todo.yml +1991 -0
  7. data/CHANGELOG.md +246 -2
  8. data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
  9. data/README.rst +646 -25
  10. data/Rakefile +0 -5
  11. data/apipie-rails.gemspec +14 -9
  12. data/app/controllers/apipie/apipies_controller.rb +51 -20
  13. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  14. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  15. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  16. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  17. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  18. data/app/views/apipie/apipies/_method_detail.erb +21 -0
  19. data/app/views/apipie/apipies/_params.html.erb +4 -2
  20. data/app/views/apipie/apipies/index.html.erb +5 -1
  21. data/app/views/apipie/apipies/resource.html.erb +3 -0
  22. data/app/views/layouts/apipie/apipie.html.erb +1 -1
  23. data/config/locales/en.yml +1 -0
  24. data/config/locales/fr.yml +31 -0
  25. data/config/locales/it.yml +31 -0
  26. data/config/locales/ja.yml +31 -0
  27. data/config/locales/ko.yml +31 -0
  28. data/config/locales/pt-BR.yml +1 -1
  29. data/gemfiles/Gemfile.rails50 +10 -0
  30. data/gemfiles/Gemfile.rails51 +10 -0
  31. data/gemfiles/Gemfile.rails52 +10 -0
  32. data/gemfiles/Gemfile.rails60 +17 -0
  33. data/gemfiles/Gemfile.rails61 +17 -0
  34. data/gemfiles/Gemfile.rails70 +17 -0
  35. data/lib/apipie/apipie_module.rb +22 -4
  36. data/lib/apipie/application.rb +54 -25
  37. data/lib/apipie/configuration.rb +26 -4
  38. data/lib/apipie/core_ext/route.rb +9 -0
  39. data/lib/apipie/dsl_definition.rb +168 -16
  40. data/lib/apipie/error_description.rb +9 -2
  41. data/lib/apipie/errors.rb +34 -0
  42. data/lib/apipie/extractor/collector.rb +4 -0
  43. data/lib/apipie/extractor/recorder.rb +14 -12
  44. data/lib/apipie/extractor/writer.rb +86 -58
  45. data/lib/apipie/extractor.rb +5 -5
  46. data/lib/apipie/generator/generator.rb +2 -0
  47. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  48. data/lib/apipie/generator/swagger/type.rb +16 -0
  49. data/lib/apipie/generator/swagger/type_extractor.rb +70 -0
  50. data/lib/apipie/generator/swagger/warning.rb +77 -0
  51. data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
  52. data/lib/apipie/markup.rb +14 -11
  53. data/lib/apipie/method_description/api.rb +12 -0
  54. data/lib/apipie/method_description/apis_service.rb +82 -0
  55. data/lib/apipie/method_description.rb +51 -49
  56. data/lib/apipie/param_description.rb +63 -5
  57. data/lib/apipie/resource_description.rb +11 -4
  58. data/lib/apipie/response_description.rb +131 -0
  59. data/lib/apipie/response_description_adapter.rb +200 -0
  60. data/lib/apipie/routes_formatter.rb +1 -1
  61. data/lib/apipie/rspec/response_validation_helper.rb +194 -0
  62. data/lib/apipie/static_dispatcher.rb +5 -2
  63. data/lib/apipie/swagger_generator.rb +717 -0
  64. data/lib/apipie/tag_list_description.rb +11 -0
  65. data/lib/apipie/validator.rb +83 -9
  66. data/lib/apipie/version.rb +1 -1
  67. data/lib/apipie-rails.rb +15 -4
  68. data/lib/generators/apipie/install/install_generator.rb +1 -1
  69. data/lib/generators/apipie/views_generator.rb +1 -1
  70. data/lib/tasks/apipie.rake +115 -15
  71. data/rel-eng/gem_release.ipynb +398 -0
  72. data/spec/controllers/apipies_controller_spec.rb +79 -14
  73. data/spec/controllers/concerns_controller_spec.rb +2 -2
  74. data/spec/controllers/extended_controller_spec.rb +14 -0
  75. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  76. data/spec/controllers/memes_controller_spec.rb +10 -0
  77. data/spec/controllers/users_controller_spec.rb +139 -76
  78. data/spec/dummy/Rakefile +1 -1
  79. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  80. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  81. data/spec/dummy/app/controllers/extended_controller.rb +14 -0
  82. data/spec/dummy/app/controllers/extending_concern.rb +10 -0
  83. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  84. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  85. data/spec/dummy/app/controllers/pets_controller.rb +408 -0
  86. data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
  87. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
  88. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
  89. data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
  90. data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
  91. data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
  92. data/spec/dummy/app/controllers/users_controller.rb +26 -12
  93. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  94. data/spec/dummy/components/test_engine/Gemfile +6 -0
  95. data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
  96. data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
  97. data/spec/dummy/components/test_engine/config/routes.rb +3 -0
  98. data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
  99. data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
  100. data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
  101. data/spec/dummy/config/application.rb +6 -4
  102. data/spec/dummy/config/boot.rb +2 -2
  103. data/spec/dummy/config/environment.rb +1 -1
  104. data/spec/dummy/config/environments/development.rb +3 -3
  105. data/spec/dummy/config/environments/production.rb +3 -3
  106. data/spec/dummy/config/environments/test.rb +3 -5
  107. data/spec/dummy/config/initializers/apipie.rb +5 -3
  108. data/spec/dummy/config/routes.rb +25 -1
  109. data/spec/dummy/config.ru +1 -1
  110. data/spec/dummy/script/rails +2 -2
  111. data/spec/lib/application_spec.rb +1 -1
  112. data/spec/lib/extractor/writer_spec.rb +37 -7
  113. data/spec/lib/file_handler_spec.rb +25 -0
  114. data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
  115. data/spec/lib/generator/swagger/warning_spec.rb +51 -0
  116. data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
  117. data/spec/lib/method_description/apis_service_spec.rb +60 -0
  118. data/spec/lib/method_description_spec.rb +34 -0
  119. data/spec/lib/param_description_spec.rb +90 -4
  120. data/spec/lib/rake_spec.rb +2 -4
  121. data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
  122. data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
  123. data/spec/lib/swagger/response_validation_spec.rb +104 -0
  124. data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
  125. data/spec/lib/validator_spec.rb +59 -1
  126. data/spec/lib/validators/array_validator_spec.rb +28 -8
  127. data/spec/spec_helper.rb +49 -3
  128. data/spec/support/custom_bool_validator.rb +17 -0
  129. metadata +104 -99
  130. data/.travis.yml +0 -12
  131. data/Gemfile +0 -7
  132. data/Gemfile.rails32 +0 -6
  133. data/Gemfile.rails40 +0 -5
  134. data/Gemfile.rails41 +0 -5
  135. data/Gemfile.rails42 +0 -5
  136. data/lib/apipie/client/generator.rb +0 -135
@@ -0,0 +1,398 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Release of apipie-rails gem\n",
8
+ "\n",
9
+ "### Requirements\n",
10
+ "- push access to https://github.com/Apipie/apipie-rails\n",
11
+ "- push access to rubygems.org for apipie-rails\n",
12
+ "- sudo yum install python-slugify asciidoc\n",
13
+ "- ensure neither the `git push` or `gem push` don't require interractive auth. If you can't use api key or ssh key to auth skip these steps and run them form the shell manually\n",
14
+ "- ensure all checks have passed on the branch you're about to release\n",
15
+ "\n",
16
+ "### Release process\n",
17
+ "- Follow the steps with `<Shift>+<Enter>` or `<Ctrl>+<Enter>,<Down>`\n",
18
+ "- If anything fails, fix it and re-run the step if applicable\n",
19
+ "\n",
20
+ "### Release settings"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "%autosave 0"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "%cd .."
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "markdown",
43
+ "metadata": {},
44
+ "source": [
45
+ "### Update the following notebook settings"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "NEW_VERSION = '0.5.20'\n",
55
+ "LAST_VERSION = '0.5.19'\n",
56
+ "GIT_REMOTE_UPSTREAM = 'origin'\n",
57
+ "STABLE_RELEASE = False\n",
58
+ "WORK_BRANCH = 'stable' if STABLE_RELEASE else 'master'\n",
59
+ "# Array of strings, e.g. [\"21cbsc214g3\", \"21casc214g3\"]\n",
60
+ "CHERRY_PICKS = []\n",
61
+ "GEMFILE='Gemfile.rails61'"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "markdown",
66
+ "metadata": {},
67
+ "source": [
68
+ "### Ensure the repo is up to date"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": null,
74
+ "metadata": {},
75
+ "outputs": [],
76
+ "source": [
77
+ "! git checkout {WORK_BRANCH}"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "! git fetch {GIT_REMOTE_UPSTREAM}"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": null,
92
+ "metadata": {},
93
+ "outputs": [],
94
+ "source": [
95
+ "! git rebase {GIT_REMOTE_UPSTREAM}/{WORK_BRANCH}"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "markdown",
100
+ "metadata": {},
101
+ "source": [
102
+ "### Cherry picks for stable release"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "metadata": {},
109
+ "outputs": [],
110
+ "source": [
111
+ "if STABLE_RELEASE:\n",
112
+ " for cp in CHERRY_PICKS:\n",
113
+ " ! git cherry-pick -x {cp}"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "markdown",
118
+ "metadata": {},
119
+ "source": [
120
+ "### Run tests localy if your setup allows, otherwise ensure the HEAD is green"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": null,
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle update"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": null,
135
+ "metadata": {
136
+ "scrolled": true
137
+ },
138
+ "outputs": [],
139
+ "source": [
140
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rspec"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "markdown",
145
+ "metadata": {},
146
+ "source": [
147
+ "### Update release related stuff"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": null,
153
+ "metadata": {},
154
+ "outputs": [],
155
+ "source": [
156
+ "! sed -i 's/VERSION = .*/VERSION = \"{NEW_VERSION}\"/' lib/apipie/version.rb"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": null,
162
+ "metadata": {},
163
+ "outputs": [],
164
+ "source": [
165
+ "# Parse git changelog\n",
166
+ "from IPython.display import Markdown as md\n",
167
+ "from subprocess import check_output\n",
168
+ "from shlex import split\n",
169
+ "import re\n",
170
+ "\n",
171
+ "def format_log_entry(entry):\n",
172
+ " author = re.search(r'author:(.*)', entry).group(1)\n",
173
+ " entry = re.sub(r'author:(.*)', '', entry)\n",
174
+ " entry = re.sub(r'([fF]ixes|[rR]efs)[^-]*-\\s*(.*)', r'\\2', entry)\n",
175
+ " entry = '* ' + entry.capitalize()\n",
176
+ " entry = re.sub(r'\\(#([0-9]+)\\)', r'[#\\1](https://github.com/Apipie/apipie-rails/pull/\\1)', entry)\n",
177
+ " entry = entry + f'({author})'\n",
178
+ " return entry\n",
179
+ "\n",
180
+ "def skip(entry):\n",
181
+ " if re.match(r'Merge pull', entry) or \\\n",
182
+ " re.match(r'^i18n', entry) or \\\n",
183
+ " re.match(r'^Bump to version', entry):\n",
184
+ " return True\n",
185
+ " else:\n",
186
+ " return False \n",
187
+ "git_log_cmd = 'git log --pretty=format:\"%%s author:%%an\" v%s..HEAD' % LAST_VERSION\n",
188
+ "log = check_output(split(git_log_cmd)).decode('utf8').split('\\n')\n",
189
+ "change_log = [format_log_entry(e) for e in log if not skip(e)]\n",
190
+ "md('\\n'.join(change_log))\n"
191
+ ]
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "execution_count": null,
196
+ "metadata": {},
197
+ "outputs": [],
198
+ "source": [
199
+ "# Write release notes\n",
200
+ "from datetime import datetime\n",
201
+ "import fileinput\n",
202
+ "import sys\n",
203
+ "\n",
204
+ "fh = fileinput.input('CHANGELOG.md', inplace=True) \n",
205
+ "for line in fh: \n",
206
+ " print(line.rstrip())\n",
207
+ " if re.match(r'========', line):\n",
208
+ " print('## [v%s](https://github.com/Apipie/apipie-rails/tree/v%s) (%s)' % (NEW_VERSION, NEW_VERSION, datetime.today().strftime('%Y-%m-%d')))\n",
209
+ " print('[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v%s...v%s)' % (LAST_VERSION, NEW_VERSION))\n",
210
+ " for entry in change_log:\n",
211
+ " print(entry)\n",
212
+ " print('')\n",
213
+ "fh.close() "
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "metadata": {},
219
+ "source": [
220
+ "#### Manual step: Update deps in the gemspec if neccessary"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {},
226
+ "source": [
227
+ "### Check what is going to be commited"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": null,
233
+ "metadata": {
234
+ "scrolled": false
235
+ },
236
+ "outputs": [],
237
+ "source": [
238
+ "! git add -u\n",
239
+ "! git status"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": null,
245
+ "metadata": {
246
+ "scrolled": true
247
+ },
248
+ "outputs": [],
249
+ "source": [
250
+ "! git diff --cached"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "markdown",
255
+ "metadata": {},
256
+ "source": [
257
+ "### Commit changes"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": null,
263
+ "metadata": {
264
+ "scrolled": true
265
+ },
266
+ "outputs": [],
267
+ "source": [
268
+ "! git commit -m \"Bump to {NEW_VERSION}\""
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "metadata": {},
274
+ "source": [
275
+ "### Tag new version"
276
+ ]
277
+ },
278
+ {
279
+ "cell_type": "code",
280
+ "execution_count": null,
281
+ "metadata": {},
282
+ "outputs": [],
283
+ "source": [
284
+ "! git tag {NEW_VERSION}"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "metadata": {},
290
+ "source": [
291
+ "### Build the gem"
292
+ ]
293
+ },
294
+ {
295
+ "cell_type": "code",
296
+ "execution_count": null,
297
+ "metadata": {},
298
+ "outputs": [],
299
+ "source": [
300
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rake build"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": null,
306
+ "metadata": {},
307
+ "outputs": [],
308
+ "source": [
309
+ "! gem push pkg/apipie-rails-{NEW_VERSION}.gem"
310
+ ]
311
+ },
312
+ {
313
+ "cell_type": "markdown",
314
+ "metadata": {},
315
+ "source": [
316
+ "### PUSH the changes upstream If everything is correct"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "code",
321
+ "execution_count": null,
322
+ "metadata": {},
323
+ "outputs": [],
324
+ "source": [
325
+ "! git push {GIT_REMOTE_UPSTREAM} {WORK_BRANCH}"
326
+ ]
327
+ },
328
+ {
329
+ "cell_type": "code",
330
+ "execution_count": null,
331
+ "metadata": {},
332
+ "outputs": [],
333
+ "source": [
334
+ "! git push --tags {GIT_REMOTE_UPSTREAM} {WORK_BRANCH}"
335
+ ]
336
+ },
337
+ {
338
+ "cell_type": "markdown",
339
+ "metadata": {},
340
+ "source": [
341
+ "#### Now the new release is in upstream repo"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "markdown",
346
+ "metadata": {},
347
+ "source": [
348
+ "### Some manual steps follow to improve the UX\n",
349
+ "\n",
350
+ "#### New relase on GitHub\n",
351
+ "\n",
352
+ "Copy the following changelog lines to the description in form on link below\n",
353
+ "The release title is the new version."
354
+ ]
355
+ },
356
+ {
357
+ "cell_type": "code",
358
+ "execution_count": null,
359
+ "metadata": {},
360
+ "outputs": [],
361
+ "source": [
362
+ "print('\\n')\n",
363
+ "print('\\n'.join(change_log))\n",
364
+ "print('\\n\\nhttps://github.com/Apipie/apipie-rails/releases/new?tag=%s' % NEW_VERSION)"
365
+ ]
366
+ },
367
+ {
368
+ "cell_type": "markdown",
369
+ "metadata": {},
370
+ "source": [
371
+ "## Congratulations\n",
372
+ "\n",
373
+ "Release is public now."
374
+ ]
375
+ }
376
+ ],
377
+ "metadata": {
378
+ "kernelspec": {
379
+ "display_name": "Python 3",
380
+ "language": "python",
381
+ "name": "python3"
382
+ },
383
+ "language_info": {
384
+ "codemirror_mode": {
385
+ "name": "ipython",
386
+ "version": 3
387
+ },
388
+ "file_extension": ".py",
389
+ "mimetype": "text/x-python",
390
+ "name": "python",
391
+ "nbconvert_exporter": "python",
392
+ "pygments_lexer": "ipython3",
393
+ "version": "3.6.8"
394
+ }
395
+ },
396
+ "nbformat": 4,
397
+ "nbformat_minor": 2
398
+ }
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'fileutils'
3
+ require "json-schema"
3
4
 
4
5
  describe Apipie::ApipiesController do
5
6
 
@@ -12,37 +13,62 @@ describe Apipie::ApipiesController do
12
13
  end
13
14
 
14
15
  it "succeeds on version details" do
15
- get :index, :version => "2.0"
16
+ get :index, :params => { :version => "2.0" }
16
17
 
17
18
  assert_response :success
18
19
  end
19
20
 
20
21
  it "returns not_found on wrong version" do
21
- get :index, :version => "wrong_version"
22
+ get :index, :params => { :version => "wrong_version" }
22
23
 
23
24
  assert_response :not_found
24
25
  end
25
26
 
26
27
  it "succeeds on resource details" do
27
- get :index, :version => "2.0", :resource => "architectures"
28
+ get :index, :params => { :version => "2.0", :resource => "architectures" }
28
29
 
29
30
  assert_response :success
30
31
  end
31
32
 
32
33
  it "returns not_found on wrong resource" do
33
- get :index, :version => "2.0", :resource => "wrong_resource"
34
+ get :index, :params => { :version => "2.0", :resource => "wrong_resource" }
34
35
 
35
36
  assert_response :not_found
36
37
  end
37
38
 
38
39
  it "succeeds on method details" do
39
- get :index, :version => "2.0", :resource => "architectures", :method => "index"
40
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index" }
40
41
 
41
42
  assert_response :success
42
43
  end
43
44
 
44
45
  it "returns not_found on wrong method" do
45
- get :index, :version => "2.0", :resource => "architectures", :method => "wrong_method"
46
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "wrong_method" }
47
+
48
+ assert_response :not_found
49
+ end
50
+
51
+ it "succeeds on method details with a supported language" do
52
+ allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
53
+
54
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.es" }
55
+
56
+ assert_response :success
57
+ end
58
+
59
+ it "succeeds on method details with the default language" do
60
+ allow(Apipie.configuration).to receive(:default_locale).and_return("en")
61
+ allow(Apipie.configuration).to receive(:languages).and_return([])
62
+
63
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.en" }
64
+
65
+ assert_response :success
66
+ end
67
+
68
+ it "returns not_found on a method with an unsupported language" do
69
+ allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
70
+
71
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.jp" }
46
72
 
47
73
  assert_response :not_found
48
74
  end
@@ -130,6 +156,38 @@ describe Apipie::ApipiesController do
130
156
  end
131
157
  end
132
158
 
159
+ describe "GET index as swagger" do
160
+
161
+ let(:swagger_schema) do
162
+ File.read(File.join(File.dirname(__FILE__),"../lib/swagger/openapi_2_0_schema.json"))
163
+ end
164
+
165
+ it "outputs swagger when format is json and type is swagger" do
166
+ get :index, :params => { :format => "json", :type => "swagger"}
167
+
168
+ assert_response :success
169
+ expect(response.body).to match(/"swagger":"2.0"/)
170
+ # puts response.body
171
+
172
+ expect(JSON::Validator.validate(swagger_schema, response.body)).to be_truthy
173
+ end
174
+
175
+ it "does not output swagger when format is not json even if type is swagger" do
176
+ get :index, :params => { :type => "swagger"}
177
+
178
+ assert_response :success
179
+ expect(response.body).not_to match(/"swagger":"2.0"/)
180
+ end
181
+
182
+ it "does not output swagger when format is json even but type is not swagger" do
183
+ get :index, :params => { :format => "json"}
184
+
185
+ assert_response :success
186
+ expect(response.body).not_to match(/"swagger":"2.0"/)
187
+ end
188
+ end
189
+
190
+
133
191
  describe "authenticate user" do
134
192
  it "authenticate user if an authentication method is setted" do
135
193
  test = false
@@ -183,6 +241,11 @@ describe Apipie::ApipiesController do
183
241
  expect(assigns(:doc)[:resources]["users"][:methods].size).to eq(users_methods - 1)
184
242
  expect(assigns(:doc)[:resources]["twitter_example"][:methods].size).to eq(twitter_example_methods)
185
243
  end
244
+ it "does not allow access to swagger when authorization is set" do
245
+ get :index, :params => { :format => "json", :type => "swagger"}
246
+
247
+ assert_response :forbidden
248
+ end
186
249
  end
187
250
 
188
251
  describe "documentation cache" do
@@ -190,7 +253,7 @@ describe Apipie::ApipiesController do
190
253
  let(:cache_dir) { File.join(Rails.root, "tmp", "apipie-cache") }
191
254
 
192
255
  before do
193
- FileUtils.rm_r(cache_dir) if File.exists?(cache_dir)
256
+ FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
194
257
  FileUtils.mkdir_p(File.join(cache_dir, "apidoc", "v1", "resource"))
195
258
  File.open(File.join(cache_dir, "apidoc", "v1.html"), "w") { |f| f << "apidoc.html cache v1" }
196
259
  File.open(File.join(cache_dir, "apidoc", "v2.html"), "w") { |f| f << "apidoc.html cache v2" }
@@ -209,25 +272,27 @@ describe Apipie::ApipiesController do
209
272
  Apipie.configuration.use_cache = false
210
273
  Apipie.configuration.default_version = @orig_version
211
274
  Apipie.configuration.cache_dir = @orig_cache_dir
212
- # FileUtils.rm_r(cache_dir) if File.exists?(cache_dir)
275
+ # FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
213
276
  end
214
277
 
215
278
  it "uses the file in cache dir instead of generating the content on runtime" do
216
279
  get :index
217
280
  expect(response.body).to eq("apidoc.html cache v1")
218
- get :index, :version => 'v1'
281
+ get :index, :params => { :version => 'v1' }
219
282
  expect(response.body).to eq("apidoc.html cache v1")
220
- get :index, :version => 'v2'
283
+ get :index, :params => { :version => 'v2' }
221
284
  expect(response.body).to eq("apidoc.html cache v2")
222
- get :index, :version => 'v1', :format => "html"
285
+ get :index, :params => { :version => 'v1', :format => "html" }
223
286
  expect(response.body).to eq("apidoc.html cache v1")
224
- get :index, :version => 'v1', :format => "json"
287
+ get :index, :params => { :version => 'v1', :format => "json" }
225
288
  expect(response.body).to eq("apidoc.json cache")
226
- get :index, :version => 'v1', :format => "html", :resource => "resource"
289
+ get :index, :params => { :version => 'v1', :format => "html", :resource => "resource" }
227
290
  expect(response.body).to eq("resource.html cache")
228
- get :index, :version => 'v1', :format => "html", :resource => "resource", :method => "method"
291
+ get :index, :params => { :version => 'v1', :format => "html", :resource => "resource", :method => "method" }
229
292
  expect(response.body).to eq("method.html cache")
230
293
  end
231
294
 
232
295
  end
296
+
297
+
233
298
  end
@@ -8,12 +8,12 @@ describe ConcernsController do
8
8
  end
9
9
 
10
10
  it "should reply to valid request" do
11
- get :show, :id => '5', :session => "secret_hash"
11
+ get :show, :params => { :id => '5' }, :session => { :user_id => "secret_hash" }
12
12
  assert_response :success
13
13
  end
14
14
 
15
15
  it "should pass if required parameter is missing" do
16
- expect { get :show, :id => '5' }.not_to raise_error
16
+ expect { get :show, :params => { :id => '5' } }.not_to raise_error
17
17
  end
18
18
 
19
19
  it "peserved the order of methods being defined in file" do
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe ExtendedController do
4
+
5
+ it 'should include params from both original controller and extending concern' do
6
+ expect(Apipie["extended#create"].params.keys).to eq [:oauth, :user, :admin]
7
+ user_param = Apipie["extended#create"].params[:user]
8
+ expect(user_param.validator.params_ordered.map(&:name)).to eq [:name, :password, :from_concern]
9
+ end
10
+
11
+ it 'should include updated metadata' do
12
+ expect(Apipie['extended#create'].metadata).to eq metadata: 'data'
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe IncludedParamGroupController do
5
+
6
+ let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
7
+
8
+ it "should not error when there is a param_group that is deeply nested in response description" do
9
+ subject = Apipie.get_resource_description(IncludedParamGroupController, Apipie.configuration.default_version)
10
+ expect(subject._methods.keys).to include(:show)
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestEngine::MemesController do
4
+
5
+ describe "#index" do
6
+ it "should have the full mounted path of engine" do
7
+ Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].should eq("/test/memes")
8
+ end
9
+ end
10
+ end