apipie-rails 0.5.19 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +31 -0
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.github/workflows/rubocop.yml +18 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +128 -0
  7. data/.rubocop_todo.yml +2056 -0
  8. data/.vscode/settings.json +3 -0
  9. data/CHANGELOG.md +161 -0
  10. data/Gemfile +20 -0
  11. data/README.rst +117 -23
  12. data/Rakefile +0 -5
  13. data/apipie-rails.gemspec +18 -9
  14. data/app/controllers/apipie/apipies_controller.rb +14 -29
  15. data/app/helpers/apipie_helper.rb +1 -1
  16. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  17. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  18. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  19. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  20. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  21. data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
  22. data/app/views/apipie/apipies/_params.html.erb +7 -1
  23. data/config/locales/en.yml +8 -0
  24. data/config/locales/ko.yml +31 -0
  25. data/gemfiles/Gemfile.tools +9 -0
  26. data/lib/apipie/apipie_module.rb +7 -7
  27. data/lib/apipie/application.rb +132 -97
  28. data/lib/apipie/configuration.rb +43 -33
  29. data/lib/apipie/dsl_definition.rb +44 -33
  30. data/lib/apipie/error_description.rb +3 -3
  31. data/lib/apipie/errors.rb +17 -17
  32. data/lib/apipie/extractor/collector.rb +5 -6
  33. data/lib/apipie/extractor/recorder.rb +35 -8
  34. data/lib/apipie/extractor/writer.rb +15 -15
  35. data/lib/apipie/extractor.rb +6 -9
  36. data/lib/apipie/generator/config.rb +12 -0
  37. data/lib/apipie/generator/generator.rb +2 -0
  38. data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
  39. data/lib/apipie/generator/swagger/config.rb +80 -0
  40. data/lib/apipie/generator/swagger/context.rb +38 -0
  41. data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
  42. data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
  43. data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
  44. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
  45. data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
  46. data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
  47. data/lib/apipie/generator/swagger/method_description.rb +2 -0
  48. data/lib/apipie/generator/swagger/operation_id.rb +51 -0
  49. data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
  50. data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
  51. data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
  52. data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
  53. data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
  54. data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
  55. data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
  56. data/lib/apipie/generator/swagger/param_description/type.rb +128 -0
  57. data/lib/apipie/generator/swagger/param_description.rb +18 -0
  58. data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
  59. data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
  60. data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
  61. data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
  62. data/lib/apipie/generator/swagger/schema.rb +63 -0
  63. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  64. data/lib/apipie/generator/swagger/type.rb +16 -0
  65. data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
  66. data/lib/apipie/generator/swagger/warning.rb +74 -0
  67. data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
  68. data/lib/apipie/helpers.rb +3 -3
  69. data/lib/apipie/markup.rb +9 -8
  70. data/lib/apipie/method_description/api.rb +12 -0
  71. data/lib/apipie/method_description/apis_service.rb +82 -0
  72. data/lib/apipie/method_description.rb +12 -56
  73. data/lib/apipie/param_description/deprecation.rb +24 -0
  74. data/lib/apipie/param_description.rb +57 -24
  75. data/lib/apipie/resource_description.rb +42 -14
  76. data/lib/apipie/response_description.rb +3 -3
  77. data/lib/apipie/response_description_adapter.rb +12 -10
  78. data/lib/apipie/routing.rb +1 -1
  79. data/lib/apipie/rspec/response_validation_helper.rb +3 -3
  80. data/lib/apipie/static_dispatcher.rb +10 -2
  81. data/lib/apipie/swagger_generator.rb +28 -691
  82. data/lib/apipie/validator.rb +41 -11
  83. data/lib/apipie/version.rb +1 -1
  84. data/lib/apipie-rails.rb +36 -5
  85. data/lib/generators/apipie/install/install_generator.rb +1 -1
  86. data/lib/generators/apipie/views_generator.rb +1 -1
  87. data/lib/tasks/apipie.rake +37 -32
  88. data/rel-eng/gem_release.ipynb +41 -9
  89. data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
  90. data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
  91. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
  92. data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
  93. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  94. data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
  95. data/spec/controllers/users_controller_spec.rb +47 -6
  96. data/spec/dummy/Rakefile +1 -1
  97. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
  98. data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
  99. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
  100. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
  101. data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
  102. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  103. data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
  104. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  105. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  106. data/spec/dummy/app/controllers/pets_controller.rb +5 -5
  107. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  108. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
  109. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  110. data/spec/dummy/app/controllers/users_controller.rb +17 -5
  111. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  112. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  113. data/spec/dummy/config/application.rb +2 -5
  114. data/spec/dummy/config/boot.rb +2 -2
  115. data/spec/dummy/config/environment.rb +1 -1
  116. data/spec/dummy/config/environments/development.rb +0 -3
  117. data/spec/dummy/config/environments/production.rb +0 -3
  118. data/spec/dummy/config/environments/test.rb +0 -5
  119. data/spec/dummy/config/initializers/apipie.rb +2 -2
  120. data/spec/dummy/config/routes.rb +8 -0
  121. data/spec/dummy/config.ru +1 -1
  122. data/spec/dummy/script/rails +2 -2
  123. data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
  124. data/spec/lib/apipie/application_spec.rb +62 -0
  125. data/spec/lib/apipie/configuration_spec.rb +38 -0
  126. data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
  127. data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
  128. data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
  129. data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
  130. data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
  131. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  132. data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
  133. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
  134. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  135. data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
  136. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
  137. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
  138. data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
  139. data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
  140. data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
  141. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
  142. data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
  143. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  144. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  145. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  146. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  147. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  148. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
  149. data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
  150. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
  151. data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
  152. data/spec/lib/apipie/method_description_spec.rb +133 -0
  153. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  154. data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
  155. data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
  156. data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
  157. data/spec/lib/apipie/resource_description_spec.rb +91 -0
  158. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  159. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  160. data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
  161. data/spec/lib/rake_spec.rb +3 -5
  162. data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
  163. data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
  164. data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
  165. data/spec/lib/validators/array_validator_spec.rb +1 -1
  166. data/spec/spec_helper.rb +10 -32
  167. data/spec/support/custom_bool_validator.rb +17 -0
  168. data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
  169. metadata +173 -125
  170. data/.travis.yml +0 -41
  171. data/Gemfile +0 -1
  172. data/Gemfile.rails41 +0 -7
  173. data/Gemfile.rails42 +0 -14
  174. data/Gemfile.rails50 +0 -9
  175. data/Gemfile.rails51 +0 -9
  176. data/Gemfile.rails60 +0 -10
  177. data/Gemfile.rails61 +0 -10
  178. data/spec/lib/application_spec.rb +0 -49
  179. data/spec/lib/method_description_spec.rb +0 -98
  180. data/spec/lib/resource_description_spec.rb +0 -48
  181. /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -5,100 +5,94 @@ require 'apipie/rspec/response_validation_helper'
