apipie-rails 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +2 -2
  3. data/.rubocop.yml +23 -14
  4. data/.rubocop_todo.yml +103 -487
  5. data/CHANGELOG.md +20 -3
  6. data/README.rst +12 -12
  7. data/app/controllers/apipie/apipies_controller.rb +6 -6
  8. data/app/helpers/apipie_helper.rb +1 -1
  9. data/lib/apipie/apipie_module.rb +5 -5
  10. data/lib/apipie/application.rb +81 -55
  11. data/lib/apipie/configuration.rb +19 -26
  12. data/lib/apipie/dsl_definition.rb +8 -9
  13. data/lib/apipie/error_description.rb +1 -1
  14. data/lib/apipie/errors.rb +2 -16
  15. data/lib/apipie/extractor/collector.rb +3 -3
  16. data/lib/apipie/extractor/recorder.rb +1 -1
  17. data/lib/apipie/extractor.rb +2 -2
  18. data/lib/apipie/generator/config.rb +12 -0
  19. data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
  20. data/lib/apipie/generator/swagger/config.rb +78 -0
  21. data/lib/apipie/generator/swagger/context.rb +12 -1
  22. data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
  23. data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +86 -0
  24. data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
  25. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
  26. data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
  27. data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
  28. data/lib/apipie/generator/swagger/method_description.rb +2 -0
  29. data/lib/apipie/generator/swagger/operation_id.rb +2 -2
  30. data/lib/apipie/generator/swagger/param_description/builder.rb +4 -4
  31. data/lib/apipie/generator/swagger/param_description/composite.rb +9 -1
  32. data/lib/apipie/generator/swagger/param_description/in.rb +1 -1
  33. data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
  34. data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
  35. data/lib/apipie/generator/swagger/param_description/type.rb +9 -2
  36. data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
  37. data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
  38. data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
  39. data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
  40. data/lib/apipie/generator/swagger/schema.rb +63 -0
  41. data/lib/apipie/generator/swagger/type_extractor.rb +0 -19
  42. data/lib/apipie/generator/swagger/warning.rb +3 -6
  43. data/lib/apipie/generator/swagger/warning_writer.rb +7 -1
  44. data/lib/apipie/helpers.rb +3 -3
  45. data/lib/apipie/method_description.rb +5 -3
  46. data/lib/apipie/param_description.rb +4 -2
  47. data/lib/apipie/resource_description.rb +11 -8
  48. data/lib/apipie/response_description.rb +1 -1
  49. data/lib/apipie/response_description_adapter.rb +3 -3
  50. data/lib/apipie/routing.rb +1 -1
  51. data/lib/apipie/rspec/response_validation_helper.rb +1 -1
  52. data/lib/apipie/swagger_generator.rb +27 -551
  53. data/lib/apipie/validator.rb +9 -5
  54. data/lib/apipie/version.rb +1 -1
  55. data/lib/apipie-rails.rb +17 -0
  56. data/lib/tasks/apipie.rake +25 -20
  57. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +2 -2
  58. data/spec/controllers/pets_controller_spec.rb +10 -16
  59. data/spec/controllers/users_controller_spec.rb +2 -2
  60. data/spec/dummy/app/controllers/pets_controller.rb +4 -4
  61. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  62. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  63. data/spec/dummy/app/controllers/users_controller.rb +5 -5
  64. data/spec/dummy/config.ru +1 -1
  65. data/spec/lib/apipie/apipies_controller_spec.rb +4 -0
  66. data/spec/lib/apipie/application_spec.rb +25 -15
  67. data/spec/lib/apipie/configuration_spec.rb +15 -0
  68. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  69. data/spec/lib/apipie/generator/swagger/context_spec.rb +23 -2
  70. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +106 -0
  71. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  72. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +1 -1
  73. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +2 -2
  74. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +7 -7
  75. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  76. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  77. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  78. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  79. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  80. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +0 -43
  81. data/spec/lib/apipie/generator/swagger/warning_spec.rb +1 -1
  82. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +19 -7
  83. data/spec/lib/apipie/method_description_spec.rb +101 -66
  84. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  85. data/spec/lib/apipie/param_description_spec.rb +209 -49
  86. data/spec/lib/apipie/param_group_spec.rb +1 -0
  87. data/spec/lib/apipie/resource_description_spec.rb +71 -28
  88. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  89. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  90. data/spec/lib/apipie/validator_spec.rb +47 -11
  91. data/spec/lib/rake_spec.rb +1 -1
  92. data/spec/lib/swagger/rake_swagger_spec.rb +6 -6
  93. data/spec/lib/swagger/swagger_dsl_spec.rb +17 -11
  94. data/spec/lib/validators/array_validator_spec.rb +1 -1
  95. data/spec/spec_helper.rb +2 -2
  96. metadata +31 -3
