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
data/CHANGELOG.md CHANGED
@@ -1,7 +1,251 @@
1
- ===========
2
1
  Changelog
3
2
  ===========
4
3
 
4
+ Also deleted the `Gemfile` that was now a broken symlink.
5
+ please use `export BUNDLE_GEMFILE='gemfiles/Gemfile.rails61'; bundle exec rspec` to run the test suite
6
+
7
+ ## [v0.9.1](https://github.com/Apipie/apipie-rails/tree/v0.9.1) (2023-01-16)
8
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.0...v0.9.1)
9
+ * [Refactor] Create test cache files under a not version controlled directory [#809](https://github.com/Apipie/apipie-rails/pull/809) (Panos Dalitsouris)
10
+ * [Ruby] Support for Ruby 3.2 [#807](https://github.com/Apipie/apipie-rails/pull/807) (Mathieu Jobin)
11
+ * [Fix] Reverted conditional assignment operators that caused #559 [#806](https://github.com/Apipie/apipie-rails/pull/806) (Nick L. Deltik)
12
+ * [Rubocop] Autocorrect Style/SymbolProc [#793](https://github.com/Apipie/apipie-rails/pull/793) (Rubocop Challenger)
13
+
14
+ ## [v0.9.0](https://github.com/Apipie/apipie-rails/tree/v0.9.0) (2023-01-03)
15
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.8.2...v0.9.0)
16
+ * [Refactor] Move Swagger types and warnings under `/generator` namespace [#803](https://github.com/Apipie/apipie-rails/pull/803) (Panos Dalitsouris)
17
+ * [Refactor] Creates `Apipie::MethodDescription::ApisService` [#805](https://github.com/Apipie/apipie-rails/pull/805) (Panos Dalitsouris)
18
+ * [Refactor] Change output folder to `spec/dummy/tmp/` [#804](https://github.com/Apipie/apipie-rails/pull/804) (Panos Dalitsouris)
19
+ * Fix tiny typo in docs [#798](https://github.com/Apipie/apipie-rails/pull/798) (Erik-B. Ernst)
20
+ * Fix Generated docs.json output [#787](https://github.com/Apipie/apipie-rails/pull/787) (Jeremy Liberman)
21
+ * Rubocop Fixes [#775](https://github.com/Apipie/apipie-rails/pull/775), [#778](https://github.com/Apipie/apipie-rails/pull/778), [#780](https://github.com/Apipie/apipie-rails/pull/780), [#790](https://github.com/Apipie/apipie-rails/pull/790), [#783](https://github.com/Apipie/apipie-rails/pull/783), [#785](https://github.com/Apipie/apipie-rails/pull/785) (RuboCop)
22
+ * Remove/clean up dev dependencies and unused rake tasks [#777](https://github.com/Apipie/apipie-rails/pull/777) (Mathieu Jobin)
23
+ - remove unused rake task
24
+ * Setup Rubocop Challenger [#776](https://github.com/Apipie/apipie-rails/pull/776) (Mathieu Jobin)
25
+
26
+ ## [v0.8.2](https://github.com/Apipie/apipie-rails/tree/v0.8.2) (2022-09-03)
27
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.8.1...v0.8.2)
28
+ * Allow custom validators to opt out of allow_blank behavior [#762](https://github.com/Apipie/apipie-rails/pull/762). (Stephen Hanson)
29
+ * Enforce test coverage, set current 89% as minimum [#764](https://github.com/Apipie/apipie-rails/pull/764). (Mathieu Jobin)
30
+ * Add contributing instructions to readme [#763](https://github.com/Apipie/apipie-rails/pull/763). (Stephen Hanson)
31
+ * Fix readme formatting [#765](https://github.com/Apipie/apipie-rails/pull/765). (Stephen Hanson)
32
+ * Adds expected_type to IntegerValidator example [#769](https://github.com/Apipie/apipie-rails/pull/769). (Jeremy Liberman)
33
+ * Update readme with error handling example [#768](https://github.com/Apipie/apipie-rails/pull/768). (Jesse Eisenberg)
34
+ * Fix scope incorrectly set to nil when a param_group is used inside an array_of_hash and the param_group is in a different module / controller. [#693](https://github.com/Apipie/apipie-rails/pull/693) [#774](https://github.com/Apipie/apipie-rails/pull/774). (Omkar Joshi / Oliver Iyer)
35
+
36
+ ## [v0.8.1](https://github.com/Apipie/apipie-rails/tree/v0.8.1) (2022-05-26)
37
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.8.0...v0.8.1)
38
+ * Remove warning that came back as of [#752](https://github.com/Apipie/apipie-rails/pull/752). [#761](https://github.com/Apipie/apipie-rails/pull/761) (Jorge Santos / Mathieu Jobin)
39
+
40
+ ## [v0.8.0](https://github.com/Apipie/apipie-rails/tree/v0.8.0) (2022-05-24)
41
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.7.2...v0.8.0)
42
+ * Add support for scheme definition in Swagger docs. [#710](https://github.com/Apipie/apipie-rails/pull/710) (Dan Leyden)
43
+ * Add support for Rails 7 [#760](https://github.com/Apipie/apipie-rails/pull/760) (Mathieu Jobin)
44
+ * Clean up code base, removing all trace of unsupported Rails 4.x [#752](https://github.com/Apipie/apipie-rails/pull/752) (Mathieu Jobin)
45
+ * fix: Controller resource set before version [#744](https://github.com/Apipie/apipie-rails/pull/744) (LuukvH)
46
+ * fix: enable swagger generator to add referenced schema for an array of hashes param [#689](https://github.com/Apipie/apipie-rails/pull/689) (Francis San Juan)
47
+
48
+ ## [v0.7.2](https://github.com/Apipie/apipie-rails/tree/v0.7.2) (2022-04-19)
49
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.7.1...v0.7.2)
50
+ * Added Korean locale. [#480](https://github.com/Apipie/apipie-rails/pull/480) (Jaehyun Shin ) [#757](https://github.com/Apipie/apipie-rails/pull/757) (Jorge Santos)
51
+ * `Security` Upgraded Bootstrap from 2.0.2 to 2.3.2, JQuery from 1.11.3 to 1.12.4 [#708](https://github.com/Apipie/apipie-rails/pull/708) (Nicolas Waissbluth)
52
+ * Fix ruby2 keyword argument warning [#756](https://github.com/Apipie/apipie-rails/pull/756) (Jorge Santos)
53
+
54
+ ## [v0.7.1](https://github.com/Apipie/apipie-rails/tree/v0.7.1) (2022-04-06)
55
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.7.0...v0.7.1)
56
+ * Skip extra parameters while validating the keys. [#690](https://github.com/Apipie/apipie-rails/pull/690) (Omkar Joshi)
57
+ * Support defining security mechanisms for Swagger [#711](https://github.com/Apipie/apipie-rails/pull/711) (Dan Leyden)
58
+ * Update boolean handling of false [#749](https://github.com/Apipie/apipie-rails/pull/749) (Colin Bruce)
59
+
60
+ Note: Up until and including v0.6.x, apipie-rails was silently ignoring allow_blank == false on String validation.
61
+ when allow_blank is not specified, it default to false. to allow blank strings, you must specify it as a parameter.
62
+
63
+ Alternatively, if you want to revert to the previous behavior, you can set this configuration option:
64
+ `Apipie.configuration.ignore_allow_blank_false = true`.
65
+
66
+ ## [v0.7.0](https://github.com/Apipie/apipie-rails/tree/v0.7.0) (2022-03-30)
67
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.6.0...v0.7.0)
68
+ * ArgumentError (invalid byte sequence in UTF-8) [#746](https://github.com/Apipie/apipie-rails/pull/746) (David Milanese)
69
+ * Fix allow_blank does not work [#733](https://github.com/Apipie/apipie-rails/pull/733) (CHEN Song)
70
+ * Fix schema generation for param descriptions using the array validator in option [#732](https://github.com/Apipie/apipie-rails/pull/732) (Frank Hock)
71
+ * Remove support for Rails 4 and Ruby <= 2.5 [#747](https://github.com/Apipie/apipie-rails/pull/747) (Mathieu Jobin)
72
+
73
+ ## [v0.6.0](https://github.com/Apipie/apipie-rails/tree/v0.6.0) (2022-03-29)
74
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.20...v0.6.0)
75
+ * Ruby 3.0 fixes [#716](https://github.com/Apipie/apipie-rails/pull/716) (hank-spokeo)
76
+ * only depends on actionpack and activesupport [#741](https://github.com/Apipie/apipie-rails/pull/741) (Mathieu Jobin)
77
+ * language fix, fallback to default locale [#726](https://github.com/Apipie/apipie-rails/pull/726) (Alex Coomans)
78
+
79
+ ## [v0.5.20](https://github.com/Apipie/apipie-rails/tree/v0.5.20) (2022-03-16)
80
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.19...v0.5.20)
81
+ * Update rel-eng (Oleh Fedorenko)
82
+ * Deprecate travis, run tests on github actions [#740](https://github.com/Apipie/apipie-rails/pull/740) (Mathieu Jobin)
83
+ * Update validator.rb [#739](https://github.com/Apipie/apipie-rails/pull/739) (Dmytro Budnyk)
84
+ * Fix wrong number of arguments for recorder#process [#725](https://github.com/Apipie/apipie-rails/pull/725) (rob mathews)
85
+ * Change "an" to "a" [#723](https://github.com/Apipie/apipie-rails/pull/723) (Naokimi)
86
+
87
+ ## [v0.5.19](https://github.com/Apipie/apipie-rails/tree/v0.5.19) (2021-07-25)
88
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.18...v0.5.19)
89
+ * Add rel-eng notebook (Oleh Fedorenko)
90
+ * Correct the word parâmentros for brazilian portuguese [#687](https://github.com/Apipie/apipie-rails/pull/687) (Diego Noronha)
91
+ * Fix depreciated file.exists. [#721](https://github.com/Apipie/apipie-rails/pull/721) (Diane Delallée)
92
+ * Fix typo in changelog [#703](https://github.com/Apipie/apipie-rails/pull/703) (Pavel Rodionov)
93
+ * Add rails 6.1 support in doc generation [#702](https://github.com/Apipie/apipie-rails/pull/702) (andrew-newell)
94
+
95
+
96
+ [v0.5.18](https://github.com/Apipie/apipie-rails/tree/v0.5.18) (2020-05-20)
97
+ --------
98
+
99
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.17...v0.5.18)
100
+
101
+ - Optional rdoc dependency with lazyload [\#683](https://github.com/Apipie/apipie-rails/pull/683) ([vkrizan](https://github.com/vkrizan))
102
+
103
+ [v0.5.17](https://github.com/Apipie/apipie-rails/tree/v0.5.17) (2020-01-20)
104
+ --------
105
+
106
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.16...v0.5.17)
107
+
108
+ - Allows update metadata for methods [\#667](https://github.com/Apipie/apipie-rails/pull/667) ([speckins](https://github.com/speckins))
109
+
110
+ [v0.5.16](https://github.com/Apipie/apipie-rails/tree/v0.5.16) (2019-05-22)
111
+ --------
112
+
113
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.15...v0.5.16)
114
+
115
+ - Load file directly instead of using Rails constant [\#665](https://github.com/Apipie/apipie-rails/pull/665) ([speckins](https://github.com/speckins))
116
+
117
+ [v0.5.15](https://github.com/Apipie/apipie-rails/tree/v0.5.15) (2019-01-03)
118
+ --------
119
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.14...v0.5.15)
120
+
121
+
122
+ - Fix authorization of resources [\#655](https://github.com/Apipie/apipie-rails/pull/655) ([NielsKSchjoedt](https://github.com/NielsKSchjoedt))
123
+ - Use configured value when swagger\_content\_type\_input argument is not passed [\#648](https://github.com/Apipie/apipie-rails/pull/648) ([nullnull](https://github.com/nullnull))
124
+ - Fix "ArgumentError: string contains null byte" on malformed stings [\#477](https://github.com/Apipie/apipie-rails/pull/477) ([avokhmin](https://github.com/avokhmin))
125
+
126
+ v0.5.14
127
+ -------
128
+ - HTML escape validator values [\#645](https://github.com/Apipie/apipie-rails/pull/645) ([ekohl](https://github.com/ekohl))
129
+ - Support for adding new params via `update\_api` [\#642](https://github.com/Apipie/apipie-rails/pull/642) ([iNecas](https://github.com/iNecas))
130
+ - Allow the "null" JSON string to be used as a parameter in Apipie spec examples \(`show\_in\_doc`\) [\#641](https://github.com/Apipie/apipie-rails/pull/641) ([enrique-guillen](https://github.com/enrique-guillen))
131
+ - Fix examples recording for specific cases [\#640](https://github.com/Apipie/apipie-rails/pull/640) ([Marri](https://github.com/Marri))
132
+ - Add description section to response [\#639](https://github.com/Apipie/apipie-rails/pull/639) ([X1ting](https://github.com/X1ting))
133
+
134
+
135
+ v0.5.13
136
+ -------
137
+ - Fix swagger generation if a controller's parent doesn't define a resource_description [\#637](https://github.com/Apipie/apipie-rails/pull/637) ([enrique-guillen](https://github.com/enrique-guillen))
138
+
139
+ v0.5.12
140
+ -------
141
+ - Fix returns displaying [\#635](https://github.com/Apipie/apipie-rails/pull/635) ([X1ting](https://github.com/X1ting))
142
+
143
+ v0.5.11
144
+ -------
145
+
146
+ - Adds swagger tags in swagger output [\#634](https://github.com/Apipie/apipie-rails/pull/634) ([enrique-guillen](https://github.com/enrique-guillen))
147
+ - Generate swagger with headers [\#630](https://github.com/Apipie/apipie-rails/pull/630) ([Uysim](https://github.com/Uysim))
148
+ - Fix examples not being generated for Rails < 5.0.0 [\#633](https://github.com/Apipie/apipie-rails/pull/633) ([RomanKapitonov](https://github.com/RomanKapitonov))
149
+
150
+ v0.5.10
151
+ ------
152
+
153
+ - Support response validation [\#626](https://github.com/Apipie/apipie-rails/pull/626) ([COzero](https://github.com/COzero))
154
+
155
+ v0.5.9
156
+ ------
157
+
158
+ - Support response validation [\#619](https://github.com/Apipie/apipie-rails/pull/619) ([abenari](https://github.com/abenari))
159
+ - Expect :number to have type 'numeric' [\#614](https://github.com/Apipie/apipie-rails/pull/614) ([akofink](https://github.com/akofink))
160
+ - New validator - DecimalValidator [\#431](https://github.com/Apipie/apipie-rails/pull/431) ([kiddrew](https://github.com/kiddrew))
161
+
162
+
163
+ v0.5.8
164
+ ------
165
+
166
+ - Swagger json includes apipie's description as swagger's description [\#615](https://github.com/Apipie/apipie-rails/pull/615) ([gogotanaka](https://github.com/gogotanaka))
167
+ - Fix api! issue by using underscore when appending `controller` to the default controller string [\#613](https://github.com/Apipie/apipie-rails/pull/613) ([kevinmarx](https://github.com/kevinmarx))
168
+ - Possibility to compress examples [\#600](https://github.com/Apipie/apipie-rails/pull/600) ([Haniyya](https://github.com/Haniyya))
169
+ - Possibility to describe responses [\#588](https://github.com/Apipie/apipie-rails/pull/588) ([elasti-ron](https://github.com/elasti-ron))
170
+
171
+ v0.5.7
172
+ ------
173
+
174
+ - Fix example recording with Rails 5 [\#607](https://github.com/Apipie/apipie-rails/pull/607) ([adamruzicka](https://github.com/adamruzicka))
175
+ - Use SHA1 instead of MD5 to enable using APIPIE at FIPS-enables systems [\#605](https://github.com/Apipie/apipie-rails/pull/605) ([iNecas](https://github.com/iNecas))
176
+ - Replaced String\#constantize with String\#safe\_constantize so apipie won't break on a missing constant [\#575](https://github.com/Apipie/apipie-rails/pull/575) ([Haniyya](https://github.com/Haniyya))
177
+ - Added Swagger generation [\#569](https://github.com/Apipie/apipie-rails/pull/569) ([elasti-ron](https://github.com/elasti-ron))
178
+
179
+ v0.5.6
180
+ ------
181
+
182
+ - Prevent missing translation span in title [\#571](https://github.com/Apipie/apipie-rails/pull/571) ([mbacovsky](https://github.com/mbacovsky))
183
+ - Clean up old generator code for CLI [\#572](https://github.com/Apipie/apipie-rails/pull/572) ([voxik](https://github.com/voxik))
184
+ - Added french locale [\#568](https://github.com/Apipie/apipie-rails/pull/568) ([giglemad](https://github.com/giglemad))
185
+
186
+ v0.5.5
187
+ ------
188
+
189
+ - prevent lang in url when config.translate is false [\#562](https://github.com/Apipie/apipie-rails/pull/562) ([markmoser](https://github.com/markmoser))
190
+ - Allow for resource-level deprecations [\#567](https://github.com/Apipie/apipie-rails/pull/567) ([cross-p6](https://github.com/cross-p6))
191
+
192
+ v0.5.4
193
+ ------
194
+
195
+ - Constantize controller class before calling superclass [\#558](https://github.com/Apipie/apipie-rails/pull/558) ([ydkn](https://github.com/ydkn))
196
+
197
+ v0.5.3
198
+ ------
199
+
200
+ - Fix reloading when extending the apidoc from concern [\#557](https://github.com/Apipie/apipie-rails/pull/557) ([iNecas](https://github.com/iNecas))
201
+ - Fix example recording when using send\_file [\#504](https://github.com/Apipie/apipie-rails/pull/504) ([tdeo](https://github.com/tdeo))
202
+
203
+ v0.5.2
204
+ ------
205
+
206
+ - A way to extend an exiting API via concern [\#554](https://github.com/Apipie/apipie-rails/pull/554) ([iNecas](https://github.com/iNecas))
207
+ - Fallback to apipie views when application override isn't present [\#552](https://github.com/Apipie/apipie-rails/pull/552) ([tstrachota](https://github.com/tstrachota))
208
+ - Updated setting default locale for api documentation [\#543](https://github.com/Apipie/apipie-rails/pull/543) ([DmitryKK](https://github.com/DmitryKK))
209
+
210
+ v0.5.1
211
+ ------
212
+
213
+ - Use AD::Reloader on Rails 4, app.reloader only on Rails 5+ [\#541](https://github.com/Apipie/apipie-rails/pull/541) ([domcleal](https://github.com/domcleal))
214
+ - Recognize Rack Symbols as Status Codes [\#468](https://github.com/Apipie/apipie-rails/pull/468)([alex-tan](https://github.com/alex-tan))
215
+
216
+ v0.5.0
217
+ ------
218
+
219
+ - Fix Rails 5.1 deprecations [\#530](https://github.com/Apipie/apipie-rails/pull/530) ([@Onumis](https://github.com/Onumis) [@sedx](https://github.com/sedx))
220
+ - **This release is no longer compatible with Ruby 1.9.x**
221
+ - Do not mutate strings passed as config options, fixes \#461 [\#537](https://github.com/Apipie/apipie-rails/pull/537) ([samphilipd](https://github.com/samphilipd))
222
+ - Added recursion for documentation, fixed bug in examples with paperclip [\#531](https://github.com/Apipie/apipie-rails/pull/531) ([blddmnd](https://github.com/blddmnd))
223
+ - Added locales/ja.yml for Japanese [\#529](https://github.com/Apipie/apipie-rails/pull/529) ([kikuchi0808](https://github.com/kikuchi0808))
224
+
225
+
226
+ v0.4.0
227
+ ------
228
+
229
+ - Rails 5 compatibility [\#527](https://github.com/Apipie/apipie-rails/pull/527) ([iNecas](https://github.com/iNecas)) [\#420](https://github.com/Apipie/apipie-rails/pull/420) ([buren](https://github.com/buren)) [\#473](https://github.com/Apipie/apipie-rails/pull/473)([domcleal](https://github.com/domcleal))
230
+ - **This release is no longer compatible with Rails 3.x**
231
+ - Include delete request parmeters in generated documentation [\#524](https://github.com/Apipie/apipie-rails/pull/524) ([johnnaegle](https://github.com/johnnaegle))
232
+ - Allow a blank, not just nil, base\_url. [\#521](https://github.com/Apipie/apipie-rails/pull/521) ([johnnaegle](https://github.com/johnnaegle))
233
+ - Adds allow\_blank option [\#508](https://github.com/Apipie/apipie-rails/pull/508) ([MrLeebo](https://github.com/MrLeebo))
234
+ - Boolean Validator uses \<code\> instead of ' [\#502](https://github.com/Apipie/apipie-rails/pull/502) ([berfarah](https://github.com/berfarah))
235
+ - Fix type validator message [\#501](https://github.com/Apipie/apipie-rails/pull/501) ([cindygu-itglue](https://github.com/cindygu-itglue))
236
+ - Add IT locale [\#496](https://github.com/Apipie/apipie-rails/pull/496) ([alepore](https://github.com/alepore))
237
+ - Fix small typo on dsl\_definition data init [\#494](https://github.com/Apipie/apipie-rails/pull/494) ([begault](https://github.com/begault))
238
+ - Localize app info message [\#491](https://github.com/Apipie/apipie-rails/pull/491) ([belousovAV](https://github.com/belousovAV))
239
+ - Fix travis build [\#489](https://github.com/Apipie/apipie-rails/pull/489) ([mtparet](https://github.com/mtparet))
240
+ - Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
241
+ - Allow layouts to be overridable. Fixes a regression introduced in \#425. [\#447](https://github.com/Apipie/apipie-rails/pull/447) ([nilsojes](https://github.com/nilsojes))
242
+
243
+ v0.3.7
244
+ ------
245
+
246
+ - Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
247
+ - Allow layouts to be overridable. Fixes a regression introduced in \#425. [\#447](https://github.com/Apipie/apipie-rails/pull/447) ([nilseriksson](https://github.com/nilseriksson))
248
+
5
249
  v0.3.6
6
250
  ------
7
251
 
@@ -70,7 +314,7 @@ v0.3.2
70
314
  v0.3.1
71
315
  ------
72
316
 
73
- * Support for ``api!`` keyword in concerns
317
+ * Support for ``api!`` keyword in concerns
74
318
  [#322](https://github.com/Apipie/apipie-rails/pull/322) [@iNecas][]
75
319
  * More explicit ordering of the static dispatcher middleware
76
320
  [#315](https://github.com/Apipie/apipie-rails/pull/315) [@iNecas][]
@@ -0,0 +1,244 @@
1
+ # Proposal for supporting response descriptions in Apipie
2
+
3
+ ## Rationale
4
+
5
+ Swagger allows API authors to describe the structure of objects returned by REST API calls.
6
+ Client authors and code generators can use such descriptions for various purposes, such as verification,
7
+ autocompletion, and so forth.
8
+
9
+ The current Apipie DSL allows API authors to indicate returned error codes (using the `error` keyword),
10
+ but does not support descriptions of returned data objects. As such, swagger files
11
+ generated from the DSL do not include those, and are somewhat limited in their value.
12
+
13
+ This document proposes a minimalistic approach to extending the Apipie DSL to allow description of response
14
+ objects, and including those descriptions in generated swagger files.
15
+
16
+ ## Design Objectives
17
+
18
+ * Full backward compatibility with the existing DSL
19
+ * Minimal implementation effort
20
+ * Enough expressiveness to support common use cases
21
+ * Optional integration of the DSL with advanced JSON generators (such as Grape-Entity)
22
+ * Allowing developers to easily verify that actual responses match the response declarations
23
+
24
+ ## Approach
25
+
26
+ #### Add a `returns` keyword to the DSL, based on the existing `error` keyword
27
+
28
+ Currently, returned error codes are indicated using the `error` keyword, for example:
29
+ ```ruby
30
+ api :GET, "/users/:id", "Show user profile"
31
+ error :code => 401, :desc => "Unauthorized"
32
+ ```
33
+
34
+ The proposed approach is to add a `returns` keyword, that has the following syntax:
35
+ ```ruby
36
+ returns <type-identifier> [, :code => <number>] [, :desc => <response-description>]
37
+ ```
38
+
39
+ For example:
40
+ ```ruby
41
+ api :GET, "/users/:id", "Show user profile"
42
+ error :code => 401, :desc => "Unauthorized"
43
+ returns :SomeTypeIdentifier # :code is not specified, so it is assumed to be 200
44
+ ```
45
+
46
+
47
+ #### Leverage `param_group` for response object description
48
+
49
+ Apipie currently has a mechanism for describing complex objects using the `param_group` keyword.
50
+ It seems reasonable to leverage this mechanism as the basis of the response object description mechanism,
51
+ so that the `<type-identifier>` in the `returns` keyword will be the name of a param_group.
52
+
53
+ For example:
54
+ ```ruby
55
+ def_param_group :user do
56
+ param :user, Hash, :desc => "User info", :required => true, :action_aware => true do
57
+ param_group :credentials
58
+ param :membership, ["standard","premium"], :desc => "User membership", :allow_nil => false
59
+ end
60
+ end
61
+
62
+ api :GET, "/users/:id", "Get user record"
63
+ returns :user, "the requested record"
64
+ error :code => 404, :desc => "no user with the specified id"
65
+ ```
66
+
67
+ Implementation of this DSL extension would involve - as part of the implementation of the `returns` keyword -
68
+ the generation of a Apipie::ParamDescription object that has a Hash validator pointing to the param_group block.
69
+
70
+ #### Extend action-aware functionality to include 'response-only' parameters
71
+
72
+ In CRUD operations, it is common for `param_group` input definitions to be very similar to the
73
+ output of the API, with the exception of a very small number of fields (such as the `:id` field
74
+ which usually appears in the response, but is not described in the `param_group` because it is passed as a
75
+ path parameter).
76
+
77
+ To allow reuse of the `param_group`, it would be useful to its definition to describe parameters that are not passed
78
+ in the request but are returned in the response. This would be implementing by extending the DSL to
79
+ support a `:only_in => :response` option on `param` definitions. Similarly, params could be defined to be
80
+ `:only_in => :request` to indicate that they will not be included in the response.
81
+
82
+ For example:
83
+ ```ruby
84
+ # in the following group, the :id param is ignored in requests, but included in responses
85
+ def_param_group :user do
86
+ param :user, Hash, :desc => "User info", :required => true, :action_aware => true do
87
+ param :id, Integer, :only_in => :response
88
+ param :requested_id, Integer, :only_in => :request
89
+ param_group :credentials
90
+ param :membership, ["standard","premium"], :desc => "User membership", :allow_nil => false
91
+ end
92
+ end
93
+
94
+ api :GET, "/users/:id", "Get user record"
95
+ returns :user, :desc => "the requested record" # includes the :id field, because this is a response
96
+ error :code => 404, :desc => "no user with the specified id"
97
+ ```
98
+
99
+
100
+ #### Support `:array_of => <param_group-name>` in the `returns` keyword
101
+
102
+ Very often, a REST API call returns an array of some previously-defined object
103
+ (the most common example an `index` operation that returns an array of the same entity returned by a `show` request),
104
+ and it would be tedious to have to define a separate `param_group` for each one.
105
+
106
+ For added convenience, the `returns` keyword will also support an `:array_of =>` construct
107
+ to specify that an API call returns an array of some object type.
108
+
109
+ For example:
110
+ ```ruby
111
+ api :GET, "/users", "Get all user records"
112
+ returns :array_of => :user, :desc => "the requested user records"
113
+
114
+ api :GET, "/user/:id", "Get a single user record"
115
+ returns :user, :desc => "the requested user record"
116
+ ```
117
+
118
+ #### Integration with advanced JSON generators using an [adapter](https://en.wikipedia.org/wiki/Adapter_pattern) to `param_group`
119
+
120
+ While it makes sense for the sake of simplicity to leverage the `param_group` construct to describe
121
+ returned objects, it is likely that many developers will prefer to unify the
122
+ description of the response with the actual generation of the JSON.
123
+
124
+ Some JSON-generation libraries, such as [Grape-Entity](https://github.com/ruby-grape/grape-entity),
125
+ provide a declarative interface for describing an object model, allowing both runtime
126
+ generation of the response, as well as the ability to traverse the description to auto-generate
127
+ documentation.
128
+
129
+ Such libraries could be integrated with Apipie using adapters that wrap the library-specific
130
+ object description and expose an API that includes a `params_ordered` method that behaves in a
131
+ similar manner to [`Apipie::HashValidator.params_ordered`](https://github.com/Apipie/apipie-rails/blob/cfb42198bc39b5b30d953ba5a8b523bafdb4f897/lib/apipie/validator.rb#L315).
132
+ Such an adapter would make it possible to pass an externally-defined entity to the `returns` keyword
133
+ as if it were a `param_group`.
134
+
135
+ Such adapters can be created easily by having a class respond to `#describe_own_properties`
136
+ with an array of property description objects. When such a class is specified as the
137
+ parameter to a `returns` declaration, Apipie would query the class for its properties
138
+ by calling `<Class>#describe_own_properties`.
139
+
140
+ For example:
141
+ ```ruby
142
+ # here is a class that can describe itself to Apipie
143
+ class Animal
144
+ def self.describe_own_properties
145
+ [
146
+ Apipie::prop(:id, Integer, {:description => 'Name of pet', :required => false}),
147
+ Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => ["dog", "cat", "iguana", "kangaroo"]}),
148
+ Apipie::additional_properties(false)
149
+ ]
150
+ end
151
+
152
+ attr_accessor :id
153
+ attr_accessor :animal_type
154
+ end
155
+
156
+ # Here is an API defined as returning Animal objects.
157
+ # Apipie creates an internal adapter by querying Animal#describe_own_properties
158
+ api :GET, "/animals", "Get all records"
159
+ returns :array_of => Animal, :desc => "the requested records"
160
+ ```
161
+
162
+ The `#describe_own_properties` mechanism can also be used with reflection so that a
163
+ class would query its own properties and populate the response to `#describe_own_properties`
164
+ automatically. See [this gist](https://gist.github.com/elasti-ron/ac145b2c85547487ca33e5216a69f527)
165
+ for an example of how Grape::Entity classes can automatically describe itself to Apipie
166
+
167
+ #### Response validation
168
+
169
+ The swagger definitions created by Apipie can be used to auto-generate clients that access the
170
+ described APIs. Those clients will break if the responses returned from the API do not match
171
+ the declarations. As such, it is very important to include unit tests that validate the actual
172
+ responses against the swagger definitions.
173
+
174
+ The ~~proposed~~ implemented mechanism provides two ways to include such validations in RSpec unit tests:
175
+ manual (using an RSpec matcher) and automated (by injecting a test into the http operations 'get', 'post',
176
+ raising an error if there is no match).
177
+
178
+ Example of the manual mechanism:
179
+
180
+ ```ruby
181
+ require 'apipie/rspec/response_validation_helper'
182
+
183
+ RSpec.describe MyController, :type => :controller, :show_in_doc => true do
184
+
185
+ describe "GET stuff with response validation" do
186
+ render_views # this makes sure the 'get' operation will actually
187
+ # return the rendered view even though this is a Controller spec
188
+
189
+ it "does something" do
190
+ response = get :index, {format: :json}
191
+
192
+ # the following expectation will fail if the returned object
193
+ # does not match the 'returns' declaration in the Controller,
194
+ # or if there is no 'returns' declaration for the returned
195
+ # HTTP status code
196
+ expect(response).to match_declared_responses
197
+ end
198
+ end
199
+ ```
200
+
201
+
202
+ Example of the automated mechanism:
203
+ ```ruby
204
+ require 'apipie/rspec/response_validation_helper'
205
+
206
+ RSpec.describe MyController, :type => :controller, :show_in_doc => true do
207
+
208
+ describe "GET stuff with response validation" do
209
+ render_views
210
+ auto_validate_rendered_views
211
+
212
+ it "does something" do
213
+ get :index, {format: :json}
214
+ end
215
+ it "does something else" do
216
+ get :another_index, {format: :json}
217
+ end
218
+ end
219
+
220
+ describe "GET stuff without response validation" do
221
+ it "does something" do
222
+ get :index, {format: :json}
223
+ end
224
+ it "does something else" do
225
+ get :another_index, {format: :json}
226
+ end
227
+ end
228
+ ```
229
+
230
+ Explanation of the implementation approach:
231
+
232
+ The Apipie Swagger Generator is enhanced to allow extraction of the JSON schema of the response object
233
+ for any controller#action[http-status]. When validation is required, the validator receives the
234
+ actual response object (along with information about the controller, action and http status code),
235
+ queries the swagger generator to get the schema, and uses the json-schema validator (gem) to validate
236
+ one against the other.
237
+
238
+ Note that there is a slight complication here: while supported by JSON-shema, the Swagger 2.0
239
+ specification does not support a mechanism to declare that fields in the response could be null.
240
+ As such, for a response that contains `null` fields, if the exact same schema used in the swagger def
241
+ is passed to the json-schema validator, the validation fails. To work around this issue, when asked
242
+ to provide the schema for the purpose of response validation (i.e., not for inclusion in the swagger),
243
+ the Apipie Swagger Generator creates a slightly modified schema which declares null values to be valid.
244
+