5
5
  require "json-schema"
6
6
 
7
7
  RSpec.describe PetsController, :type => :controller do
8
- before :each do
9
- Apipie.configuration.swagger_allow_additional_properties_in_response = false
10
- end
11
-
12
8
  it "does not raise error when rendered output matches the described response" do
13
- response = get :return_and_validate_expected_response, {format: :json}
9
+ response = get :return_and_validate_expected_response, format: :json
14
10
  expect(response).to match_declared_responses
15
11
  end
16
12
 
17
13
  it "does not raise error when rendered output (array) matches the described response" do
18
- response = get :return_and_validate_expected_array_response, {format: :json}
14
+ response = get :return_and_validate_expected_array_response, format: :json
19
15
  expect(response).to match_declared_responses
20
16
  end
21
17
 
22
18
  it "does not raises error when rendered output includes null in the response" do
23
- response = get :return_and_validate_expected_response_with_null, {format: :json}
19
+ response = get :return_and_validate_expected_response_with_null, format: :json
24
20
  expect(response).to match_declared_responses
25
21
  end
26
22
 
27
23
  it "does not raise error when rendered output includes null (instead of an object) in the response" do
28
- response = get :return_and_validate_expected_response_with_null_object, {format: :json}
24
+ response = get :return_and_validate_expected_response_with_null_object, format: :json
29
25
  expect(response).to match_declared_responses
30
26
  end
31
27
 
32
28
  it "raises error when a response field has the wrong type" do
33
- response = get :return_and_validate_type_mismatch, {format: :json}
29
+ response = get :return_and_validate_type_mismatch, format: :json
34
30
  expect(response).not_to match_declared_responses