@@ -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'
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]
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
@@ -10,7 +10,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
10
10
  described_class.new(
11
11
  param_description,
12
12
  in_schema: in_schema,
13
- controller_method: 'show'
13
+ controller_method: method_desc
14
14
  )
15
15
  end
16
16
  let(:generated_block) { builder.to_swagger }
@@ -13,7 +13,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Composite do
13
13
  Apipie::Generator::Swagger::Context.new(
14
14
  allow_null: true,
15
15
  http_method: 'get',
16
- controller_method: 'show'
16
+ controller_method: method_description
17
17
  )
18
18
  end
19
19
 
@@ -50,7 +50,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Composite do
50
50
 
51
51
  context 'when additional properties in response allowed' do
52
52
  before do
53
- Apipie.configuration.swagger_allow_additional_properties_in_response = true
53
+ Apipie.configuration.generator.swagger.allow_additional_properties_in_response = true
54
54
  end
55
55
 
56
56
  it { is_expected.to be_blank }
@@ -75,7 +75,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
75
75
  it { is_expected.to eq(validator.to_s.downcase) }
76
76
 
77
77
  context 'when validator is enum' do
78
- let(:validator) { ['name', 'enum'] }
78
+ let(:validator) { %w[name enum] }
79
79
 
80
80
  it { is_expected.to eq('string') }
81
81
  end
@@ -108,9 +108,9 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
108
108
 
109
109
  it { is_expected.to eq({ type: 'string' }) }
110
110
 
111
- context 'and swagger_json_input_uses_refs is set to true' do
112
- before { Apipie.configuration.swagger_json_input_uses_refs = true }
113
- after { Apipie.configuration.swagger_json_input_uses_refs = false }
111
+ context 'and swagger.json_input_uses_refs is set to true' do
112
+ before { Apipie.configuration.generator.swagger.json_input_uses_refs = true }
113
+ after { Apipie.configuration.generator.swagger.json_input_uses_refs = false }
114
114
 
115
115
  it 'returns the reference' do
116
116
  expect(subject).to eq({ '$ref' => reference })
@@ -130,8 +130,8 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
130
130
  it { is_expected.to be_blank }
131
131
 
132
132
  context 'and an array of in values is given' do
133
- let(:enum_values) { ['enum-value-1', 'enum-value-2'] }
134
- let(:validator_options) { { in: ['enum-value-1', 'enum-value-2'] } }
133
+ let(:enum_values) { %w[enum-value-1 enum-value-2] }
134
+ let(:validator_options) { { in: %w[enum-value-1 enum-value-2] } }
135
135
 
136
136
  it { is_expected.to eq(enum_values) }
137
137
  end
@@ -144,7 +144,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
144
144
  subject { type_definition[:enum] }
145
145
 
146
146
  context 'and an array of in values is given' do
147
- let(:validator) { ['enum-value-1', 'enum-value-2'] }
147
+ let(:validator) { %w[enum-value-1 enum-value-2] }
148
148
 
149
149
  it { is_expected.to eq(validator) }
