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,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#539 post params given as array' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :issue_539 do
9
+ class Element < Grape::Entity
10
+ expose :id
11
+ expose :description
12
+ expose :role
13
+ end
14
+
15
+ class ArrayOfElements < Grape::Entity
16
+ expose :elements,
17
+ documentation: {
18
+ type: Element, is_array: true, param_type: 'body', required: true
19
+ }
20
+ end
21
+
22
+ desc 'create account',
23
+ params: ArrayOfElements.documentation
24
+ post do
25
+ present params
26
+ end
27
+ end
28
+
29
+ add_swagger_documentation format: :json
30
+ end
31
+ end
32
+
33
+ subject do
34
+ get '/swagger_doc'
35
+ JSON.parse(last_response.body)
36
+ end
37
+
38
+ let(:parameters) { subject['paths']['/issue_539']['post']['parameters'] }
39
+ let(:definitions) { subject['definitions'] }
40
+
41
+ specify do
42
+ expect(parameters).to eql(
43
+ [
44
+ {
45
+ 'in' => 'body', 'name' => 'elements', 'required' => true, 'schema' => {
46
+ 'type' => 'array', 'items' => { '$ref' => '#/definitions/Element' }
47
+ }
48
+ }
49
+ ]
50
+ )
51
+ end
52
+
53
+ specify do
54
+ expect(definitions).to eql(
55
+ 'Element' => {
56
+ 'type' => 'object',
57
+ 'properties' => {
58
+ 'id' => { 'type' => 'string' },
59
+ 'description' => { 'type' => 'string' },
60
+ 'role' => { 'type' => 'string' }
61
+ }
62
+ }
63
+ )
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#542 array of type in post params' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :issue_542 do
9
+ params do
10
+ requires :logs, type: Array[String], documentation: { param_type: 'body' }
11
+ end
12
+
13
+ post do
14
+ present params
15
+ end
16
+ end
17
+
18
+ add_swagger_documentation format: :json
19
+ end
20
+ end
21
+
22
+ subject do
23
+ get '/swagger_doc'
24
+ JSON.parse(last_response.body)
25
+ end
26
+
27
+ let(:parameters) { subject['paths']['/issue_542']['post']['parameters'] }
28
+
29
+ specify do
30
+ expect(parameters).to eql(
31
+ [
32
+ {
33
+ 'in' => 'body',
34
+ 'name' => 'logs',
35
+ 'required' => true,
36
+ 'schema' => {
37
+ 'type' => 'array',
38
+ 'items' => {
39
+ 'type' => 'string'
40
+ }
41
+ }
42
+ }
43
+ ]
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#553 array of type in post/put params' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :in_form_data do
9
+ desc 'create foo' do
10
+ consumes ['application/x-www-form-urlencoded']
11
+ end
12
+ params do
13
+ requires :guid, type: Array[String]
14
+ end
15
+ post do
16
+ # your code goes here
17
+ end
18
+
19
+ desc 'put specific foo' do
20
+ consumes ['application/x-www-form-urlencoded']
21
+ end
22
+ params do
23
+ requires :id
24
+ requires :guid, type: Array[String]
25
+ end
26
+ put ':id' do
27
+ # your code goes here
28
+ end
29
+ end
30
+
31
+ namespace :in_body do
32
+ desc 'create foo' do
33
+ consumes ['application/x-www-form-urlencoded']
34
+ end
35
+ params do
36
+ requires :guid, type: Array[String], documentation: { param_type: 'body' }
37
+ end
38
+ post do
39
+ # your code goes here
40
+ end
41
+
42
+ desc 'put specific foo' do
43
+ consumes ['application/x-www-form-urlencoded']
44
+ end
45
+ params do
46
+ requires :id
47
+ requires :guid, type: Array[String], documentation: { param_type: 'body' }
48
+ end
49
+ put ':id' do
50
+ # your code goes here
51
+ end
52
+ end
53
+
54
+ add_swagger_documentation format: :json
55
+ end
56
+ end
57
+
58
+ subject do
59
+ get '/swagger_doc'
60
+ JSON.parse(last_response.body)
61
+ end
62
+
63
+ describe 'type for Array specified' do
64
+ describe 'in formData' do
65
+ describe 'post request' do
66
+ let(:params) { subject['paths']['/in_form_data']['post']['parameters'] }
67
+
68
+ specify do
69
+ expect(params).to eql([{
70
+ 'in' => 'formData',
71
+ 'name' => 'guid',
72
+ 'type' => 'array',
73
+ 'items' => { 'type' => 'string' },
74
+ 'required' => true
75
+ }])
76
+ end
77
+ end
78
+
79
+ describe 'put request' do
80
+ let(:params) { subject['paths']['/in_form_data/{id}']['put']['parameters'] }
81
+
82
+ specify do
83
+ expect(params).to eql(
84
+ [
85
+ {
86
+ 'in' => 'path',
87
+ 'name' => 'id',
88
+ 'type' => 'string',
89
+ 'required' => true
90
+ },
91
+ {
92
+ 'in' => 'formData',
93
+ 'name' => 'guid',
94
+ 'type' => 'array',
95
+ 'items' => { 'type' => 'string' },
96
+ 'required' => true
97
+ }
98
+ ]
99
+ )
100
+ end
101
+ end
102
+ end
103
+
104
+ describe 'in body' do
105
+ describe 'post request' do
106
+ let(:params) { subject['paths']['/in_body']['post']['parameters'] }
107
+
108
+ specify do
109
+ expect(params).to eql(
110
+ [
111
+ {
112
+ 'in' => 'body',
113
+ 'name' => 'guid',
114
+ 'required' => true,
115
+ 'schema' => {
116
+ 'type' => 'array',
117
+ 'items' => { 'type' => 'string' }
118
+ }
119
+ }
120
+ ]
121
+ )
122
+ end
123
+ end
124
+
125
+ describe 'put request' do
126
+ let(:params) { subject['paths']['/in_body/{id}']['put']['parameters'] }
127
+
128
+ specify do
129
+ expect(params).to eql(
130
+ [
131
+ {
132
+ 'in' => 'path',
133
+ 'name' => 'id',
134
+ 'type' => 'string',
135
+ 'required' => true
136
+ },
137
+ {
138
+ 'in' => 'body',
139
+ 'name' => 'guid',
140
+ 'required' => true,
141
+ 'schema' => {
142
+ 'type' => 'array',
143
+ 'items' => { 'type' => 'string' }
144
+ }
145
+ }
146
+ ]
147
+ )
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#572 is_array is applied to all possible responses' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ let(:app) do
9
+ Class.new(Grape::API) do
10
+ namespace :issue_572 do
11
+ desc 'get issue',
12
+ is_array: true,
13
+ success: Entities::UseResponse,
14
+ failure: [
15
+ [401, 'BadKittenError', Entities::ApiError],
16
+ [404, 'NoTreatsError', Entities::ApiError],
17
+ [429, 'TooManyScratchesError', Entities::ApiError]
18
+ ]
19
+
20
+ get
21
+ end
22
+
23
+ add_swagger_documentation format: :json
24
+ end
25
+ end
26
+
27
+ subject do
28
+ get '/swagger_doc'
29
+ JSON.parse(last_response.body)
30
+ end
31
+
32
+ let(:codes) { %w[200 401 404 429] }
33
+
34
+ let(:responses) { subject['paths']['/issue_572']['get']['responses'] }
35
+
36
+ specify { expect(responses.keys.sort).to eq codes }
37
+
38
+ specify do
39
+ expect(responses['200']['schema']).to include 'type'
40
+ expect(responses['200']['schema']['type']).to eql 'array'
41
+ end
42
+
43
+ describe 'no array types' do
44
+ specify do
45
+ codes[1..-1].each do |code|
46
+ expect(responses[code]['schema']).not_to include 'type'
47
+ expect(responses[code]['schema'].keys).to eql ['$ref']
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#579 put / post parameters spec' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :issue_579 do
9
+ class BodySpec < Grape::Entity
10
+ expose :guid, documentation: { type: String, format: 'guid', in: 'body' }
11
+ expose :name, documentation: { type: String, in: 'body' }
12
+ expose :content, documentation: { type: String, in: 'body' }
13
+ end
14
+
15
+ class Spec < Grape::Entity
16
+ expose :guid, documentation: { type: String, format: 'guid' }
17
+ expose :name, documentation: { type: String }
18
+ expose :content, documentation: { type: String }
19
+ end
20
+
21
+ namespace :implicit do
22
+ namespace :body_parameter do
23
+ desc 'update spec',
24
+ consumes: ['application/x-www-form-urlencoded'],
25
+ success: BodySpec,
26
+ params: BodySpec.documentation
27
+ put ':guid' do
28
+ # your code goes here
29
+ end
30
+ end
31
+
32
+ namespace :form_parameter do
33
+ desc 'update spec',
34
+ consumes: ['application/x-www-form-urlencoded'],
35
+ success: Spec,
36
+ params: Spec.documentation
37
+ put ':guid' do
38
+ # your code goes here
39
+ end
40
+ end
41
+ end
42
+
43
+ namespace :explicit do
44
+ namespace :body_parameter do
45
+ desc 'update spec',
46
+ consumes: ['application/x-www-form-urlencoded'],
47
+ success: BodySpec,
48
+ params: BodySpec.documentation
49
+ params do
50
+ requires :guid
51
+ end
52
+ put ':guid' do
53
+ # your code goes here
54
+ end
55
+ end
56
+
57
+ namespace :form_parameter do
58
+ desc 'update spec',
59
+ consumes: ['application/x-www-form-urlencoded'],
60
+ success: Spec,
61
+ params: Spec.documentation
62
+ params do
63
+ requires :guid
64
+ end
65
+ put ':guid' do
66
+ # your code goes here
67
+ end
68
+ end
69
+ end
70
+
71
+ namespace :namespace_param do
72
+ route_param :guid do
73
+ namespace :body_parameter do
74
+ desc 'update spec',
75
+ consumes: ['application/x-www-form-urlencoded'],
76
+ success: BodySpec,
77
+ params: BodySpec.documentation
78
+ put do
79
+ # your code goes here
80
+ end
81
+ end
82
+
83
+ namespace :form_parameter do
84
+ desc 'update spec',
85
+ consumes: ['application/x-www-form-urlencoded'],
86
+ success: Spec,
87
+ params: Spec.documentation
88
+ put do
89
+ # your code goes here
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ add_swagger_documentation format: :json
97
+ end
98
+ end
99
+
100
+ subject do
101
+ get '/swagger_doc'
102
+ JSON.parse(last_response.body)
103
+ end
104
+
105
+ describe 'implicit path param given' do
106
+ let(:body_parameters) { subject['paths']['/issue_579/implicit/body_parameter/{guid}']['put']['parameters'] }
107
+ specify do
108
+ expect(body_parameters).to eql(
109
+ [
110
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
111
+ {
112
+ 'name' => 'putIssue579ImplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
113
+ '$ref' => '#/definitions/putIssue579ImplicitBodyParameterGuid'
114
+ }
115
+ }
116
+ ]
117
+ )
118
+ end
119
+
120
+ let(:form_parameters) { subject['paths']['/issue_579/implicit/form_parameter/{guid}']['put']['parameters'] }
121
+ specify do
122
+ expect(form_parameters).to eql(
123
+ [
124
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
125
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
126
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
127
+ ]
128
+ )
129
+ end
130
+ end
131
+
132
+ describe 'explicit path param given' do
133
+ let(:body_parameters) { subject['paths']['/issue_579/explicit/body_parameter/{guid}']['put']['parameters'] }
134
+ specify do
135
+ expect(body_parameters).to eql(
136
+ [
137
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
138
+ {
139
+ 'name' => 'putIssue579ExplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
140
+ '$ref' => '#/definitions/putIssue579ExplicitBodyParameterGuid'
141
+ }
142
+ }
143
+ ]
144
+ )
145
+ end
146
+
147
+ let(:form_parameters) { subject['paths']['/issue_579/explicit/form_parameter/{guid}']['put']['parameters'] }
148
+ specify do
149
+ expect(form_parameters).to eql(
150
+ [
151
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
152
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
153
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
154
+ ]
155
+ )
156
+ end
157
+ end
158
+
159
+ describe 'explicit as route param given' do
160
+ let(:body_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/body_parameter']['put']['parameters'] }
161
+ specify do
162
+ expect(body_parameters).to eql(
163
+ [
164
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
165
+ {
166
+ 'name' => 'putIssue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
167
+ '$ref' => '#/definitions/putIssue579NamespaceParamGuidBodyParameter'
168
+ }
169
+ }
170
+ ]
171
+ )
172
+ end
173
+
174
+ let(:form_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/form_parameter']['put']['parameters'] }
175
+ specify do
176
+ expect(form_parameters).to eql(
177
+ [
178
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
179
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
180
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
181
+ ]
182
+ )
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#582 respond with a file' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ let(:app) do
9
+ Class.new(Grape::API) do
10
+ namespace :issue_582 do
11
+ desc 'produces given',
12
+ success: File,
13
+ produces: ['application/pdf', 'text/csv']
14
+ get '/produces_given' do
15
+ 'responds a file'
16
+ end
17
+
18
+ desc 'automatic produces',
19
+ success: 'file'
20
+ get '/automatic_produces' do
21
+ 'responds a file'
22
+ end
23
+ end
24
+
25
+ add_swagger_documentation format: :json
26
+ end
27
+ end
28
+
29
+ subject do
30
+ get '/swagger_doc'
31
+ JSON.parse(last_response.body)
32
+ end
33
+
34
+ describe 'produces given' do
35
+ let(:produces) { subject['paths']['/issue_582/produces_given']['get']['produces'] }
36
+ let(:response) { subject['paths']['/issue_582/produces_given']['get']['responses']['200'] }
37
+
38
+ specify do
39
+ expect(produces).to eql ['application/pdf', 'text/csv']
40
+ expect(response).to include 'schema'
41
+ expect(response['schema']).to eql 'type' => 'file'
42
+ end
43
+ end
44
+
45
+ describe 'automatic_produces' do
46
+ let(:produces) { subject['paths']['/issue_582/automatic_produces']['get']['produces'] }
47
+ let(:response) { subject['paths']['/issue_582/automatic_produces']['get']['responses']['200'] }
48
+
49
+ specify do
50
+ expect(produces).to eql ['application/octet-stream']
51
+ expect(response).to include 'schema'
52
+ expect(response['schema']).to eql 'type' => 'file'
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#587 process route with parameters delimited by dash' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :range_parameter do
9
+ desc 'Get a array with range'
10
+ get '/range/:range_start-:range_end' do
11
+ present []
12
+ end
13
+ end
14
+
15
+ add_swagger_documentation format: :json
16
+ end
17
+ end
18
+
19
+ subject do
20
+ get '/swagger_doc'
21
+ JSON.parse(last_response.body)['paths']
22
+ end
23
+
24
+ specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
25
+ specify { expect(subject['/range_parameter/range/{range_start}-{range_end}']['get']['operationId']).to eql 'getRangeParameterRangeRangeStart-RangeEnd' }
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#605 root route documentation' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ get do
9
+ { message: 'hello world' }
10
+ end
11
+
12
+ add_swagger_documentation format: :json
13
+ end
14
+ end
15
+
16
+ subject do
17
+ get '/swagger_doc'
18
+ JSON.parse(last_response.body)['paths']
19
+ end
20
+
21
+ specify { expect(app.combined_routes.keys).to include '/' }
22
+ specify { expect(subject.keys).to include '/' }
23
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#605 Group Params as Array' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ desc 'array_of_range' do
9
+ consumes ['application/x-www-form-urlencoded']
10
+ end
11
+ params do
12
+ requires :array_of_range_string, type: [String], values: %w[a b c]
13
+ requires :array_of_range_integer, type: [Integer], values: [1, 2, 3]
14
+ end
15
+ post '/array_of_range' do
16
+ { 'declared_params' => declared(params) }
17
+ end
18
+
19
+ desc 'array_with_default' do
20
+ consumes ['application/x-www-form-urlencoded']
21
+ end
22
+ params do
23
+ requires :array_with_default_string, type: [String], default: 'abc'
24
+ requires :array_with_default_integer, type: Array[Integer], default: 123
25
+ end
26
+ post '/array_with_default' do
27
+ { 'declared_params' => declared(params) }
28
+ end
29
+
30
+ add_swagger_documentation
31
+ end
32
+ end
33
+
34
+ describe 'retrieves the documentation for typed group range parameters' do
35
+ subject do
36
+ get '/swagger_doc/array_of_range'
37
+ JSON.parse(last_response.body)
38
+ end
39
+
40
+ specify do
41
+ expect(subject['paths']['/array_of_range']['post']['parameters']).to eql(
42
+ [
43
+ { 'in' => 'formData', 'name' => 'array_of_range_string', 'type' => 'array', 'items' => { 'type' => 'string', 'enum' => %w[a b c] }, 'required' => true },
44
+ { 'in' => 'formData', 'name' => 'array_of_range_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'enum' => [1, 2, 3] }, 'required' => true }
45
+ ]
46
+ )
47
+ end
48
+ end
49
+
50
+ describe 'retrieves the documentation for typed group parameters with default' do
51
+ subject do
52
+ get '/swagger_doc/array_with_default'
53
+ JSON.parse(last_response.body)
54
+ end
55
+
56
+ specify do
57
+ expect(subject['paths']['/array_with_default']['post']['parameters']).to eql(
58
+ [
59
+ { 'in' => 'formData', 'name' => 'array_with_default_string', 'type' => 'array', 'items' => { 'type' => 'string', 'default' => 'abc' }, 'required' => true },
60
+ { 'in' => 'formData', 'name' => 'array_with_default_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'default' => 123 }, 'required' => true }
61
+ ]
62
+ )
63
+ end
64
+ end
65
+ end