35
31
  end
36
32
 
37
33
  it "raises error when a response has a missing field" do
38
- response = get :return_and_validate_missing_field, {format: :json}
34
+ response = get :return_and_validate_missing_field, format: :json
39
35
  expect(response).not_to match_declared_responses
40
36
  end
41
37
 
42
- it "raises error when a response has an extra property and 'swagger_allow_additional_properties_in_response' is false" do
43
- response = get :return_and_validate_extra_property, {format: :json}
38
+ it "raises error when a response has an extra property and 'swagger.allow_additional_properties_in_response' is false" do
39
+ response = get :return_and_validate_extra_property, format: :json
44
40
  expect(response).not_to match_declared_responses
45
41
  end
46
42
 
47
43
  it "raises error when a response has is array instead of object" do
48
44
  # note: this action returns HTTP 201, not HTTP 200!
49
- response = get :return_and_validate_unexpected_array_response, {format: :json}
45
+ response = get :return_and_validate_unexpected_array_response, format: :json
50
46
  expect(response).not_to match_declared_responses
51
47
  end
52
48
 
53
- it "does not raise error when a response has an extra property and 'swagger_allow_additional_properties_in_response' is true" do
54
- Apipie.configuration.swagger_allow_additional_properties_in_response = true
55
- response = get :return_and_validate_extra_property, {format: :json}
56
- expect(response).to match_declared_responses
49
+ context "when allow_additional_properties_in_response is true'" do
50
+ before do
51
+ Apipie.configuration.generator.swagger.allow_additional_properties_in_response = true
52
+ end
53
+
54
+ it "does not raise error when a response has an extra property" do
55
+ response = get :return_and_validate_extra_property, format: :json
56
+ expect(response).to match_declared_responses
57
+ end
57
58
  end
58
59
 
59
60
  it "does not raise error when a response has an extra field and 'additional_properties' is specified in the response" do
60
- Apipie.configuration.swagger_allow_additional_properties_in_response = false
61
- response = get :return_and_validate_allowed_extra_property, {format: :json}
61
+ response = get :return_and_validate_allowed_extra_property, format: :json
62
62
  expect(response).to match_declared_responses
63
63
  end
64
64
 
65
65
  it "raises error when a response sub-object has an extra field and 'additional_properties' is not specified on it, but specified on the top level of the response" do
66
- Apipie.configuration.swagger_allow_additional_properties_in_response = false
67
- response = get :sub_object_invalid_extra_property, {format: :json}
66
+ response = get :sub_object_invalid_extra_property, format: :json
68
67
  expect(response).not_to match_declared_responses
69
68
  end
70
69
 
71
- it "does not rais error when a response sub-object has an extra field and 'additional_properties' is specified on it" do
72
- Apipie.configuration.swagger_allow_additional_properties_in_response = false
73
- response = get :sub_object_allowed_extra_property, {format: :json}
70
+ it "does not raise error when a response sub-object has an extra field and 'additional_properties' is specified on it" do
71
+ response = get :sub_object_allowed_extra_property, format: :json
74
72
  expect(response).to match_declared_responses
75
73
  end
76
74
 
77
75
  describe "auto validation" do
78
76
  auto_validate_rendered_views
79
77
  it "raises exception when a response field has the wrong type and auto validation is turned on" do
80
- expect { get :return_and_validate_type_mismatch, {format: :json} }.to raise_error(Apipie::ResponseDoesNotMatchSwaggerSchema)
78
+ expect { get :return_and_validate_type_mismatch, format: :json }.to raise_error(Apipie::ResponseDoesNotMatchSwaggerSchema)
81
79
  end
82
80
 
83
81
  it "does not raise an exception when calling an undocumented method" do
84
- expect { get :undocumented_method, {format: :json} }.not_to raise_error
82
+ expect { get :undocumented_method, format: :json }.not_to raise_error
85
83
  end
86
84
 
87
85
  end
88
86
 
89
-
90
87
  describe "with array field" do
91
88
  it "no error for valid response" do
92
- response = get :returns_response_with_valid_array, {format: :json}
89
+ response = get :returns_response_with_valid_array, format: :json
93
90
  expect(response).to match_declared_responses
94
91
  end
95
92
 
96
93
  it "error if type of element in the array is wrong" do