150
150
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::PathDecorator do
4
+ let(:decorated_path) { described_class.new(path) }
5
+
6
+ describe '#param_names' do
7
+ subject { decorated_path.param_names }
8
+
9
+ context 'when path does not contain any params' do
10
+ let(:path) { 'some/path/without_params' }
11
+
12
+ it { is_expected.to be_empty }
13
+ end
14
+
15
+ context 'when path has a param' do
16
+ let(:path) { '/:resource_id/custom' }
17
+
18
+ it { is_expected.to eq([:resource_id]) }
19
+ end
20
+ end
21
+
22
+ describe '#param?' do
23
+ subject { decorated_path.param?(param) }
24
+
25
+ context 'when path has params' do
26
+ let(:path) { '/:resource_id/custom' }
27
+
28
+ context 'when param to check is in the path' do
29
+ let(:param) { :resource_id }
30
+
31
+ it { is_expected.to be(true) }
32
+ end
33
+
34
+ context 'when param to check is not in the path' do
35
+ let(:param) { :some_param }
36
+
37
+ it { is_expected.to be(false) }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#swagger_path' do
43
+ subject(:swagger_path) { decorated_path.swagger_path }
44
+
45
+ let(:path) { '/some/custom/path' }
46
+
47
+ it { is_expected.to eq('/some/custom/path') }
48
+
49
+ context 'when path does not start with slash' do
50
+ let(:path) { ':resource_id/custom' }
51
+
52
+ it 'adds the slash in the beginning' do
53
+ expect(swagger_path).to eq('/{resource_id}/custom')
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ReferencedDefinitions do
4
+ let(:definitions) { described_class.instance }
5
+
6
+ before { Singleton.__init__(described_class) }
7
+
8
+ describe '.add!' do
9
+ subject(:add_call) { definitions.add!(param_type, schema) }
10
+
11
+ let(:param_type) { :some_type }
12
+ let(:schema) { { key: 'value' } }
13
+
14
+ it 'returns add the definition' do
15
+ expect { add_call }
16
+ .to change(definitions, :definitions)
17
+ .from({})
18
+ .to({ param_type => schema })
19
+ end
20
+ end
21
+
22
+ describe '.added?' do
23
+ subject { definitions.added?(param_type) }
24
+
25
+ let(:param_type) { :some_type }
26
+
27
+ it { is_expected.to be_blank }
28
+
29
+ context 'when definition exists' do
30
+ before { definitions.add!(param_type, {}) }
31
+
32
+ it { is_expected.to be(true) }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ResourceDescriptionComposite do
4
+ let(:dsl_data) { {} }
5
+ let(:resource_id) { 'pets' }
6
+ let(:resource_description) do
7
+ Apipie::ResourceDescription.new(PetsController, resource_id, dsl_data)
8
+ end
9
+
10
+ let(:resource_descriptions) { [resource_description] }
11
+ let(:composite) { described_class.new(resource_descriptions, language: :en) }
12
+
13
+ describe '#to-swagger' do
14
+ subject { composite.to_swagger }
15
+
16
+ it { is_expected.to include(:paths, :tags) }
17
+
18
+ describe 'tags' do
19
+ subject(:tag) { composite.to_swagger[:tags].first }
20
+
21
+ it { is_expected.to be_blank }
22
+
23
+ context 'when resource description has full description' do
24
+ let(:dsl_data) { { description: 'something' } }
25
+
26
+ it 'returns the name and description' do
27
+ expect(tag).to eq(
28
+ {
29
+ name: resource_id,
30
+ description: resource_description._full_description
31
+ }
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::ResourceDescriptionsCollection do
4
+ let(:collection) { described_class.new(resource_descriptions) }
5
+
6
+ let(:users_resource_description) do
7
+ Apipie.get_resource_description(UsersController, Apipie.configuration.default_version)
8
+ end
9
+
10
+ let(:pets_resource_description) do
11
+ Apipie.get_resource_description(PetsController, Apipie.configuration.default_version)
12
+ end
13
+
14
+ let(:resource_descriptions) do
15
+ {
16
+ 'development' => {
17
+ users_resource_description._id => users_resource_description,
18
+ pets_resource_description._id => pets_resource_description
19
+ },
20
+ 'production' => {
21
+ pets_resource_description._id => pets_resource_description
22
+ }
23
+ }
24
+ end
25
+
26
+ describe '#filter' do
27
+ subject(:filtered_resource_descriptions) do
28
+ collection.filter(
29
+ version: version,
30
+ resource_id: resource_id,
31
+ method_name: method_name
32
+ )
33
+ end
34
+
35
+ let(:version) { 'development' }
36
+ let(:resource_id) { users_resource_description._id }
37
+ let(:method_name) { nil }
38
+
39
+ it 'filters resources for the given version and resource name' do
40
+ expect(filtered_resource_descriptions).to eq([users_resource_description])
41
+ end
42
+
43
+ context 'when method name is given' do
44
+ context 'when does not exist in the controller' do
45
+ let(:method_name) { :i_do_not_exist }
46
+
47
+ it { is_expected.to be_empty }
48
+ end
49
+
50
+ context 'when exists in the controller' do
51
+ let(:method_name) { :show }
52
+
53
+ it { is_expected.to eq([users_resource_description]) }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::Schema do
4
+ let(:version) { :ok }
5
+ let(:language) { :ok }
6
+ let(:clear_warnings) { :ok }
7
+ let(:dsl_data) { {} }
8
+ let(:resource_id) { 'pets' }
9
+ let(:resource_descriptions) { [resource_description] }
10
+
11
+ let(:resource_description) do
12
+ Apipie::ResourceDescription.new(PetsController, resource_id, dsl_data)
13
+ end
14
+
15
+ let(:schema_generator) do
16
+ described_class.new(
17
+ resource_descriptions,
18
+ version: version,
19
+ language: language,
20
+ clear_warnings: clear_warnings
21
+ )
22
+ end
23
+
24
+ describe '#generate' do
25
+ subject(:schema) { schema_generator.generate }
26
+
27
+ describe 'host' do
28
+ before { Apipie.configuration.generator.swagger.api_host = nil }
29
+
30
+ it 'is not returned' do
31
+ expect(schema.keys).not_to include(:host)
32
+ end
33
+
34
+ context 'when api_host is set' do
35
+ let(:host) { 'localhost:3000' }
36
+
37
+ before { Apipie.configuration.generator.swagger.api_host = host }
38
+
39
+ it 'returns the host' do
40
+ expect(schema[:host]).to eq(host)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'consumes' do
46
+ subject { schema_generator.generate[:consumes] }
47
+
48
+ before { Apipie.configuration.generator.swagger.content_type_input = nil }
49
+
50
+ it { is_expected.to eq(['application/x-www-form-urlencoded', 'multipart/form-data']) }
51
+
52
+ context 'when swagger.content_type_input is set to json' do
53
+ before { Apipie.configuration.generator.swagger.content_type_input = :json }
54
+
55
+ it { is_expected.to eq(['application/json']) }
56
+ end
57
+ end
58
+
59
+ describe 'title' do
60
+ subject { schema_generator.generate[:info][:title] }
61
+
62
+ before { Apipie.configuration.generator.swagger.content_type_input = nil }
63
+
64
+ it { is_expected.to include(' (params in:formData)') }
65
+
66
+ context 'when swagger.content_type_input is set to json' do
67
+ before { Apipie.configuration.generator.swagger.content_type_input = :json }
68
+
69
+ it { is_expected.to include(' (params in:body)') }
70
+ end
71
+ end
72
+
73
+ describe 'x-computed-id' do
74
+ subject(:schema) { schema_generator.generate[:info] }
75
+
76
+ before { Apipie.configuration.generator.swagger.generate_x_computed_id_field = false }
77
+
78
+ it 'is not returned' do
79
+ expect(schema.keys).not_to include('x-computed-id')
80
+ end
81
+
82
+ context 'when swagger.content_type_input is set to json' do
83
+ before { Apipie.configuration.generator.swagger.generate_x_computed_id_field = true }
84
+
85
+ it { is_expected.to include('x-computed-id') }
86
+ end
87
+ end
88
+ end
89
+ end
@@ -26,15 +26,6 @@ describe Apipie::Generator::Swagger::TypeExtractor do
26
26
  it 'returns an enum type' do
27
27
  expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:enum])
