grape-swagger 1.6.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -1
  3. data/README.md +1 -0
  4. data/grape-swagger.gemspec +5 -5
  5. data/lib/grape-swagger/doc_methods/extensions.rb +2 -1
  6. data/lib/grape-swagger/doc_methods/move_params.rb +1 -0
  7. data/lib/grape-swagger/endpoint.rb +1 -1
  8. data/lib/grape-swagger/version.rb +1 -1
  9. metadata +26 -129
  10. data/.coveralls.yml +0 -1
  11. data/.github/dependabot.yml +0 -20
  12. data/.github/workflows/ci.yml +0 -120
  13. data/.gitignore +0 -45
  14. data/.rspec +0 -3
  15. data/.rubocop.yml +0 -136
  16. data/.rubocop_todo.yml +0 -45
  17. data/Dangerfile +0 -3
  18. data/Gemfile +0 -43
  19. data/Rakefile +0 -20
  20. data/example/api/endpoints.rb +0 -131
  21. data/example/api/entities.rb +0 -18
  22. data/example/config.ru +0 -42
  23. data/example/example_requests.postman_collection +0 -146
  24. data/example/splines.png +0 -0
  25. data/example/swagger-example.png +0 -0
  26. data/spec/issues/267_nested_namespaces.rb +0 -55
  27. data/spec/issues/403_versions_spec.rb +0 -124
  28. data/spec/issues/427_entity_as_string_spec.rb +0 -39
  29. data/spec/issues/430_entity_definitions_spec.rb +0 -94
  30. data/spec/issues/532_allow_custom_format_spec.rb +0 -38
  31. data/spec/issues/533_specify_status_code_spec.rb +0 -78
  32. data/spec/issues/537_enum_values_spec.rb +0 -50
  33. data/spec/issues/539_array_post_body_spec.rb +0 -65
  34. data/spec/issues/542_array_of_type_in_post_body_spec.rb +0 -46
  35. data/spec/issues/553_align_array_put_post_params_spec.rb +0 -144
  36. data/spec/issues/572_array_post_body_spec.rb +0 -51
  37. data/spec/issues/579_align_put_post_parameters_spec.rb +0 -179
  38. data/spec/issues/582_file_response_spec.rb +0 -55
  39. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +0 -26
  40. data/spec/issues/605_root_route_documentation_spec.rb +0 -23
  41. data/spec/issues/650_params_array_spec.rb +0 -59
  42. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +0 -100
  43. data/spec/issues/680_keep_204_error_schemas_spec.rb +0 -55
  44. data/spec/issues/751_deeply_nested_objects_spec.rb +0 -190
  45. data/spec/issues/776_multiple_presents_spec.rb +0 -59
  46. data/spec/issues/784_extensions_on_params_spec.rb +0 -38
  47. data/spec/issues/809_utf8_routes_spec.rb +0 -55
  48. data/spec/issues/832_array_hash_float_decimal_spec.rb +0 -111
  49. data/spec/issues/847_route_param_options_spec.rb +0 -37
  50. data/spec/lib/data_type_spec.rb +0 -111
  51. data/spec/lib/endpoint/params_parser_spec.rb +0 -124
  52. data/spec/lib/endpoint_spec.rb +0 -153
  53. data/spec/lib/extensions_spec.rb +0 -185
  54. data/spec/lib/format_data_spec.rb +0 -115
  55. data/spec/lib/model_parsers_spec.rb +0 -104
  56. data/spec/lib/move_params_spec.rb +0 -444
  57. data/spec/lib/oapi_tasks_spec.rb +0 -163
  58. data/spec/lib/operation_id_spec.rb +0 -55
  59. data/spec/lib/optional_object_spec.rb +0 -47
  60. data/spec/lib/parse_params_spec.rb +0 -82
  61. data/spec/lib/path_string_spec.rb +0 -101
  62. data/spec/lib/produces_consumes_spec.rb +0 -116
  63. data/spec/lib/tag_name_description_spec.rb +0 -80
  64. data/spec/lib/version_spec.rb +0 -28
  65. data/spec/spec_helper.rb +0 -39
  66. data/spec/support/empty_model_parser.rb +0 -23
  67. data/spec/support/grape_version.rb +0 -13
  68. data/spec/support/mock_parser.rb +0 -23
  69. data/spec/support/model_parsers/entity_parser.rb +0 -334
  70. data/spec/support/model_parsers/mock_parser.rb +0 -346
  71. data/spec/support/model_parsers/representable_parser.rb +0 -406
  72. data/spec/support/namespace_tags.rb +0 -93
  73. data/spec/support/the_paths_definitions.rb +0 -109
  74. data/spec/swagger_v2/api_documentation_spec.rb +0 -26
  75. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +0 -83
  76. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +0 -48
  77. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +0 -36
  78. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +0 -79
  79. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +0 -145
  80. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +0 -137
  81. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +0 -56
  82. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +0 -64
  83. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +0 -58
  84. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +0 -57
  85. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +0 -103
  86. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +0 -48
  87. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +0 -145
  88. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +0 -355
  89. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +0 -217
  90. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +0 -239
  91. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +0 -72
  92. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +0 -143
  93. data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +0 -135
  94. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +0 -216
  95. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +0 -55
  96. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +0 -153
  97. data/spec/swagger_v2/api_swagger_v2_spec.rb +0 -237
  98. data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +0 -93
  99. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +0 -89
  100. data/spec/swagger_v2/boolean_params_spec.rb +0 -35
  101. data/spec/swagger_v2/default_api_spec.rb +0 -175
  102. data/spec/swagger_v2/deprecated_field_spec.rb +0 -25
  103. data/spec/swagger_v2/description_not_initialized_spec.rb +0 -39
  104. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +0 -130
  105. data/spec/swagger_v2/errors_spec.rb +0 -77
  106. data/spec/swagger_v2/float_api_spec.rb +0 -33
  107. data/spec/swagger_v2/form_params_spec.rb +0 -67
  108. data/spec/swagger_v2/grape-swagger_spec.rb +0 -17
  109. data/spec/swagger_v2/guarded_endpoint_spec.rb +0 -162
  110. data/spec/swagger_v2/hide_api_spec.rb +0 -147
  111. data/spec/swagger_v2/host_spec.rb +0 -43
  112. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +0 -57
  113. data/spec/swagger_v2/mount_override_api_spec.rb +0 -58
  114. data/spec/swagger_v2/mounted_target_class_spec.rb +0 -76
  115. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +0 -122
  116. data/spec/swagger_v2/namespace_tags_spec.rb +0 -78
  117. data/spec/swagger_v2/namespaced_api_spec.rb +0 -121
  118. data/spec/swagger_v2/nicknamed_api_spec.rb +0 -25
  119. data/spec/swagger_v2/operation_id_api_spec.rb +0 -27
  120. data/spec/swagger_v2/param_multi_type_spec.rb +0 -77
  121. data/spec/swagger_v2/param_type_spec.rb +0 -87
  122. data/spec/swagger_v2/param_values_spec.rb +0 -162
  123. data/spec/swagger_v2/params_array_collection_format_spec.rb +0 -105
  124. data/spec/swagger_v2/params_array_spec.rb +0 -203
  125. data/spec/swagger_v2/params_example_spec.rb +0 -40
  126. data/spec/swagger_v2/params_hash_spec.rb +0 -71
  127. data/spec/swagger_v2/params_nested_spec.rb +0 -86
  128. data/spec/swagger_v2/parent_less_namespace_spec.rb +0 -32
  129. data/spec/swagger_v2/reference_entity_spec.rb +0 -129
  130. data/spec/swagger_v2/security_requirement_spec.rb +0 -46
  131. data/spec/swagger_v2/simple_mounted_api_spec.rb +0 -326
  132. data/spec/version_spec.rb +0 -10
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'parsing additional_parameters' do
6
- let(:app) do
7
- Class.new(Grape::API) do
8
- namespace :things do
9
- class Element < Grape::Entity
10
- expose :id
11
- end
12
-
13
- params do
14
- optional :closed, type: Hash, documentation: { additional_properties: false, in: 'body' } do
15
- requires :only
16
- end
17
- optional :open, type: Hash, documentation: { additional_properties: true }
18
- optional :type_limited, type: Hash, documentation: { additional_properties: String }
19
- optional :ref_limited, type: Hash, documentation: { additional_properties: Element }
20
- optional :fallback, type: Hash, documentation: { additional_properties: { type: 'integer' } }
21
- end
22
- post do
23
- present params
24
- end
25
- end
26
-
27
- add_swagger_documentation format: :json, models: [Element]
28
- end
29
- end
30
-
31
- subject do
32
- get '/swagger_doc/things'
33
- JSON.parse(last_response.body)
34
- end
35
-
36
- describe 'POST' do
37
- specify do
38
- expect(subject.dig('paths', '/things', 'post', 'parameters')).to eql(
39
- [
40
- { 'name' => 'postThings', 'in' => 'body', 'required' => true, 'schema' => { '$ref' => '#/definitions/postThings' } }
41
- ]
42
- )
43
- end
44
-
45
- specify do
46
- expect(subject.dig('definitions', 'postThings')).to eql(
47
- 'type' => 'object',
48
- 'properties' => {
49
- 'closed' => {
50
- 'type' => 'object',
51
- 'additionalProperties' => false,
52
- 'properties' => {
53
- 'only' => { 'type' => 'string' }
54
- },
55
- 'required' => ['only']
56
- },
57
- 'open' => {
58
- 'type' => 'object',
59
- 'additionalProperties' => true
60
- },
61
- 'type_limited' => {
62
- 'type' => 'object',
63
- 'additionalProperties' => {
64
- 'type' => 'string'
65
- }
66
- },
67
- 'ref_limited' => {
68
- 'type' => 'object',
69
- 'additionalProperties' => {
70
- '$ref' => '#/definitions/Element'
71
- }
72
- },
73
- 'fallback' => {
74
- 'type' => 'object',
75
- 'additionalProperties' => {
76
- 'type' => 'integer'
77
- }
78
- }
79
- }
80
- )
81
- end
82
- end
83
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'body parameter definitions' do
6
- before :all do
7
- module TheBodyApi
8
- class Endpoint < Grape::API
9
- resource :endpoint do
10
- desc 'The endpoint' do
11
- headers XAuthToken: {
12
- description: 'Valdates your identity',
13
- required: true
14
- }
15
- params body_param: { type: 'String', desc: 'param', documentation: { in: 'body' } },
16
- body_type_as_const_param: { type: String, desc: 'string_param', documentation: { in: 'body' } }
17
- end
18
-
19
- post do
20
- { 'declared_params' => declared(params) }
21
- end
22
- end
23
-
24
- add_swagger_documentation
25
- end
26
- end
27
- end
28
-
29
- def app
30
- TheBodyApi::Endpoint
31
- end
32
-
33
- subject do
34
- get '/swagger_doc'
35
- JSON.parse(last_response.body)
36
- end
37
-
38
- context 'a definition is generated for the endpoints parameters defined within the desc block' do
39
- specify do
40
- expect(subject['definitions']['postEndpoint']['properties']).to eql(
41
- 'body_param' => { 'type' => 'string', 'description' => 'param' },
42
- 'body_type_as_const_param' => { 'type' => 'string', 'description' => 'string_param' }
43
- )
44
-
45
- expect(subject['paths']['/endpoint']['post']['parameters'].any? { |p| p['name'] == 'XAuthToken' && p['in'] == 'header' }).to eql(true)
46
- end
47
- end
48
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'definitions/models' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ModelApi < Grape::API
11
- format :json
12
-
13
- add_swagger_documentation models: [
14
- ::Entities::UseResponse,
15
- ::Entities::ApiError,
16
- ::Entities::RecursiveModel,
17
- ::Entities::DocumentedHashAndArrayModel
18
- ]
19
- end
20
- end
21
- end
22
-
23
- def app
24
- TheApi::ModelApi
25
- end
26
-
27
- subject do
28
- get '/swagger_doc'
29
- JSON.parse(last_response.body)
30
- end
31
-
32
- specify do
33
- expect(subject).to include 'definitions'
34
- expect(subject['definitions']).to include(swagger_definitions_models)
35
- end
36
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- def details
6
- <<-DETAILS
7
- # Burgers in Heaven
8
-
9
- > A burger doesn't come for free
10
-
11
- If you want to reserve a burger in heaven, you have to do
12
- some crazy stuff on earth.
13
-
14
- ```
15
- def do_good
16
- puts 'help people'
17
- end
18
- ```
19
-
20
- * _Will go to Heaven:_ Probably
21
- * _Will go to Hell:_ Probably not
22
- DETAILS
23
- end
24
-
25
- describe 'details' do
26
- describe 'take deatils as it is' do
27
- include_context "#{MODEL_PARSER} swagger example"
28
-
29
- before :all do
30
- module TheApi
31
- class DetailApi < Grape::API
32
- format :json
33
-
34
- desc 'This returns something',
35
- detail: 'detailed description of the route',
36
- entity: Entities::UseResponse,
37
- failure: [{ code: 400, model: Entities::ApiError }]
38
- get '/use_detail' do
39
- { 'declared_params' => declared(params) }
40
- end
41
-
42
- desc 'This returns something' do
43
- detail 'detailed description of the route inside the `desc` block'
44
- entity Entities::UseResponse
45
- failure [{ code: 400, model: Entities::ApiError }]
46
- end
47
- get '/use_detail_block' do
48
- { 'declared_params' => declared(params) }
49
- end
50
-
51
- add_swagger_documentation
52
- end
53
- end
54
- end
55
-
56
- def app
57
- TheApi::DetailApi
58
- end
59
-
60
- subject do
61
- get '/swagger_doc'
62
- JSON.parse(last_response.body)
63
- end
64
-
65
- specify do
66
- expect(subject['paths']['/use_detail']['get']).to include('summary')
67
- expect(subject['paths']['/use_detail']['get']['summary']).to eql 'This returns something'
68
- expect(subject['paths']['/use_detail']['get']).to include('description')
69
- expect(subject['paths']['/use_detail']['get']['description']).to eql 'detailed description of the route'
70
- end
71
-
72
- specify do
73
- expect(subject['paths']['/use_detail_block']['get']).to include('summary')
74
- expect(subject['paths']['/use_detail_block']['get']['summary']).to eql 'This returns something'
75
- expect(subject['paths']['/use_detail_block']['get']).to include('description')
76
- expect(subject['paths']['/use_detail_block']['get']['description']).to eql 'detailed description of the route inside the `desc` block'
77
- end
78
- end
79
- end
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'extensions' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ExtensionsApi < Grape::API
11
- format :json
12
-
13
- route_setting :x_path, some: 'stuff'
14
-
15
- desc 'This returns something with extension on path level',
16
- params: Entities::UseResponse.documentation,
17
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
18
- get '/path_extension' do
19
- { 'declared_params' => declared(params) }
20
- end
21
-
22
- route_setting :x_operation, some: 'stuff'
23
-
24
- desc 'This returns something with extension on verb level',
25
- params: Entities::UseResponse.documentation,
26
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
27
- params do
28
- requires :id, type: Integer
29
- end
30
- get '/verb_extension' do
31
- { 'declared_params' => declared(params) }
32
- end
33
-
34
- route_setting :x_def, for: 200, some: 'stuff'
35
-
36
- desc 'This returns something with extension on definition level',
37
- params: Entities::ResponseItem.documentation,
38
- success: Entities::ResponseItem,
39
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
40
- get '/definitions_extension' do
41
- { 'declared_params' => declared(params) }
42
- end
43
-
44
- route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
45
-
46
- desc 'This returns something with extension on definition level',
47
- success: Entities::OtherItem
48
- get '/non_existend_status_definitions_extension' do
49
- { 'declared_params' => declared(params) }
50
- end
51
-
52
- route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
53
-
54
- desc 'This returns something with extension on definition level',
55
- success: Entities::OtherItem,
56
- failure: [{ code: 422, message: 'NotFound', model: Entities::SecondApiError }]
57
- get '/multiple_definitions_extension' do
58
- { 'declared_params' => declared(params) }
59
- end
60
-
61
- add_swagger_documentation(x: { some: 'stuff' })
62
- end
63
- end
64
- end
65
-
66
- def app
67
- TheApi::ExtensionsApi
68
- end
69
-
70
- describe 'extension on root level' do
71
- subject do
72
- get '/swagger_doc/path_extension'
73
- JSON.parse(last_response.body)
74
- end
75
-
76
- specify do
77
- expect(subject).to include 'x-some'
78
- expect(subject['x-some']).to eql 'stuff'
79
- end
80
- end
81
-
82
- describe 'extension on path level' do
83
- subject do
84
- get '/swagger_doc/path_extension'
85
- JSON.parse(last_response.body)
86
- end
87
-
88
- specify do
89
- expect(subject['paths']['/path_extension']).to include 'x-some'
90
- expect(subject['paths']['/path_extension']['x-some']).to eql 'stuff'
91
- end
92
- end
93
-
94
- describe 'extension on verb level' do
95
- subject do
96
- get '/swagger_doc/verb_extension'
97
- JSON.parse(last_response.body)
98
- end
99
-
100
- specify do
101
- expect(subject['paths']['/verb_extension']['get']).to include 'x-some'
102
- expect(subject['paths']['/verb_extension']['get']['x-some']).to eql 'stuff'
103
- end
104
- end
105
-
106
- describe 'extension on definition level' do
107
- subject do
108
- get '/swagger_doc/definitions_extension'
109
- JSON.parse(last_response.body)
110
- end
111
-
112
- specify do
113
- expect(subject['definitions']['ResponseItem']).to include 'x-some'
114
- expect(subject['definitions']['ResponseItem']['x-some']).to eql 'stuff'
115
- expect(subject['definitions']['ApiError']).not_to include 'x-some'
116
- end
117
- end
118
-
119
- describe 'extension on definition level' do
120
- subject do
121
- get '/swagger_doc/multiple_definitions_extension'
122
- JSON.parse(last_response.body)
123
- end
124
-
125
- specify do
126
- expect(subject['definitions']['OtherItem']).to include 'x-some'
127
- expect(subject['definitions']['OtherItem']['x-some']).to eql 'stuff'
128
- expect(subject['definitions']['SecondApiError']).to include 'x-other'
129
- expect(subject['definitions']['SecondApiError']['x-other']).to eql 'stuff'
130
- end
131
- end
132
-
133
- describe 'extension on definition level' do
134
- subject do
135
- get '/swagger_doc/non_existend_status_definitions_extension'
136
- JSON.parse(last_response.body)
137
- end
138
-
139
- specify do
140
- expect(subject['definitions'].length).to eql 1
141
- expect(subject['definitions']['OtherItem']).to include 'x-some'
142
- expect(subject['definitions']['OtherItem']['x-some']).to eql 'stuff'
143
- end
144
- end
145
- end
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'format, content_type' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ProducesApi < Grape::API
11
- format :json
12
-
13
- desc 'This uses json (default) for produces',
14
- failure: [{ code: 400, model: Entities::ApiError }],
15
- entity: Entities::UseResponse
16
- get '/use_default' do
17
- { 'declared_params' => declared(params) }
18
- end
19
-
20
- desc 'This uses formats for produces',
21
- failure: [{ code: 400, model: Entities::ApiError }],
22
- formats: [:xml, :binary, 'application/vdns'],
23
- entity: Entities::UseResponse
24
- get '/use_formats' do
25
- { 'declared_params' => declared(params) }
26
- end
27
-
28
- desc 'This uses content_types for produces',
29
- failure: [{ code: 400, model: Entities::ApiError }],
30
- content_types: [:xml, :binary, 'application/vdns'],
31
- entity: Entities::UseResponse
32
- get '/use_content_types' do
33
- { 'declared_params' => declared(params) }
34
- end
35
-
36
- desc 'This uses produces for produces',
37
- failure: [{ code: 400, model: Entities::ApiError }],
38
- produces: [:xml, :binary, 'application/vdns'],
39
- entity: Entities::UseResponse
40
- get '/use_produces' do
41
- { 'declared_params' => declared(params) }
42
- end
43
-
44
- desc 'This uses consumes for consumes',
45
- failure: [{ code: 400, model: Entities::ApiError }],
46
- consumes: ['application/www_url_encoded'],
47
- entity: Entities::UseResponse
48
- post '/use_consumes' do
49
- { 'declared_params' => declared(params) }
50
- end
51
-
52
- desc 'This uses consumes for consumes',
53
- failure: [{ code: 400, model: Entities::ApiError }],
54
- consumes: ['application/www_url_encoded'],
55
- entity: Entities::UseResponse
56
- patch '/use_consumes' do
57
- { 'declared_params' => declared(params) }
58
- end
59
-
60
- add_swagger_documentation
61
- end
62
- end
63
- end
64
-
65
- def app
66
- TheApi::ProducesApi
67
- end
68
-
69
- let(:produced) do
70
- [
71
- 'application/xml',
72
- 'application/octet-stream',
73
- 'application/vdns'
74
- ]
75
- end
76
-
77
- describe 'formats' do
78
- subject do
79
- get '/swagger_doc/use_default'
80
- JSON.parse(last_response.body)
81
- end
82
-
83
- specify do
84
- expect(subject['paths']['/use_default']['get']).to include('produces')
85
- expect(subject['paths']['/use_default']['get']['produces']).to eql(['application/json'])
86
- end
87
- end
88
-
89
- describe 'formats' do
90
- subject do
91
- get '/swagger_doc/use_formats'
92
- JSON.parse(last_response.body)
93
- end
94
-
95
- specify do
96
- expect(subject['paths']['/use_formats']['get']).to include('produces')
97
- expect(subject['paths']['/use_formats']['get']['produces']).to eql(produced)
98
- end
99
- end
100
-
101
- describe 'content types' do
102
- subject do
103
- get '/swagger_doc/use_content_types'
104
- JSON.parse(last_response.body)
105
- end
106
-
107
- specify do
108
- expect(subject['paths']['/use_content_types']['get']).to include('produces')
109
- expect(subject['paths']['/use_content_types']['get']['produces']).to eql(produced)
110
- end
111
- end
112
-
113
- describe 'produces' do
114
- subject do
115
- get '/swagger_doc/use_produces'
116
- JSON.parse(last_response.body)
117
- end
118
-
119
- specify do
120
- expect(subject['paths']['/use_produces']['get']).to include('produces')
121
- expect(subject['paths']['/use_produces']['get']['produces']).to eql(produced)
122
- end
123
- end
124
-
125
- describe 'consumes' do
126
- subject do
127
- get '/swagger_doc/use_consumes'
128
- JSON.parse(last_response.body)
129
- end
130
-
131
- specify do
132
- expect(subject['paths']['/use_consumes']['post']).to include('consumes')
133
- expect(subject['paths']['/use_consumes']['post']['consumes']).to eql ['application/www_url_encoded']
134
- expect(subject['paths']['/use_consumes']['patch']['consumes']).to eql ['application/www_url_encoded']
135
- end
136
- end
137
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'global configuration stuff' do
6
- before :all do
7
- module TheApi
8
- class ConfigurationApi < Grape::API
9
- format :json
10
- version 'v3', using: :path
11
-
12
- desc 'This returns something',
13
- failure: [{ code: 400, message: 'NotFound' }]
14
- params do
15
- requires :foo, type: Integer
16
- end
17
- get :configuration do
18
- { 'declared_params' => declared(params) }
19
- end
20
-
21
- add_swagger_documentation format: :json,
22
- doc_version: '23',
23
- schemes: 'https',
24
- host: -> { 'another.host.com' },
25
- base_path: -> { 'somewhere/over/the/rainbow' },
26
- mount_path: 'documentation',
27
- add_base_path: true,
28
- add_version: true,
29
- security_definitions: { api_key: { foo: 'bar' } },
30
- security: [{ api_key: [] }]
31
- end
32
- end
33
- end
34
-
35
- def app
36
- TheApi::ConfigurationApi
37
- end
38
-
39
- describe 'shows documentation paths' do
40
- subject do
41
- get '/v3/documentation'
42
- JSON.parse(last_response.body)
43
- end
44
-
45
- specify do
46
- expect(subject['info']['version']).to eql '23'
47
- expect(subject['host']).to eql 'another.host.com'
48
- expect(subject['basePath']).to eql 'somewhere/over/the/rainbow'
49
- expect(subject['paths'].keys.first).to eql '/somewhere/over/the/rainbow/v3/configuration'
50
- expect(subject['schemes']).to eql ['https']
51
- expect(subject['securityDefinitions'].keys).to include('api_key')
52
- expect(subject['securityDefinitions']['api_key']).to include('foo' => 'bar')
53
- expect(subject['security']).to include('api_key' => [])
54
- end
55
- end
56
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'document hash and array' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class TestApi < Grape::API
11
- format :json
12
-
13
- if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation)
14
- documentation = ::Entities::DocumentedHashAndArrayModel.documentation
15
- end
16
-
17
- desc 'This returns something'
18
- namespace :arbitrary do
19
- params do
20
- requires :id, type: Integer
21
- end
22
- route_param :id do
23
- desc 'Timeless treasure'
24
- params do
25
- requires :body, using: documentation unless documentation.nil?
26
- requires :raw_hash, type: Hash, documentation: { param_type: 'body' } if documentation.nil?
27
- requires :raw_array, type: Array, documentation: { param_type: 'body' } if documentation.nil?
28
- end
29
- put '/id_and_hash' do
30
- {}
31
- end
32
- end
33
- end
34
-
35
- add_swagger_documentation
36
- end
37
- end
38
- end
39
-
40
- def app
41
- TheApi::TestApi
42
- end
43
-
44
- subject do
45
- get '/swagger_doc'
46
- JSON.parse(last_response.body)
47
- end
48
- describe 'generated request definition' do
49
- it 'has hash' do
50
- expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
51
- expect(subject['definitions']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_hash')
52
- end
53
-
54
- it 'has array' do
55
- expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
56
- expect(subject['definitions']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_array')
57
- end
58
-
59
- it 'does not have the path parameter' do
60
- expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
61
- expect(subject['definitions']['putArbitraryIdIdAndHash']).to_not include('id')
62
- end
63
- end
64
- end