97
- response = get :returns_response_with_invalid_array, {format: :json}
94
+ response = get :returns_response_with_invalid_array, format: :json
98
95
  expect(response).not_to match_declared_responses
99
96
  end
100
97
  end
101
-
102
-
103
-
104
98
  end
@@ -5,9 +5,10 @@ def compare_hashes(h1, h2)
5
5
  expect(h1).to eq(h2)
6
6
  else
7
7
  h1.each do |key, val|
8
- if val.is_a? Hash
8
+ case val
9
+ when Hash
9
10
  compare_hashes val, h2[key]
10
- elsif val.is_a? Array
11
+ when Array
11
12
  val.each_with_index do |v, i|
12
13
  compare_hashes val[i], h2[key][i]
13
14
  end
@@ -36,6 +37,7 @@ describe UsersController do
36
37
  expect(methods.keys).to include(:update)
37
38
  expect(methods.keys).to include(:two_urls)
38
39
  expect(methods.keys).to include(:action_with_headers)
40
+ expect(methods.keys).to include(:multiple_required_params)
39
41
  end
40
42
 
41
43
  it "should contain info about resource" do
@@ -51,7 +53,7 @@ describe UsersController do
51
53
  expect(subject._params_args.count).to eq(2)
52
54
  name, type, options = subject._params_args.first
53
55
  expect(name).to eq(:id)
54
- expect(type).to eq(Fixnum)
56
+ expect(type).to eq(Integer)
55
57
  expect(options).to eq({:required=>false, :desc=>"User ID"})
56
58
  end
57
59
  end
@@ -100,6 +102,10 @@ describe UsersController do
100
102
  expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
101
103
  end
102
104
 
105
+ it "should fail if multiple required parameters are missing" do
106
+ expect { get :multiple_required_params }.to raise_error(Apipie::ParamMultipleMissing, /required_param1.*\n.*required_param2|required_param2.*\n.*required_parameter1/)
107
+ end
108
+
103
109
  it "should pass if required parameter has wrong type" do
104
110
  expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
105
111
  expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
@@ -124,6 +130,29 @@ describe UsersController do
124
130
  end
125
131
  end
126
132
 
133
+ context "key validations are enabled and skip on non-validated keys" do
134
+ before do
135
+ Apipie.configuration.validate_value = false
136
+ Apipie.configuration.validate_presence = true
137
+ Apipie.configuration.validate_key = true
138
+ Apipie.configuration.action_on_non_validated_keys = :skip
139
+ end
140
+
141
+ it "should reply to valid request" do
142
+ expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
143
+ assert_response :success
144
+ end
145
+
146
+ it "should delete the param and not fail if an extra parameter is passed." do
147
+ expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.not_to raise_error
148
+ expect(controller.params.as_json).to eq({"session"=>"secret_hash", "id"=>"5", "controller"=>"users", "action"=>"show"})
149
+ end
150
+
151
+ after do
152
+ Apipie.configuration.action_on_non_validated_keys = :raise
153
+ end
154
+ end
155
+
127
156
  context "presence and value validations are enabled" do
128
157
  before do
129
158
  Apipie.configuration.validate_value = true
@@ -222,6 +251,11 @@ describe UsersController do
222
251
  post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
223
252
  }.to raise_error(Apipie::ParamInvalid, /membership/)
224
253
 
254
+ # Should include both pass and name
255
+ expect {
256
+ post :create, :params => { :user => { :membership => "standard" } }
257
+ }.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/)
258
+
225
259
  expect {
226
260
  post :create, :params => { :user => { :name => "root" } }
227
261
  }.to raise_error(Apipie::ParamMissing, /pass/)
@@ -245,6 +279,7 @@ describe UsersController do
245
279
  :allow_blank => false,
246
280
  :metadata => nil,
247
281
  :show => true,
282
+ :deprecated => false,
248
283
  :expected_type => "hash",
249
284
  :validations => [])
250
285
  end
@@ -387,7 +422,7 @@ describe UsersController do
387
422
  expect(b.resource._id).to eq('users')
388
423
 
389
424
  expect(b.apis.count).to eq(1)
390
- expect(b.formats).to eq(['json', 'jsonp'])
425
+ expect(b.formats).to eq(%w[json jsonp])
391
426
  api = b.apis.first
392
427
  expect(api.short_description).to eq("Show user profile")
393
428
  expect(api.path).to eq("/users/:id")