28
28
  end
29
-
30
- context 'and has `true`, `false` as values' do
31
- let(:param_description_name) { :visible }
32
- let(:enum_values) { [true, false] }
33
-
34
- it 'returns a boolean type' do
35
- expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:boolean])
36
- end
37
- end
38
29
  end
39
30
  end
40
31
  end
@@ -44,38 +35,4 @@ describe Apipie::Generator::Swagger::TypeExtractor do
44
35
 
45
36
  it_behaves_like 'extractable method'
46
37
  end
47
-
48
- describe '#extarct_with_warnings' do
49
- before { Apipie.configuration.swagger_suppress_warnings = false }
50
-
51
- subject { extractor.extract_with_warnings(warnings) }
52
-
53
- it_behaves_like 'extractable method'
54
-
55
- context "when enum validator is used" do
56
- context "and has `true`, `false` as values" do
57
- let(:enum_values) { [true, false] }
58
-
59
- let(:validator) do
60
- Apipie::ResponseDescriptionAdapter::PropDesc::Validator.new('some-type', enum_values)
61
- end
62
-
63
- context 'and a boolean warning is passed' do
64
- let(:boolean_warning) do
65
- Apipie::Generator::Swagger::Warning.for_code(
66
- Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
67
- 'SampleController#action',
68
- { parameter: 'some-param' }
69
- )
70
- end
71
-
72
- let(:warnings) { { boolean: boolean_warning } }
73
-
74
- it 'outputs the warning' do
75
- expect { subject }.to output(boolean_warning.warning_message).to_stderr
76
- end
77
- end
78
- end
79
- end
80
- end
81
38
  end
