gitlab-grape-swagger 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.github/dependabot.yml +20 -0
  4. data/.github/workflows/ci.yml +45 -0
  5. data/.gitignore +44 -0
  6. data/.gitlab-ci.yml +19 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +136 -0
  9. data/.rubocop_todo.yml +60 -0
  10. data/.ruby-gemset +1 -0
  11. data/CHANGELOG.md +671 -0
  12. data/CONTRIBUTING.md +126 -0
  13. data/Dangerfile +3 -0
  14. data/Gemfile +45 -0
  15. data/Gemfile.lock +249 -0
  16. data/LICENSE.txt +20 -0
  17. data/README.md +1772 -0
  18. data/RELEASING.md +82 -0
  19. data/Rakefile +20 -0
  20. data/UPGRADING.md +201 -0
  21. data/example/api/endpoints.rb +131 -0
  22. data/example/api/entities.rb +18 -0
  23. data/example/config.ru +42 -0
  24. data/example/example_requests.postman_collection +146 -0
  25. data/example/splines.png +0 -0
  26. data/example/swagger-example.png +0 -0
  27. data/grape-swagger.gemspec +23 -0
  28. data/lib/grape-swagger/doc_methods/build_model_definition.rb +68 -0
  29. data/lib/grape-swagger/doc_methods/data_type.rb +110 -0
  30. data/lib/grape-swagger/doc_methods/extensions.rb +101 -0
  31. data/lib/grape-swagger/doc_methods/file_params.rb +17 -0
  32. data/lib/grape-swagger/doc_methods/format_data.rb +53 -0
  33. data/lib/grape-swagger/doc_methods/headers.rb +20 -0
  34. data/lib/grape-swagger/doc_methods/move_params.rb +209 -0
  35. data/lib/grape-swagger/doc_methods/operation_id.rb +32 -0
  36. data/lib/grape-swagger/doc_methods/optional_object.rb +30 -0
  37. data/lib/grape-swagger/doc_methods/parse_params.rb +190 -0
  38. data/lib/grape-swagger/doc_methods/path_string.rb +52 -0
  39. data/lib/grape-swagger/doc_methods/produces_consumes.rb +15 -0
  40. data/lib/grape-swagger/doc_methods/status_codes.rb +21 -0
  41. data/lib/grape-swagger/doc_methods/tag_name_description.rb +34 -0
  42. data/lib/grape-swagger/doc_methods/version.rb +20 -0
  43. data/lib/grape-swagger/doc_methods.rb +142 -0
  44. data/lib/grape-swagger/endpoint/params_parser.rb +76 -0
  45. data/lib/grape-swagger/endpoint.rb +476 -0
  46. data/lib/grape-swagger/errors.rb +17 -0
  47. data/lib/grape-swagger/instance.rb +7 -0
  48. data/lib/grape-swagger/model_parsers.rb +42 -0
  49. data/lib/grape-swagger/rake/oapi_tasks.rb +135 -0
  50. data/lib/grape-swagger/version.rb +5 -0
  51. data/lib/grape-swagger.rb +174 -0
  52. data/spec/issues/267_nested_namespaces.rb +55 -0
  53. data/spec/issues/403_versions_spec.rb +124 -0
  54. data/spec/issues/427_entity_as_string_spec.rb +39 -0
  55. data/spec/issues/430_entity_definitions_spec.rb +94 -0
  56. data/spec/issues/532_allow_custom_format_spec.rb +42 -0
  57. data/spec/issues/533_specify_status_code_spec.rb +78 -0
  58. data/spec/issues/537_enum_values_spec.rb +50 -0
  59. data/spec/issues/539_array_post_body_spec.rb +65 -0
  60. data/spec/issues/542_array_of_type_in_post_body_spec.rb +46 -0
  61. data/spec/issues/553_align_array_put_post_params_spec.rb +152 -0
  62. data/spec/issues/572_array_post_body_spec.rb +51 -0
  63. data/spec/issues/579_align_put_post_parameters_spec.rb +185 -0
  64. data/spec/issues/582_file_response_spec.rb +55 -0
  65. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
  66. data/spec/issues/605_root_route_documentation_spec.rb +23 -0
  67. data/spec/issues/650_params_array_spec.rb +65 -0
  68. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
  69. data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
  70. data/spec/issues/721_set_default_parameter_location_based_on_consumes_spec.rb +62 -0
  71. data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
  72. data/spec/issues/776_multiple_presents_spec.rb +59 -0
  73. data/spec/issues/784_extensions_on_params_spec.rb +42 -0
  74. data/spec/issues/809_utf8_routes_spec.rb +55 -0
  75. data/spec/issues/832_array_hash_float_decimal_spec.rb +114 -0
  76. data/spec/issues/847_route_param_options_spec.rb +37 -0
  77. data/spec/issues/873_wildcard_segments_path_parameters_spec.rb +28 -0
  78. data/spec/issues/878_optional_path_segments_spec.rb +29 -0
  79. data/spec/issues/881_handle_file_params_spec.rb +38 -0
  80. data/spec/issues/883_query_array_parameter_spec.rb +46 -0
  81. data/spec/issues/884_dont_document_non_schema_examples_spec.rb +49 -0
  82. data/spec/issues/887_prevent_duplicate_operation_ids_spec.rb +35 -0
  83. data/spec/lib/data_type_spec.rb +111 -0
  84. data/spec/lib/endpoint/params_parser_spec.rb +124 -0
  85. data/spec/lib/endpoint_spec.rb +153 -0
  86. data/spec/lib/extensions_spec.rb +185 -0
  87. data/spec/lib/format_data_spec.rb +115 -0
  88. data/spec/lib/model_parsers_spec.rb +104 -0
  89. data/spec/lib/move_params_spec.rb +444 -0
  90. data/spec/lib/oapi_tasks_spec.rb +163 -0
  91. data/spec/lib/operation_id_spec.rb +55 -0
  92. data/spec/lib/optional_object_spec.rb +47 -0
  93. data/spec/lib/parse_params_spec.rb +68 -0
  94. data/spec/lib/path_string_spec.rb +101 -0
  95. data/spec/lib/produces_consumes_spec.rb +116 -0
  96. data/spec/lib/tag_name_description_spec.rb +80 -0
  97. data/spec/lib/version_spec.rb +28 -0
  98. data/spec/spec_helper.rb +39 -0
  99. data/spec/support/empty_model_parser.rb +23 -0
  100. data/spec/support/grape_version.rb +13 -0
  101. data/spec/support/mock_parser.rb +23 -0
  102. data/spec/support/model_parsers/entity_parser.rb +334 -0
  103. data/spec/support/model_parsers/mock_parser.rb +346 -0
  104. data/spec/support/model_parsers/representable_parser.rb +406 -0
  105. data/spec/support/namespace_tags.rb +93 -0
  106. data/spec/support/the_paths_definitions.rb +109 -0
  107. data/spec/swagger_v2/api_documentation_spec.rb +42 -0
  108. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  109. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +48 -0
  110. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +36 -0
  111. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +79 -0
  112. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +145 -0
  113. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +137 -0
  114. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +56 -0
  115. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +64 -0
  116. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +58 -0
  117. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +57 -0
  118. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +109 -0
  119. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +48 -0
  120. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +153 -0
  121. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +355 -0
  122. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +217 -0
  123. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +247 -0
  124. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +80 -0
  125. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +147 -0
  126. data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +135 -0
  127. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +216 -0
  128. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
  129. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
  130. data/spec/swagger_v2/api_swagger_v2_spec.rb +245 -0
  131. data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +93 -0
  132. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +90 -0
  133. data/spec/swagger_v2/boolean_params_spec.rb +38 -0
  134. data/spec/swagger_v2/default_api_spec.rb +175 -0
  135. data/spec/swagger_v2/deprecated_field_spec.rb +25 -0
  136. data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
  137. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +130 -0
  138. data/spec/swagger_v2/errors_spec.rb +77 -0
  139. data/spec/swagger_v2/float_api_spec.rb +36 -0
  140. data/spec/swagger_v2/form_params_spec.rb +76 -0
  141. data/spec/swagger_v2/grape-swagger_spec.rb +17 -0
  142. data/spec/swagger_v2/guarded_endpoint_spec.rb +162 -0
  143. data/spec/swagger_v2/hide_api_spec.rb +147 -0
  144. data/spec/swagger_v2/host_spec.rb +43 -0
  145. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
  146. data/spec/swagger_v2/mount_override_api_spec.rb +58 -0
  147. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  148. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +122 -0
  149. data/spec/swagger_v2/namespace_tags_spec.rb +78 -0
  150. data/spec/swagger_v2/namespaced_api_spec.rb +121 -0
  151. data/spec/swagger_v2/nicknamed_api_spec.rb +25 -0
  152. data/spec/swagger_v2/operation_id_api_spec.rb +27 -0
  153. data/spec/swagger_v2/param_multi_type_spec.rb +82 -0
  154. data/spec/swagger_v2/param_type_spec.rb +95 -0
  155. data/spec/swagger_v2/param_values_spec.rb +180 -0
  156. data/spec/swagger_v2/params_array_collection_format_spec.rb +105 -0
  157. data/spec/swagger_v2/params_array_spec.rb +225 -0
  158. data/spec/swagger_v2/params_example_spec.rb +38 -0
  159. data/spec/swagger_v2/params_hash_spec.rb +77 -0
  160. data/spec/swagger_v2/params_nested_spec.rb +92 -0
  161. data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
  162. data/spec/swagger_v2/reference_entity_spec.rb +129 -0
  163. data/spec/swagger_v2/security_requirement_spec.rb +46 -0
  164. data/spec/swagger_v2/simple_mounted_api_spec.rb +332 -0
  165. data/spec/version_spec.rb +10 -0
  166. metadata +225 -0
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::OptionalObject do
6
+ subject { described_class }
7
+
8
+ specify { expect(subject).to eql GrapeSwagger::DocMethods::OptionalObject }
9
+ specify { expect(subject).to respond_to :build }
10
+
11
+ describe 'build' do
12
+ let(:key) { :host }
13
+ let!(:request) { Rack::Request.new(Rack::MockRequest.env_for('http://example.com:8080/')) }
14
+
15
+ describe 'no option given for host, take from request' do
16
+ let(:options) { { foo: 'foo' } }
17
+ specify do
18
+ expect(subject.build(key, options, request)).to eql request.host_with_port
19
+ end
20
+ end
21
+
22
+ let(:value) { 'grape-swagger.example.com' }
23
+
24
+ describe 'option is a string' do
25
+ let(:options) { { host: value } }
26
+ specify do
27
+ expect(subject.build(key, options, request)).to eql value
28
+ end
29
+ end
30
+
31
+ describe 'option is a lambda' do
32
+ let(:options) { { host: -> { value } } }
33
+ specify do
34
+ expect(subject.build(key, options, request)).to eql value
35
+ end
36
+ end
37
+
38
+ describe 'option is a proc' do
39
+ let(:options) do
40
+ { host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
41
+ end
42
+ specify do
43
+ expect(subject.build(key, options, request)).to eql '/api-example'
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::ParseParams do
6
+ subject { described_class }
7
+ let(:start_value) { -5 }
8
+ let(:end_value) { 5 }
9
+
10
+ describe '#parse_range_values' do
11
+ specify do
12
+ parsed_range = subject.send(:parse_range_values, start_value..end_value)
13
+ expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
14
+ end
15
+ end
16
+
17
+ describe '#parse_enum_or_range_values' do
18
+ describe 'value as Range' do
19
+ describe 'first Integer' do
20
+ specify do
21
+ parsed_range = subject.send(:parse_enum_or_range_values, start_value..end_value)
22
+ expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
23
+ end
24
+ end
25
+
26
+ describe 'first String' do
27
+ specify do
28
+ parsed_range = subject.send(:parse_enum_or_range_values, 'a'..'z')
29
+ expect(parsed_range).to be_nil
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'value as Proc' do
35
+ describe 'as Range' do
36
+ let(:values) { proc { start_value..end_value } }
37
+ specify do
38
+ parsed_range = subject.send(:parse_enum_or_range_values, values)
39
+ expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
40
+ end
41
+ end
42
+
43
+ describe 'as Array' do
44
+ let(:values) { proc { %w[a b c] } }
45
+ specify do
46
+ parsed_range = subject.send(:parse_enum_or_range_values, values)
47
+ expect(parsed_range).to eql(enum: %w[a b c])
48
+ end
49
+ end
50
+
51
+ describe 'with arity one' do
52
+ let(:values) { proc { |v| v < 25 } }
53
+ specify do
54
+ parsed_range = subject.send(:parse_enum_or_range_values, values)
55
+ expect(parsed_range).to be_nil
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'values as Array -> enums' do
61
+ let(:values) { %w[a b c] }
62
+ specify do
63
+ parsed_range = subject.send(:parse_enum_or_range_values, values)
64
+ expect(parsed_range).to eql(enum: %w[a b c])
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::PathString do
6
+ subject { described_class }
7
+
8
+ specify { expect(subject).to eql GrapeSwagger::DocMethods::PathString }
9
+ specify { expect(subject).to respond_to :build }
10
+
11
+ describe 'path_string_object' do
12
+ specify 'The original route path is not mutated' do
13
+ route = Struct.new(:version, :path).new
14
+ route.path = '/foo/:dynamic/bar'
15
+ subject.build(route, route.path.dup, add_version: true)
16
+ expect(route.path).to eq '/foo/:dynamic/bar'
17
+ end
18
+
19
+ describe 'version' do
20
+ describe 'defaults: given, true' do
21
+ let(:options) { { add_version: true } }
22
+ let(:route) { Struct.new(:version, :path).new('v1') }
23
+
24
+ specify 'The returned path includes version' do
25
+ route.path = '/{version}/thing(.json)'
26
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing']
27
+ route.path = '/{version}/thing/foo(.json)'
28
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo']
29
+ route.path = '/{version}/thing(.:format)'
30
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing']
31
+ route.path = '/{version}/thing/foo(.:format)'
32
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo']
33
+ route.path = '/{version}/thing/:id'
34
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing/{id}']
35
+ route.path = '/{version}/thing/foo/:id'
36
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo/{id}']
37
+ end
38
+ end
39
+
40
+ describe 'defaults: not given, both false' do
41
+ let(:options) { { add_version: false } }
42
+ let(:route) { Struct.new(:version, :path).new }
43
+
44
+ specify 'The returned path does not include version' do
45
+ route.path = '/{version}/thing(.json)'
46
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
47
+ route.path = '/{version}/thing/foo(.json)'
48
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
49
+ route.path = '/{version}/thing(.:format)'
50
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
51
+ route.path = '/{version}/thing/foo(.:format)'
52
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
53
+ route.path = '/{version}/thing/:id'
54
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
55
+ route.path = '/{version}/thing/foo/:id'
56
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
57
+ end
58
+ end
59
+
60
+ describe 'defaults: add_version false' do
61
+ let(:options) { { add_version: false } }
62
+ let(:route) { Struct.new(:version, :path).new('v1') }
63
+
64
+ specify 'The returned path does not include version' do
65
+ route.path = '/{version}/thing(.json)'
66
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
67
+ route.path = '/{version}/thing/foo(.json)'
68
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
69
+ route.path = '/{version}/thing(.:format)'
70
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
71
+ route.path = '/{version}/thing/foo(.:format)'
72
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
73
+ route.path = '/{version}/thing/:id'
74
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
75
+ route.path = '/{version}/thing/foo/:id'
76
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
77
+ end
78
+ end
79
+
80
+ describe 'defaults: root_version nil' do
81
+ let(:options) { { add_version: true } }
82
+ let(:route) { Struct.new(:version, :path).new }
83
+
84
+ specify 'The returned path does not include version' do
85
+ route.path = '/{version}/thing(.json)'
86
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
87
+ route.path = '/{version}/thing/foo(.json)'
88
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
89
+ route.path = '/{version}/thing(.:format)'
90
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
91
+ route.path = '/{version}/thing/foo(.:format)'
92
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
93
+ route.path = '/{version}/thing/:id'
94
+ expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
95
+ route.path = '/{version}/thing/foo/:id'
96
+ expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::ProducesConsumes do
6
+ describe ':json (default)' do
7
+ subject { described_class.call }
8
+
9
+ specify do
10
+ expect(subject).to eql(['application/json'])
11
+ end
12
+ end
13
+
14
+ describe 'accept symbols of' do
15
+ describe 'single' do
16
+ subject { described_class.call(:xml) }
17
+
18
+ specify do
19
+ expect(subject).to eql(['application/xml'])
20
+ end
21
+ end
22
+
23
+ describe 'multiple' do
24
+ subject { described_class.call(:xml, :serializable_hash, :json, :binary, :txt) }
25
+
26
+ specify do
27
+ expect(subject).to eql(
28
+ [
29
+ 'application/xml',
30
+ 'application/json',
31
+ 'application/octet-stream',
32
+ 'text/plain'
33
+ ]
34
+ )
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'accept mime_types of' do
40
+ describe 'single' do
41
+ subject { described_class.call('application/xml') }
42
+
43
+ specify do
44
+ expect(subject).to eql(['application/xml'])
45
+ end
46
+ end
47
+
48
+ describe 'multiple' do
49
+ subject do
50
+ described_class.call(
51
+ 'application/xml',
52
+ 'application/json',
53
+ 'application/octet-stream',
54
+ 'text/plain'
55
+ )
56
+ end
57
+
58
+ specify do
59
+ expect(subject).to eql(
60
+ [
61
+ 'application/xml',
62
+ 'application/json',
63
+ 'application/octet-stream',
64
+ 'text/plain'
65
+ ]
66
+ )
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'mix it up' do
72
+ subject do
73
+ described_class.call(
74
+ :xml,
75
+ :serializable_hash,
76
+ 'application/json',
77
+ 'application/octet-stream',
78
+ :txt
79
+ )
80
+ end
81
+
82
+ specify do
83
+ expect(subject).to eql(
84
+ [
85
+ 'application/xml',
86
+ 'application/json',
87
+ 'application/octet-stream',
88
+ 'text/plain'
89
+ ]
90
+ )
91
+ end
92
+
93
+ subject do
94
+ described_class.call(
95
+ [
96
+ :xml,
97
+ :serializable_hash,
98
+ 'application/json',
99
+ 'application/octet-stream',
100
+ :txt
101
+ ]
102
+ )
103
+ end
104
+
105
+ specify do
106
+ expect(subject).to eql(
107
+ [
108
+ 'application/xml',
109
+ 'application/json',
110
+ 'application/octet-stream',
111
+ 'text/plain'
112
+ ]
113
+ )
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::TagNameDescription do
6
+ describe '#build_memo' do
7
+ let(:tag) { 'some_string' }
8
+ subject { described_class.send(:build_memo, tag) }
9
+
10
+ specify do
11
+ expect(subject.keys).to eql %i[name description]
12
+ expect(subject).to eql(
13
+ name: tag,
14
+ description: "Operations about #{tag.pluralize}"
15
+ )
16
+ end
17
+ end
18
+
19
+ describe '#build' do
20
+ let(:object) { described_class.build(paths) }
21
+
22
+ describe 'empty paths' do
23
+ let(:paths) { {} }
24
+ specify do
25
+ expect(object).to eql([])
26
+ end
27
+ end
28
+
29
+ describe 'paths given' do
30
+ describe 'uniq as String' do
31
+ let(:paths) do
32
+ { key_1: { post: { tags: 'tags_given' } } }
33
+ end
34
+
35
+ specify do
36
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
37
+ end
38
+ end
39
+
40
+ describe 'uniq as Array' do
41
+ let(:paths) do
42
+ { key_1: { post: { tags: ['tags_given'] } } }
43
+ end
44
+
45
+ specify do
46
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
47
+ end
48
+ end
49
+
50
+ describe 'multiple' do
51
+ describe 'uniq key' do
52
+ let(:paths) do
53
+ {
54
+ key_1: { post: { tags: %w[tags_given another_tag_given] } }
55
+ }
56
+ end
57
+
58
+ specify do
59
+ expect(object).to eql [
60
+ { name: 'tags_given', description: 'Operations about tags_givens' },
61
+ { name: 'another_tag_given', description: 'Operations about another_tag_givens' }
62
+ ]
63
+ end
64
+ end
65
+ describe 'under different keys' do
66
+ let(:paths) do
67
+ {
68
+ key_1: { post: { tags: ['tags_given'] } },
69
+ key_2: { post: { tags: ['tags_given'] } }
70
+ }
71
+ end
72
+
73
+ specify do
74
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GrapeSwagger::DocMethods::Version do
6
+ let(:route) { OpenStruct.new(version: version) }
7
+ subject { described_class.get(route) }
8
+
9
+ describe 'grape 0.16.2 version' do
10
+ let(:version) { '[:v1, :v2]' }
11
+ it { is_expected.to be_a Array }
12
+ it { is_expected.to eql %i[v1 v2] }
13
+ end
14
+
15
+ describe 'newer grape versions' do
16
+ describe 'as String' do
17
+ let(:version) { 'v1' }
18
+ it { is_expected.to be_a String }
19
+ it { is_expected.to eql 'v1' }
20
+ end
21
+
22
+ describe 'as Array' do
23
+ let(:version) { %i[v1 v2] }
24
+ it { is_expected.to be_a Array }
25
+ it { is_expected.to eql %i[v1 v2] }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ if RUBY_ENGINE == 'ruby'
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
8
+ Coveralls.wear!
9
+ end
10
+
11
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
12
+
13
+ MODEL_PARSER = ENV.key?('MODEL_PARSER') ? ENV['MODEL_PARSER'].to_s.downcase.sub('grape-swagger-', '') : 'mock'
14
+
15
+ require 'grape'
16
+ require 'grape-swagger'
17
+
18
+ Dir[File.join(Dir.getwd, 'spec/support/*.rb')].each { |f| require f }
19
+ require "grape-swagger/#{MODEL_PARSER}" if MODEL_PARSER != 'mock'
20
+ require File.join(Dir.getwd, "spec/support/model_parsers/#{MODEL_PARSER}_parser.rb")
21
+
22
+ require 'grape-entity'
23
+ require 'grape-swagger-entity'
24
+
25
+ Bundler.setup :default, :test
26
+
27
+ require 'rack'
28
+ require 'rack/test'
29
+
30
+ RSpec.configure do |config|
31
+ require 'rspec/expectations'
32
+ config.include RSpec::Matchers
33
+ config.mock_with :rspec
34
+ config.include Rack::Test::Methods
35
+ config.raise_errors_for_deprecations!
36
+
37
+ config.order = 'random'
38
+ config.seed = 40_834
39
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Lint/EmptyClass
4
+ class EmptyClass
5
+ end
6
+ # rubocop:enable Lint/EmptyClass
7
+
8
+ module GrapeSwagger
9
+ class EmptyModelParser
10
+ attr_reader :model, :endpoint
11
+
12
+ def initialize(model, endpoint)
13
+ @model = model
14
+ @endpoint = endpoint
15
+ end
16
+
17
+ def call
18
+ {}
19
+ end
20
+ end
21
+ end
22
+
23
+ GrapeSwagger.model_parsers.register(GrapeSwagger::EmptyModelParser, EmptyClass)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GrapeVersion
4
+ class << self
5
+ def current_version
6
+ Grape::VERSION
7
+ end
8
+
9
+ def satisfy?(requirement)
10
+ Gem::Dependency.new('grape-test', requirement).match?('grape-test', current_version)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GrapeSwagger
4
+ class MockParser
5
+ attr_reader :model, :endpoint
6
+
7
+ def initialize(model, endpoint)
8
+ @model = model
9
+ @endpoint = endpoint
10
+ end
11
+
12
+ def call
13
+ {
14
+ mock_data: {
15
+ type: :string,
16
+ description: "it's a mock"
17
+ }
18
+ }
19
+ end
20
+ end
21
+ end
22
+
23
+ GrapeSwagger.model_parsers.register(GrapeSwagger::MockParser, OpenStruct)