@@ -561,6 +596,7 @@ describe UsersController do
561
596
  :description=>"\n<p>Authorization</p>\n",
562
597
  :name=>"oauth",
563
598
  :show=>true,
599
+ :deprecated=>false,
564
600
  :expected_type=>"string"},
565
601
  {:validator=>"Must be a Hash",
566
602
  :description=>"\n<p>Deprecated parameter not documented</p>\n",
@@ -571,15 +607,17 @@ describe UsersController do
571
607
  :required=>false,
572
608
  :full_name=>"legacy_param",
573
609
  :show=>false,
610
+ :deprecated=>false,
574
611
  :params=>
575
612
  [{:validator=>"Must be a Hash",
576
613
  :description=>"\n<p>Param description for all methods</p>\n",
577
614
  :expected_type=>"hash",
578
615
  :allow_nil=>false,
579
- :allow_blank => false,
616
+ :allow_blank => false,
580
617
  :name=>"resource_param",
581
618
  :required=>false,
582
619
  :full_name=>"resource_param",
620
+ :deprecated=>false,
583
621
  :show=>true,
584
622
  :params=>
585
623
  [{:required=>true,
@@ -589,6 +627,7 @@ describe UsersController do
589
627
  :description=>"\n<p>Username for login</p>\n",
590
628
  :name=>"ausername", :full_name=>"resource_param[ausername]",
591
629
  :show=>true,
630
+ :deprecated=>false,
592
631
  :expected_type=>"string"},
593
632
  {:required=>true,
594
633
  :allow_nil => false,
@@ -597,6 +636,7 @@ describe UsersController do
597
636
  :description=>"\n<p>Password for login</p>\n",
598
637
  :name=>"apassword", :full_name=>"resource_param[apassword]",
599
638
  :show=>true,
639
+ :deprecated=>false,
600
640
  :expected_type=>"string"}
601
641
  ]}
602
642
  ]
@@ -607,6 +647,7 @@ describe UsersController do
607
647
  :description=>"\n<p>Company ID</p>\n",
608
648
  :name=>"id", :full_name=>"id",
609
649
  :show=>true,
650
+ :deprecated=>false,
610
651
  :expected_type=>"numeric"},
611
652
  ],
612
653
  :name => 'two_urls',
@@ -677,7 +718,7 @@ EOS2
677
718
  param = a.params[:array_param]
678
719
  expect(param.desc).to eq("\n<p>array validator</p>\n")
679
720
  expect(param.validator.class).to be(Apipie::Validator::EnumValidator)
680
- expect(param.validator.instance_variable_get("@array")).to eq(["100", "one", "two", "1", "2"])
721
+ expect(param.validator.instance_variable_get("@array")).to eq(%w[100 one two 1 2])
681
722
 
682
723
  param = a.params[:proc_param]
683
724
  expect(param.desc).to eq("\n<p>proc validator</p>\n")
data/spec/dummy/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require File.expand_path('config/application', __dir__)
5
5
  require 'rake'
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -22,7 +22,8 @@ module Api
22
22
  def update
23
23
  end
24
24
 
25
- api :DELETE, "/architecturess/:id/", "Delete an architecture."
25
+ api! "Delete an architecture."
26
+ api_version "2.0" # forces removal of the method description
26
27
  def destroy
27
28
  end
28
29
  end
@@ -5,6 +5,12 @@ module Api
5
5
  api_version '2.0'
6
6
  app_info 'Version 2.0 description'
7
7
  api_base_url '/api/v2'
8
+
9
+ name :reversed_name
10
+ end
11
+
12
+ def self.reversed_name
13
+ controller_name.capitalize.reverse
8
14
  end
9
15
  end
10
16
  end
@@ -0,0 +1,14 @@
1
+ module Api
2
+ module V2
3
+ class EmptyMiddleController < V2::BaseController
4
+ # This is an empty controller, used to test cases where controllers
5
+ # may inherit from a middle controler that does not define a resource_description,
6
+ # but the middle controller's parent does.
7
+
8
+ def inconsequential_method
9
+ # This method is here to ensure that the controller is not empty.
10
+ # It triggers method_added, which is used to add the resource description.
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,8 @@
1
1
  module Api
2
2
  module V2
3
3
  class Nested::ResourcesController < V2::BaseController