@@ -16,7 +16,7 @@ describe Apipie::Generator::Swagger::Warning do
16
16
  describe '#warning_message' do
17
17
  subject { warning.warning_message }
18
18
 
19
- it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}") }
19
+ it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}\n") }
20
20
  end
21
21
 
22
22
  describe '#warn' do
@@ -5,14 +5,14 @@ describe Apipie::Generator::Swagger::WarningWriter do
5
5
 
6
6
  let(:warning) do
7
7
  Apipie::Generator::Swagger::Warning.for_code(
8
- Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
8
+ Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE,
9
9
  'SampleController#action',
10
10
  { parameter: 'some-param' }
11
11
  )
12
12
  end
13
13
 
14
14
  before do
15
- Apipie.configuration.swagger_suppress_warnings = false
15
+ Apipie.configuration.generator.swagger.suppress_warnings = false
16
16
  Singleton.__init__(described_class)
17
17
  end
18
18
 
@@ -23,16 +23,16 @@ describe Apipie::Generator::Swagger::WarningWriter do
23
23
  expect { subject }.to output(warning.warning_message).to_stderr
24
24
  end
25
25
 
26
- context 'when Apipie.configuration.swagger_suppress_warnings is true' do
27
- before { Apipie.configuration.swagger_suppress_warnings = true }
26
+ context 'when Apipie.configuration.generator.swagger.suppress_warnings is true' do
27
+ before { Apipie.configuration.generator.swagger.suppress_warnings = true }
28
28
 
29
29
  it { is_expected.to be_falsey }
30
30
  end
31
31
 
32
- context 'when Apipie.configuration.swagger_suppress_warnings includes warning code' do
32
+ context 'when Apipie.configuration.generator.swagger.suppress_warnings includes warning code' do
33
33
  before do
34
- Apipie.configuration.swagger_suppress_warnings =
35
- Array(Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE)
34
+ Apipie.configuration.generator.swagger.suppress_warnings =
35
+ Array(Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE)
36
36
  end
37
37
 
38
38
  it { is_expected.to be_falsey }
@@ -56,4 +56,16 @@ describe Apipie::Generator::Swagger::WarningWriter do
56
56
  it { is_expected.to be_truthy }
57
57
  end
58
58
  end
59
+
60
+ describe '#clear!' do
61
+ subject { writer.clear! }
62
+
63
+ context 'when writer has issued warnings' do
64
+ before { writer.warn(warning) }
65
+
66
+ it 'removes issued warnings' do
67
+ expect { subject }.to change(writer, :issued_warnings?).from(true).to(false)
68
+ end
69
+ end
70
+ end
59
71
  end