apipie-rails 0.5.20 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +12 -21
  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 +2062 -0
  8. data/.vscode/settings.json +3 -0
  9. data/CHANGELOG.md +144 -0
  10. data/Gemfile +20 -0
  11. data/README.rst +106 -15
  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 +39 -27
  30. data/lib/apipie/error_description.rb +3 -3
  31. data/lib/apipie/errors.rb +16 -16
  32. data/lib/apipie/extractor/collector.rb +4 -5
  33. data/lib/apipie/extractor/recorder.rb +33 -6
  34. data/lib/apipie/extractor/writer.rb +14 -14
  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 +105 -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 +115 -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 +10 -8
  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 +3 -1
  81. data/lib/apipie/swagger_generator.rb +28 -691
  82. data/lib/apipie/validator.rb +40 -10
  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 +35 -30
  88. data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
  89. data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
  90. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
  91. data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
  92. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  93. data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
  94. data/spec/controllers/users_controller_spec.rb +47 -6
  95. data/spec/dummy/Rakefile +1 -1
  96. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
  97. data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
  98. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
  99. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
  100. data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
  101. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  102. data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
  103. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  104. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  105. data/spec/dummy/app/controllers/pets_controller.rb +4 -4
  106. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  107. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
  108. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  109. data/spec/dummy/app/controllers/users_controller.rb +17 -5
  110. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  111. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  112. data/spec/dummy/config/application.rb +2 -5
  113. data/spec/dummy/config/boot.rb +2 -2
  114. data/spec/dummy/config/environment.rb +1 -1
  115. data/spec/dummy/config/environments/development.rb +0 -3
  116. data/spec/dummy/config/environments/production.rb +0 -3
  117. data/spec/dummy/config/environments/test.rb +0 -5
  118. data/spec/dummy/config/initializers/apipie.rb +2 -2
  119. data/spec/dummy/config/routes.rb +8 -0
  120. data/spec/dummy/config.ru +1 -1
  121. data/spec/dummy/script/rails +2 -2
  122. data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
  123. data/spec/lib/apipie/application_spec.rb +62 -0
  124. data/spec/lib/apipie/configuration_spec.rb +38 -0
  125. data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
  126. data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
  127. data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
  128. data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
  129. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  130. data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
  131. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
  132. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  133. data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
  134. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +203 -0
  135. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
  136. data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
  137. data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
  138. data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
  139. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +178 -0
  140. data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
  141. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  142. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  143. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  144. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  145. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  146. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
  147. data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
  148. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
  149. data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
  150. data/spec/lib/apipie/method_description_spec.rb +133 -0
  151. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  152. data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
  153. data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
  154. data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
  155. data/spec/lib/apipie/resource_description_spec.rb +91 -0
  156. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  157. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  158. data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
  159. data/spec/lib/rake_spec.rb +3 -5
  160. data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
  161. data/spec/lib/swagger/rake_swagger_spec.rb +24 -9
  162. data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
  163. data/spec/lib/validators/array_validator_spec.rb +1 -1
  164. data/spec/spec_helper.rb +10 -32
  165. data/spec/support/custom_bool_validator.rb +17 -0
  166. data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
  167. metadata +169 -122
  168. data/Gemfile +0 -1
  169. data/gemfiles/Gemfile.rails42 +0 -14
  170. data/gemfiles/Gemfile.rails42.lock +0 -160
  171. data/gemfiles/Gemfile.rails52 +0 -9
  172. data/gemfiles/Gemfile.rails60 +0 -10
  173. data/gemfiles/Gemfile.rails61 +0 -10
  174. data/spec/lib/application_spec.rb +0 -49
  175. data/spec/lib/method_description_spec.rb +0 -98
  176. data/spec/lib/resource_description_spec.rb +0 -48
  177. data/spec/support/rails-42-ruby-26.rb +0 -15
  178. /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
  179. /data/spec/lib/{extractor → apipie}/extractor_spec.rb +0 -0
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
4
+ let(:http_method) { nil }
5
+ let(:controller_method) { nil }
6
+ let(:allow_null) { false }
7
+
8
+ let(:resource_description) do
9
+ Apipie::ResourceDescription.new(PetsController, 'pets')
10
+ end
11
+
12
+ let(:method_description) do
13
+ Apipie::MethodDescription.new(
14
+ 'create',
15
+ resource_description,
16
+ ActionController::Base.send(:_apipie_dsl_data_init)
17
+ )
18
+ end
19
+
20
+ let(:response_description_dsl) do
21
+ proc do
22
+ property :a_number, Integer
23
+ property :an_optional_number, Integer, required: false
24
+ end
25
+ end
26
+
27
+ let(:options) { {} }
28
+
29
+ let(:response_description) do
30
+ Apipie::ResponseDescription.new(
31
+ method_description,
32
+ 204,
33
+ options,
34
+ PetsController,
35
+ response_description_dsl,
36
+ nil
37
+ )
38
+ end
39
+
40
+ let(:service) do
41
+ described_class.new(
42
+ response_description,
43
+ allow_null: allow_null,
44
+ http_method: http_method,
45
+ controller_method: controller_method
46
+ )
47
+ end
48
+
49
+ describe '#to_swagger' do
50
+ let(:swagger_response) { service.to_swagger }
51
+
52
+ describe 'properties' do
53
+ subject(:properties) { swagger_response[:properties] }
54
+
55
+ it 'returns correct properties' do
56
+ expect(properties).to eq(
57
+ {
58
+ a_number: {
59
+ type: 'number', required: true
60
+ },
61
+ an_optional_number: {
62
+ type: 'number'
63
+ }
64
+ }
65
+ )
66
+ end
67
+
68
+ context 'when nulls are allowed' do
69
+ let(:allow_null) { true }
70
+
71
+ it 'returns correct properties' do
72
+ expect(properties).to eq(
73
+ {
74
+ a_number: {
75
+ type: %w[number null], required: true
76
+ },
77
+ an_optional_number: {
78
+ type: %w[number null]
79
+ }
80
+ }
81
+ )
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when responses_use_refs is set to true' do
87
+ subject(:response) { swagger_response }
88
+
89
+ before { Apipie.configuration.generator.swagger.responses_use_refs = true }
90
+ after { Apipie.configuration.generator.swagger.responses_use_refs = false }
91
+
92
+ context 'when typename is given' do
93
+ let(:options) { { param_group: :some_param_group } }
94
+
95
+ it 'returns the reference' do
96
+ expect(response).to eq(
97
+ {
98
+ '$ref' => '#/definitions/some_param_group'
99
+ }
100
+ )
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::OperationId do
4
+ let(:path) { '/api' }
5
+ let(:http_method) { :GET }
6
+ let(:param) {}
7
+
8
+ let(:operation_id) do
9
+ described_class.new(path: path, http_method: http_method, param: param)
10
+ end
11
+
12
+ describe '#to_s' do
13
+ subject { operation_id.to_s}
14
+
15
+ it { is_expected.to eq('get_api') }
16
+
17
+ context 'when path has variable' do
18
+ let(:path) { '/api/users/:id' }
19
+
20
+ it { is_expected.to eq("#{http_method.downcase}_api_users_id") }
21
+ end
22
+
23
+ context 'when param is given' do
24
+ let(:param) { 'show' }
25
+
26
+ it { is_expected.to eq("#{http_method.downcase}_api_param_show") }
27
+ end
28
+ end
29
+
30
+ describe '.from' do
31
+ subject { described_class.from(describable).to_s }
32
+
33
+ context 'when an Apipie::MethodDescription::Api is given' do
34
+ let(:describable) do
35
+ Apipie::MethodDescription::Api.
36
+ new(http_method, path, '', { from_routes: '' })
37
+ end
38
+
39
+ it { is_expected.to eq("#{http_method.downcase}_api") }
40
+ end
41
+
42
+ context 'when an Apipie::MethodDescription is given' do
43
+ let(:dsl_data) do
44
+ ActionController::Base.
45
+ send(:_apipie_dsl_data_init).
46
+ merge({
47
+ api_args: [[http_method, path, "description", { :deprecated => true }]]
48
+ })
49
+ end
50
+
51
+ let(:resource_desc) do
52
+ Apipie::ResourceDescription.new(UsersController, "users")
53
+ end
54
+
55
+ let(:describable) do
56
+ Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
57
+ end
58
+
59
+ it { is_expected.to eq("#{http_method.downcase}_api") }
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ParamDescription::Builder do
4
+ let(:validator) { String }
5
+ let(:validator_options) { {} }
6
+ let(:path) { '/api' }
7
+ let(:http_method) { :GET }
8
+ let(:in_schema) { true }
9
+ let(:builder) do
10
+ described_class.new(
11
+ param_description,
12
+ in_schema: in_schema,
13
+ controller_method: method_desc
14
+ )
15
+ end
16
+ let(:generated_block) { builder.to_swagger }
17
+ let(:base_param_description_options) { {} }
18
+
19
+ let(:param_description_options) do
20
+ base_param_description_options.merge(validator_options)
21
+ end
22
+
23
+ let(:base_dsl_data) do
24
+ {
25
+ :api => false,
26
+ :api_args => [],
27
+ :api_from_routes => nil,
28
+ :errors => [],
29
+ :tag_list => [],
30
+ :returns => {},
31
+ :params => [],
32
+ :headers => [],
33
+ :resource_id => nil,
34
+ :short_description => nil,
35
+ :description => nil,
36
+ :examples => [],
37
+ :see => [],
38
+ :formats => nil,
39
+ :api_versions => [],
40
+ :meta => nil,
41
+ :show => true,
42
+ :deprecated => false
43
+ }
44
+ end
45
+
46
+ let(:dsl_data) do
47
+ base_dsl_data.merge({
48
+ api_args: [
49
+ [
50
+ http_method,
51
+ path,
52
+ 'description',
53
+ { deprecated: true }
54
+ ]
55
+ ]
56
+ })
57
+ end
58
+
59
+ let(:resource_desc) do
60
+ Apipie::ResourceDescription.new(UsersController, 'dummy')
61
+ end
62
+
63
+ let(:method_desc) do
64
+ Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
65
+ end
66
+
67
+ let(:param_description) do
68
+ Apipie::ParamDescription.new(
69
+ method_desc,
70
+ :param,
71
+ validator,
72
+ param_description_options
73
+ )
74
+ end
75
+
76
+ describe 'required' do
77
+ subject { generated_block[:required] }
78
+
79
+ it { is_expected.to be_blank }
80
+
81
+ context 'when is required' do
82
+ let(:base_param_description_options) { { required: true } }
83
+
84
+ it { is_expected.to eq(true) }
85
+ end
86
+
87
+ context 'when in_schema is false' do
88
+ let(:in_schema) { false }
89
+
90
+ it { is_expected.to be_blank }
91
+
92
+ context 'and is required' do
93
+ let(:base_param_description_options) { { required: true } }
94
+
95
+ it { is_expected.to eq(true) }
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'warning' do
101
+ before { Singleton.__init__(Apipie::Generator::Swagger::WarningWriter) }
102
+
103
+ subject { generated_block }
104
+
105
+ context 'when required is true' do
106
+ let(:base_param_description_options) { { required: true } }
107
+
108
+ it 'does not output an option without default warning' do
109
+ expect { subject }.not_to output(
110
+ /is optional but default value is not specified/
111
+ ).to_stderr
112
+ end
113
+ end
114
+
115
+ context 'when required is false' do
116
+ context 'when default_value is nil' do
117
+ let(:base_param_description_options) do
118
+ { required: false, default_value: nil }
119
+ end
120
+
121
+ it 'will not warn' do
122
+ expect { subject }.not_to output(
123
+ /is optional but default value is not specified/
124
+ ).to_stderr
125
+ end
126
+ end
127
+
128
+ context 'when default_value is 123' do
129
+ let(:base_param_description_options) do
130
+ { required: false, default_value: 123 }
131
+ end
132
+
133
+ it 'will not warn' do
134
+ expect { subject }.not_to output(
135
+ /is optional but default value is not specified/
136
+ ).to_stderr
137
+ end
138
+ end
139
+
140
+ context 'default_value not given' do
141
+ let(:base_param_description_options) { { required: false } }
142
+
143
+ it 'warns' do
144
+ expect { subject }.to output(
145
+ /is optional but default value is not specified/
146
+ ).to_stderr
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ describe '.with_type' do
153
+ subject { generated_block[:type] }
154
+
155
+ it { is_expected.to be_blank }
156
+
157
+ context 'when type is assigned' do
158
+ before { builder.with_type(with_null: false ) }
159
+
160
+ it { is_expected.to be_present }
161
+ end
162
+ end
163
+
164
+ describe '.with_description' do
165
+ subject { generated_block[:description] }
166
+
167
+ it { is_expected.to be_blank }
168
+
169
+ context 'when description is assigned' do
170
+ let(:param_description_options) { { desc: 'some-description' } }
171
+
172
+ before { builder.with_description(language: 'en') }
173
+
174
+ it { is_expected.to be_present }
175
+ end
176
+ end
177
+
178
+ describe '.with_name' do
179
+ subject { generated_block[:name] }
180
+
181
+ it { is_expected.to be_blank }
182
+
183
+ context 'when name is assigned' do
184
+ before { builder.with_name }
185
+
186
+ it { is_expected.to be_present }
187
+ end
188
+ end
189
+
190
+ describe '.with_in' do
191
+ subject { generated_block[:in] }
192
+
193
+ it { is_expected.to be_blank }
194
+
195
+ context 'when in is assigned' do
196
+ let(:in_schema) { false }
197
+
198
+ before { builder.with_in(http_method: 'get') }
199
+
200
+ it { is_expected.to be_present }
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ParamDescription::Composite do
4
+ let(:param_descriptions) {}
5
+
6
+ let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
7
+
8
+ let(:resource_desc) do
9
+ Apipie::ResourceDescription.new(UsersController, "users")
10
+ end
11
+
12
+ let(:context) do
13
+ Apipie::Generator::Swagger::Context.new(
14
+ allow_null: true,
15
+ http_method: 'get',
16
+ controller_method: method_description
17
+ )
18
+ end
19
+
20
+ let(:method_description) do
21
+ Apipie::MethodDescription.new(:create, resource_desc, dsl_data)
22
+ end
23
+
24
+ let(:composite) { described_class.new(param_descriptions, context) }
25
+
26
+ let(:swagger) { composite.to_swagger }
27
+
28
+ let(:params_description_one) do
29
+ Apipie::ParamDescription.new(method_description, :some_param, String)
30
+ end
31
+
32
+ let(:params_description_two) do
33
+ Apipie::ParamDescription.new(method_description, :some_other_param, String)
34
+ end
35
+
36
+ let(:param_descriptions) { [params_description_one, params_description_two] }
37
+
38
+ context 'when no param descriptions are given' do
39
+ let(:param_descriptions) { [] }
40
+
41
+ subject { swagger }
42
+
43
+ it { is_expected.to be_blank }
44
+ end
45
+
46
+ describe 'additionalProperties' do
47
+ subject { swagger[:additionalProperties] }
48
+
49
+ it { is_expected.to be_falsey }
50
+
51
+ context 'when additional properties in response allowed' do
52
+ before do
53
+ Apipie.configuration.generator.swagger.allow_additional_properties_in_response = true
54
+ end
55
+
56
+ it { is_expected.to be_blank }
57
+ end
58
+ end
59
+
60
+ xdescribe 'nested additionalProperties' do
61
+ context 'when param description has nested params' do
62
+ let(:validator) do
63
+
64
+ end
65
+
66
+ let(:params_description_one) do
67
+ Apipie::ParamDescription.new(
68
+ method_description,
69
+ :some_param,
70
+ validator,
71
+ { required: true }
72
+ )
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'required' do
78
+ subject { swagger[:required] }
79
+
80
+ it { is_expected.to be_blank }
81
+
82
+ context 'when param description is required' do
83
+ let(:params_description_one) do
84
+ Apipie::ParamDescription.new(
85
+ method_description,
86
+ :some_param,
87
+ String,
88
+ { required: true }
89
+ )
90
+ end
91
+
92
+ it { is_expected.to be_truthy }
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ParamDescription::Description do
4
+ let(:param_description_options) { {} }
5
+ let(:http_method) { :GET }
6
+ let(:path) { '/api' }
7
+ let(:validator) { String }
8
+ let(:language) {}
9
+
10
+ let(:base_dsl_data) do
11
+ {
12
+ :api => false,
13
+ :api_args => [],
14
+ :api_from_routes => nil,
15
+ :errors => [],
16
+ :tag_list => [],
17
+ :returns => {},
18
+ :params => [],
19
+ :headers => [],
20
+ :resource_id => nil,
21
+ :short_description => nil,
22
+ :description => nil,
23
+ :examples => [],
24
+ :see => [],
25
+ :formats => nil,
26
+ :api_versions => [],
27
+ :meta => nil,
28
+ :show => true,
29
+ :deprecated => false
30
+ }
31
+ end
32
+
33
+ let(:dsl_data) do
34
+ base_dsl_data.merge({
35
+ api_args: [
36
+ [
37
+ http_method,
38
+ path,
39
+ 'description',
40
+ { deprecated: true }
41
+ ]
42
+ ]
43
+ })
44
+ end
45
+
46
+ let(:resource_desc) do
47
+ Apipie::ResourceDescription.new(UsersController, 'dummy')
48
+ end
49
+
50
+ let(:method_desc) do
51
+ Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
52
+ end
53
+
54
+ let(:param_description) do
55
+ Apipie::ParamDescription.new(
56
+ method_desc,
57
+ :param,
58
+ validator,
59
+ param_description_options
60
+ )
61
+ end
62
+
63
+ let(:description_definition) do
64
+ described_class.new(param_description, language: language).to_hash
65
+ end
66
+
67
+ describe 'description' do
68
+ subject { description_definition[:description] }
69
+
70
+ it { is_expected.to be_blank }
71
+
72
+ context 'when desc is given to options' do
73
+ let(:desc) { 'Some description' }
74
+ let(:param_description_options) { { desc: desc } }
75
+
76
+ it { is_expected.to eq(desc) }
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ParamDescription::In do
4
+ let(:validator_options) { {} }
5
+ let(:param_description_options) { {}.merge(validator_options) }
6
+ let(:with_null) { false }
7
+ let(:http_method) { :GET }
8
+ let(:path) { '/api' }
9
+ let(:validator) { String }
10
+ let(:default_in_value) { 'kati' }
11
+ let(:in_schema) { true }
12
+
13
+ let(:base_dsl_data) do
14
+ {
15
+ :api => false,
16
+ :api_args => [],
17
+ :api_from_routes => nil,
18
+ :errors => [],
19
+ :tag_list => [],
20
+ :returns => {},
21
+ :params => [],
22
+ :headers => [],
23
+ :resource_id => nil,
24
+ :short_description => nil,
25
+ :description => nil,
26
+ :examples => [],
27
+ :see => [],
28
+ :formats => nil,
29
+ :api_versions => [],
30
+ :meta => nil,
31
+ :show => true,
32
+ :deprecated => false
33
+ }
34
+ end
35
+
36
+ let(:dsl_data) do
37
+ base_dsl_data.merge({
38
+ api_args: [
39
+ [
40
+ http_method,
41
+ path,
42
+ 'description',
43
+ { deprecated: true }
44
+ ]
45
+ ]
46
+ })
47
+ end
48
+
49
+ let(:resource_desc) do
50
+ Apipie::ResourceDescription.new(UsersController, 'dummy')
51
+ end
52
+
53
+ let(:method_desc) do
54
+ Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
55
+ end
56
+
57
+ let(:param_description) do
58
+ Apipie::ParamDescription.new(
59
+ method_desc,
60
+ :param,
61
+ validator,
62
+ param_description_options
63
+ )
64
+ end
65
+
66
+ let(:in_definition) do
67
+ described_class.new(
68
+ param_description,
69
+ default_in_value: default_in_value,
70
+ http_method: http_method,
71
+ in_schema: in_schema
72
+ ).to_hash
73
+ end
74
+
75
+ describe 'in' do
76
+ subject { in_definition[:in] }
77
+
78
+ it { is_expected.to be_blank }
79
+
80
+ context 'when in_schema is false' do
81
+ let(:in_schema) { false }
82
+
83
+ it { is_expected.to eq(default_in_value) }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ParamDescription::Name do
4
+ let(:validator_options) { {} }
5
+ let(:param_description_options) { {}.merge(validator_options) }
6
+ let(:with_null) { false }
7
+ let(:http_method) { :GET }
8
+ let(:path) { '/api' }
9
+ let(:validator) { String }
10
+ let(:prefixed_by) {}
11
+
12
+ let(:base_dsl_data) do
13
+ {
14
+ :api => false,
15
+ :api_args => [],
16
+ :api_from_routes => nil,
17
+ :errors => [],
18
+ :tag_list => [],
19
+ :returns => {},
20
+ :params => [],
21
+ :headers => [],
22
+ :resource_id => nil,
23
+ :short_description => nil,
24
+ :description => nil,
25
+ :examples => [],
26
+ :see => [],
27
+ :formats => nil,
28
+ :api_versions => [],
29
+ :meta => nil,
30
+ :show => true,
31
+ :deprecated => false
32
+ }
33
+ end
34
+
35
+ let(:dsl_data) do
36
+ base_dsl_data.merge({
37
+ api_args: [
38
+ [
39
+ http_method,
40
+ path,
41
+ 'description',
42
+ { deprecated: true }
43
+ ]
44
+ ]
45
+ })
46
+ end
47
+
48
+ let(:resource_desc) do
49
+ Apipie::ResourceDescription.new(UsersController, 'dummy')
50
+ end
51
+
52
+ let(:method_desc) do
53
+ Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
54
+ end
55
+
56
+ let(:param_description) do
57
+ Apipie::ParamDescription.new(
58
+ method_desc,
59
+ :param,
60
+ validator,
61
+ param_description_options
62
+ )
63
+ end
64
+
65
+ let(:name_definition) do
66
+ described_class.new(
67
+ param_description,
68
+ prefixed_by: prefixed_by
69
+ ).to_hash
70
+ end
71
+
72
+ subject { name_definition[:name] }
73
+
74
+ it { is_expected.to eq(param_description.name) }
75
+
76
+ context 'when prefixed by is given' do
77
+ let(:prefixed_by) { 'some-prefix' }
78
+
79
+ it { is_expected.to eq("#{prefixed_by}[#{param_description.name}]") }
80
+ end
81
+ end