4
- resource_description do
5
- name 'Resources'
4
+ resource_description do
5
+ name ->(controller) { controller.controller_name.delete('aeiou').capitalize }
6
6
  resource_id "resource"
7
7
  end
8
8
  api :GET, "/nested/resources/", "List all nested resources."
@@ -0,0 +1,30 @@
1
+ module Api
2
+ module V2
3
+ module Sub
4
+ class FootgunsController < V2::EmptyMiddleController
5
+ resource_description do
6
+ short 'Footguns are bad'
7
+ end
8
+
9
+ api :GET, '/footguns/', 'List all footguns.'
10
+ def index; end
11
+
12
+ api :GET, '/footguns/:id/', 'Show a footgun.'
13
+ def show; end
14
+
15
+ api :POST, '/footguns/', 'Create a footgun.'
16
+ def create; end
17
+
18
+ api :PUT, '/footguns/:id/', 'Update a footgun.'
19
+ param :footgun, Hash, :required => true do
20
+ param :name, String
21
+ end
22
+ def update; end
23
+
24
+ api! 'Delete a footgun.'
25
+ api_version '2.0' # forces removal of the method description
26
+ def destroy; end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,6 +3,6 @@ class ConcernsController < ApplicationController
3
3
  resource_description { resource_id 'concern_resources' }
4
4
 
5
5
  apipie_concern_subst(:concern => 'user', :custom_subst => 'custom', 'string_subst' => 'string')
6
- include ::Concerns::SampleController
6
+ include SampleController
7
7
 
8
8
  end
@@ -1,4 +1,3 @@
1
- module Concerns
2
1
  module ExtendingConcern
3
2
  extend Apipie::DSL::Concern
4
3
 
@@ -9,4 +8,3 @@ module Concerns
9
8
  meta metadata: 'data'
10
9
  end
11
10
  end
12
- end
@@ -0,0 +1,19 @@
1
+ class IncludedParamGroupController < ApplicationController
2
+ include RandomParamGroup
3
+
4
+ api :GET, '/included-param-group'
5
+ returns code:200 do
6
+ property :top_level, Array, of: Hash do
7
+ param_group :random_param_group
8
+ end
9
+ property :nested, Hash do
10
+ property :random_array, Array, of: Hash do
11
+ param_group :random_param_group
12
+ end
13
+ end
14
+ end
15
+ def show
16
+ end
17
+
18
+ end
19
+
@@ -3,7 +3,7 @@ class OverriddenConcernsController < ApplicationController
3
3
  resource_description { resource_id 'overridden_concern_resources' }
4
4
 
5
5
  apipie_concern_subst(:concern => 'user')
6
- include ::Concerns::SampleController
6
+ include SampleController
7
7
 
8
8
  def_param_group :concern do
9
9
  param :concern, String
@@ -11,7 +11,7 @@ class OverriddenConcernsController < ApplicationController
11
11
 
12
12
  api :PUT, '/:resource_id/:id'
13
13
  param :custom_parameter, String, "New parameter added by the overriding method"
14
- param_group :concern, ::Concerns::SampleController
14
+ param_group :concern, SampleController
15
15
  def update
16
16
  super
17
17
  end
@@ -23,8 +23,8 @@ class PetsController < ApplicationController
23
23
  #-----------------------------------------------------------
24
24
  api :GET, "/pets/:id/as_properties", "Get a pet record"
25
25
  returns :code => 200 do
26
- property :pet_name, String, :desc => "Name of pet", :required => false
27
- property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # required by default, because this is a 'property'
26
+ property :pet_name, String, :desc => "Name of pet", :required => false, :example => 'mypet'
27
+ property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # required by default, because this is a 'property'
28
28
  end
29
29
  returns :code => 404 do
30
30
  property :another_error_message, String, :desc => "Overriding the response description from the Pets resource"
@@ -40,7 +40,7 @@ class PetsController < ApplicationController
40
40
  #-----------------------------------------------------------
41
41
  def_param_group :pet do
42
42
  property :pet_name, String, :desc => "Name of pet", :required => false
43
- property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # required by default, because this is a 'property'
43
+ property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # required by default, because this is a 'property'
44
44
  end
45
45
 
46
46
  api :GET, "/pets/:id/as_param_group_of_properties", "Get a pet record"
@@ -70,7 +70,7 @@ class PetsController < ApplicationController
70
70
  param :pet_id, Integer, :desc => "id of pet", :required => true
71
71
  param :pet_name, String, :desc => "Name of pet", :required => false, :only_in => :response
72
72
  param :partial_match_allowed, [true, false], :desc => "Partial match allowed?", :required => false, :only_in => :request
73
- property :animal_type, ['dog','cat','iguana','kangaroo'], :desc => "Type of pet" # this is implicitly :only_in => :response
73
+ property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # this is implicitly :only_in => :response
74
74
  end
75
75
 
76
76
  api :GET, "/pets/pet_by_id", "Get a pet record with the pet id in the body of the request"
@@ -142,7 +142,7 @@ class PetsController < ApplicationController
142
142
  end
143
143
  returns :code => 204 do
144
144
  property :int_array, :array_of => Integer
145
- property :enum_array, :array_of => ['v1','v2','v3']
145
+ property :enum_array, :array_of => %w[v1 v2 v3]
146
146
  end
147
147
  returns :code => :unprocessable_entity, :desc => "Fleas were discovered on the pet" do
148
148
  param_group :pet
@@ -14,7 +14,7 @@ class Pet
14
14
  def self.describe_own_properties
15
15
  [
16
16
  Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
17
- Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => ["dog", "cat", "iguana", "kangaroo"]}),
17
+ Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
18
18
  Apipie::additional_properties(false)
19
19
  ]
20
20
  end
@@ -27,7 +27,7 @@ class PetWithMeasurements
27
27
  def self.describe_own_properties
28
28
  [
29
29
  Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
30
- Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => ["dog", "cat", "iguana", "kangaroo"]}),
30
+ Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
31
31
  Apipie::prop(:pet_measurements, 'object', {}, [
32
32
  Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
33
33
  Apipie::prop(:height, 'number', {:description => "Height in inches" }),
@@ -1,4 +1,3 @@
1
- module Concerns
2
1
  module SampleController
3
2
  extend Apipie::DSL::Concern
4
3
 
@@ -38,4 +37,3 @@ module Concerns
38
37
  render :plain => "OK #{params.inspect}"
39
38
  end
40
39
  end
41
- end
@@ -31,7 +31,7 @@ class TwitterExampleController < ApplicationController
31
31
 
32
32
  api :GET, '/twitter_example/profile_image/:screen_name', 'Access the profile image in various sizes for the user with the indicated screen_name.'
33
33
  param :screen_name, String, :required => true, :desc => 'The screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.'
34
- param :size, ['bigger','normal','mini','original'], :desc => <<-EOS
34
+ param :size, %w[bigger normal mini original], :desc => <<-EOS
35
35
  Specifies the size of image to fetch. Not specifying a size will give the default, normal size of 48px by 48px. Valid options include:
36
36
 
37
37
  * bigger - 73px by 73px
@@ -166,7 +166,7 @@ class TwitterExampleController < ApplicationController
166
166
  param :user_id, Integer, :desc => 'The ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.'
167
167
  param :screen_name, String, :desc => 'The screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.'
168
168
  param :include_entities, String
169
- param :skip_status, ['t','true','1'],
169
+ param :skip_status, %w[t true 1],
170
170
  :description => 'When set to either true, t or 1 statuses will not be included in the returned user objects.'
171
171
 
172
172
  description "Look at examples."
@@ -4,7 +4,7 @@ class UsersController < ApplicationController
4
4
  short 'Site members'
5
5
  path '/users'
6
6
  formats ['json']
7
- param :id, Fixnum, :desc => "User ID", :required => false
7
+ param :id, Integer, :desc => "User ID", :required => false
8
8
  param :legacy_param, Hash, :desc => 'Deprecated parameter not documented', :show => false, :required => false do
9
9
  param :resource_param, Hash, :desc => 'Param description for all methods' do
10
10
  param :ausername, String, :desc => "Username for login", :required => true
@@ -170,14 +170,14 @@ class UsersController < ApplicationController
170
170
  eos
171
171
  api :GET, "/users/:id", "Show user profile"
172
172
  show false
173
- formats ['json', 'jsonp']
173
+ formats %w[json jsonp]
174
174
  error 401, "Unauthorized"
175
175
  error :code => 404, :description => "Not Found"
176
176
  param :id, Integer, :desc => "user id", :required => true
177
177
  param :session, String, :desc => "user is logged in", :required => true, :missing_message => lambda { "session_parameter_is_required" }
178
178
  param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
179
179
  param :regexp2, /\b[A-Z0-9._%+-=]+@[A-Z0-9.-]+.[A-Z]{2,}\b/i, :desc => "email regexp"
180
- param :array_param, ["100", "one", "two", "1", "2"], :desc => "array validator"
180
+ param :array_param, %w[100 one two 1 2], :desc => "array validator"
181
181
  param :boolean_param, [true, false], :desc => "array validator with boolean"
182
182
  param :proc_param, lambda { |val|
183
183
  val == "param value" ? true : "The only good value is 'param value'."
@@ -211,7 +211,7 @@ class UsersController < ApplicationController
211
211
  def_param_group :user do
212
212
  param :user, Hash, :desc => "User info", :required => true, :action_aware => true do
213
213
  param_group :credentials
214
- param :membership, ["standard","premium"], :desc => "User membership", :allow_nil => false
214
+ param :membership, %w[standard premium], :desc => "User membership", :allow_nil => false
215
215
  end
216
216
  end
217
217
 
@@ -269,11 +269,17 @@ class UsersController < ApplicationController
269
269
  end
270
270
 
271
271
  api :GET, '/users/by_department', 'show users from a specific department'
272
- param :department, ["finance", "operations", "sales", "marketing", "HR"], required: false, default_value: "sales"
272
+ param :department, %w[finance operations sales marketing HR], required: false, default_value: "sales"
273
273
  def get_by_department
274
274
  render :plain => 'nothing to see here'
275
275
  end
276
276
 
277
+ api :GET, '/users/in_departments', 'show users from specific departments'
278
+ param :departments, Array, in: %w[finance operations sales marketing HR], default_value: ['sales']
279
+ def get_in_departments
280
+ render :plain => 'nothing to see here'
281
+ end
282
+
277
283
  api :GET, '/users/desc_from_file', 'desc from file'
278
284
  document 'users/desc_from_file.md'
279
285
  def desc_from_file
@@ -295,4 +301,10 @@ class UsersController < ApplicationController
295
301
  header :HeaderNameWithDefaultValue, 'Header with default value', required: true, default: 'default value'
296
302
  def action_with_headers
297
303
  end
304
+
305
+ api :GET, '/users/multiple_required_params'
306
+ param :required_param1, String, required: true
307
+ param :required_param2, String, required: true
308
+ def multiple_required_params
309
+ end
298
310
  end
@@ -0,0 +1,8 @@
1
+ module RandomParamGroup
2
+ def self.included(klazz)
3
+ klazz.def_param_group :random_param_group do
4
+ property :id, Integer
5
+ property :name, String
6
+ end
7
+ end
8
+ end
@@ -1,4 +1,4 @@
1
- $:.push File.expand_path('../lib', __FILE__)
1
+ $:.push File.expand_path('lib', __dir__)
2
2
 
3
3
  # Describe your gem and declare its dependencies:
4
4
  Gem::Specification.new do |s|
@@ -1,10 +1,7 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
- require "active_model/railtie"
4
- require "active_record/railtie"
5
3
  require "action_controller/railtie"
6
4
  require "action_view/railtie"
7
- require "action_mailer/railtie"
8
5
 
9
6
  Bundler.require
10
7
  require "apipie-rails"
@@ -44,7 +41,7 @@ module Dummy
44
41
  config.filter_parameters += [:password]
45
42
 
46
43
  config.to_prepare do
47
- ExtendedController.send(:include, Concerns::ExtendingConcern)
44
+ ExtendedController.send(:include, ExtendingConcern)
48
45
  end
49
46
  end
50
47
  end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
2
+ gemfile = File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
4
  if File.exist?(gemfile)
5
5
  ENV['BUNDLE_GEMFILE'] = gemfile
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
7
7
  Bundler.setup
8
8
  end
9
9
 
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../lib', __dir__)
@@ -2,7 +2,7 @@
2
2
  # ENV['RAILS_RELATIVE_URL_ROOT'] = '/relative/path'
3
3
 
4
4
  # Load the rails application
5
- require File.expand_path('../application', __FILE__)
5
+ require File.expand_path('application', __dir__)
6
6
 
7
7
  # Initialize the rails application
8
8
  Dummy::Application.initialize!