grape-swagger 0.20.2 → 0.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/.rubocop_todo.yml +43 -33
- data/.travis.yml +22 -13
- data/CHANGELOG.md +29 -53
- data/Gemfile +1 -1
- data/README.md +24 -24
- data/example/api/endpoints.rb +28 -29
- data/example/api/entities.rb +1 -1
- data/example/config.ru +5 -7
- data/grape-swagger.gemspec +1 -1
- data/lib/grape-swagger.rb +9 -6
- data/lib/grape-swagger/doc_methods.rb +1 -1
- data/lib/grape-swagger/doc_methods/extensions.rb +3 -3
- data/lib/grape-swagger/doc_methods/headers.rb +1 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +25 -16
- data/lib/grape-swagger/doc_methods/operation_id.rb +2 -2
- data/lib/grape-swagger/doc_methods/parse_params.rb +12 -5
- data/lib/grape-swagger/doc_methods/path_string.rb +1 -1
- data/lib/grape-swagger/doc_methods/status_codes.rb +3 -1
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +33 -46
- data/lib/grape-swagger/grape/route.rb +16 -0
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/403_versions_spec.rb +158 -0
- data/spec/lib/data_type_spec.rb +9 -10
- data/spec/lib/endpoint_spec.rb +1 -2
- data/spec/lib/extensions_spec.rb +44 -40
- data/spec/lib/move_params_spec.rb +113 -93
- data/spec/lib/operation_id_spec.rb +42 -12
- data/spec/lib/optional_object_spec.rb +3 -4
- data/spec/lib/path_string_spec.rb +2 -2
- data/spec/lib/produces_consumes_spec.rb +64 -53
- data/spec/markdown/redcarpet_adapter_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/api_swagger_v2_result.rb +122 -128
- data/spec/support/namespace_tags.rb +17 -19
- data/spec/support/the_api_entities.rb +1 -3
- data/spec/support/the_paths_definitions.rb +95 -85
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +1 -1
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +19 -19
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +21 -21
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +34 -32
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +5 -7
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +19 -18
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +9 -10
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +21 -24
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +90 -92
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +54 -54
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +65 -57
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +17 -14
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +79 -123
- data/spec/swagger_v2/api_swagger_v2_spec.rb +33 -34
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +32 -36
- data/spec/swagger_v2/boolean_params_spec.rb +1 -1
- data/spec/swagger_v2/default_api_spec.rb +26 -29
- data/spec/swagger_v2/description_not_initialized.rb +3 -3
- data/spec/swagger_v2/float_api_spec.rb +1 -1
- data/spec/swagger_v2/form_params_spec.rb +4 -4
- data/spec/swagger_v2/hide_api_spec.rb +48 -51
- data/spec/swagger_v2/host.rb +1 -1
- data/spec/swagger_v2/mounted_target_class_spec.rb +31 -33
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +23 -21
- data/spec/swagger_v2/namespace_tags_spec.rb +23 -20
- data/spec/swagger_v2/param_type_spec.rb +5 -6
- data/spec/swagger_v2/param_values_spec.rb +31 -37
- data/spec/swagger_v2/params_array_spec.rb +17 -15
- data/spec/swagger_v2/params_hash_spec.rb +17 -15
- data/spec/swagger_v2/params_nested_spec.rb +12 -10
- data/spec/swagger_v2/reference_entity.rb +9 -9
- data/spec/swagger_v2/response_model_spec.rb +58 -62
- data/spec/swagger_v2/simple_mounted_api_spec.rb +179 -147
- metadata +5 -10
- data/spec/params_entity_spec.rb +0 -49
@@ -0,0 +1,16 @@
|
|
1
|
+
# backwards compatibility for Grape < 0.16.0
|
2
|
+
module Grape
|
3
|
+
class Route
|
4
|
+
[:path, :prefix, :entity, :description, :settings, :params, :headers, :http_codes].each do |m|
|
5
|
+
define_method m do
|
6
|
+
send "route_#{m}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def request_method
|
11
|
+
route_method
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :options
|
15
|
+
end
|
16
|
+
end if defined?(Grape::VERSION) && Gem::Version.new(::Grape::VERSION) < Gem::Version.new('0.16.0')
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'describing versions' do
|
5
|
+
describe 'nothings given' do
|
6
|
+
def app
|
7
|
+
Class.new(Grape::API) do
|
8
|
+
desc 'no versions given'
|
9
|
+
get '/nothings' do
|
10
|
+
{ message: 'hello world …' }
|
11
|
+
end
|
12
|
+
|
13
|
+
add_swagger_documentation format: :json
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject do
|
18
|
+
get '/swagger_doc'
|
19
|
+
JSON.parse(last_response.body, symbolize_names: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
specify do
|
23
|
+
expect(subject).to eql(
|
24
|
+
info: { title: 'API title', version: '0.0.1' },
|
25
|
+
swagger: '2.0',
|
26
|
+
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
27
|
+
host: 'example.org',
|
28
|
+
tags: [{ name: 'nothings', description: 'Operations about nothings' }],
|
29
|
+
paths: {
|
30
|
+
:'/nothings' => {
|
31
|
+
get: {
|
32
|
+
description: 'no versions given',
|
33
|
+
produces: ['application/json'],
|
34
|
+
responses: {
|
35
|
+
:'200' => { description: 'no versions given' }
|
36
|
+
},
|
37
|
+
tags: ['nothings'],
|
38
|
+
operationId: 'getNothings'
|
39
|
+
} } })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'API version given' do
|
44
|
+
def app
|
45
|
+
Class.new(Grape::API) do
|
46
|
+
version 'v2', using: :path
|
47
|
+
desc 'api versions given'
|
48
|
+
get '/api_version' do
|
49
|
+
{ message: 'hello world …' }
|
50
|
+
end
|
51
|
+
|
52
|
+
add_swagger_documentation format: :json
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
subject do
|
57
|
+
get '/v2/swagger_doc'
|
58
|
+
JSON.parse(last_response.body, symbolize_names: true)
|
59
|
+
end
|
60
|
+
|
61
|
+
specify do
|
62
|
+
expect(subject).to eql(
|
63
|
+
info: { title: 'API title', version: '0.0.1' },
|
64
|
+
swagger: '2.0',
|
65
|
+
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
66
|
+
host: 'example.org',
|
67
|
+
tags: [{ name: 'api_version', description: 'Operations about api_versions' }],
|
68
|
+
paths: {
|
69
|
+
:'/v2/api_version' => {
|
70
|
+
get: {
|
71
|
+
description: 'api versions given',
|
72
|
+
produces: ['application/json'],
|
73
|
+
responses: {
|
74
|
+
:'200' => { description: 'api versions given' }
|
75
|
+
},
|
76
|
+
tags: ['api_version'],
|
77
|
+
operationId: 'getV2ApiVersion'
|
78
|
+
} } })
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'DOC version given' do
|
83
|
+
def app
|
84
|
+
Class.new(Grape::API) do
|
85
|
+
desc 'doc versions given'
|
86
|
+
get '/doc_version' do
|
87
|
+
{ message: 'hello world …' }
|
88
|
+
end
|
89
|
+
|
90
|
+
add_swagger_documentation doc_version: '0.0.2'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
subject do
|
95
|
+
get '/swagger_doc'
|
96
|
+
JSON.parse(last_response.body, symbolize_names: true)
|
97
|
+
end
|
98
|
+
|
99
|
+
specify do
|
100
|
+
expect(subject).to eql(
|
101
|
+
info: { title: 'API title', version: '0.0.2' },
|
102
|
+
swagger: '2.0',
|
103
|
+
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
104
|
+
host: 'example.org',
|
105
|
+
tags: [{ name: 'doc_version', description: 'Operations about doc_versions' }],
|
106
|
+
paths: {
|
107
|
+
:'/doc_version' => {
|
108
|
+
get: {
|
109
|
+
description: 'doc versions given',
|
110
|
+
produces: ['application/json'],
|
111
|
+
responses: {
|
112
|
+
:'200' => { description: 'doc versions given' }
|
113
|
+
},
|
114
|
+
tags: ['doc_version'],
|
115
|
+
operationId: 'getDocVersion'
|
116
|
+
} } })
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'both versions given' do
|
121
|
+
def app
|
122
|
+
Class.new(Grape::API) do
|
123
|
+
version :v2, using: :path
|
124
|
+
desc 'both versions given'
|
125
|
+
get '/both_versions' do
|
126
|
+
{ message: 'hello world …' }
|
127
|
+
end
|
128
|
+
|
129
|
+
add_swagger_documentation doc_version: '0.0.2'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
subject do
|
134
|
+
get '/v2/swagger_doc'
|
135
|
+
JSON.parse(last_response.body, symbolize_names: true)
|
136
|
+
end
|
137
|
+
|
138
|
+
specify do
|
139
|
+
expect(subject).to eql(
|
140
|
+
info: { title: 'API title', version: '0.0.2' },
|
141
|
+
swagger: '2.0',
|
142
|
+
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
143
|
+
host: 'example.org',
|
144
|
+
tags: [{ name: 'both_versions', description: 'Operations about both_versions' }],
|
145
|
+
paths: {
|
146
|
+
:'/v2/both_versions' => {
|
147
|
+
get: {
|
148
|
+
description: 'both versions given',
|
149
|
+
produces: ['application/json'],
|
150
|
+
responses: {
|
151
|
+
:'200' => { description: 'both versions given' }
|
152
|
+
},
|
153
|
+
tags: ['both_versions'],
|
154
|
+
operationId: 'getV2BothVersions'
|
155
|
+
} } })
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/spec/lib/data_type_spec.rb
CHANGED
@@ -1,55 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GrapeSwagger::DocMethods::DataType do
|
4
|
-
|
5
4
|
subject { described_class.call(value) }
|
6
5
|
|
7
|
-
describe
|
6
|
+
describe 'standards' do
|
8
7
|
['Boolean', Date, Integer, String, Float].each do |type|
|
9
8
|
specify do
|
10
|
-
data_type = described_class.call(
|
9
|
+
data_type = described_class.call(type: type)
|
11
10
|
expect(data_type).to eql type.to_s.downcase
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
describe
|
15
|
+
describe 'Hash' do
|
17
16
|
let(:value) { { type: Hash } }
|
18
17
|
|
19
18
|
it { expect(subject).to eql 'object' }
|
20
19
|
end
|
21
20
|
|
22
|
-
describe
|
21
|
+
describe 'Rack::Multipart::UploadedFile' do
|
23
22
|
let(:value) { { type: Rack::Multipart::UploadedFile } }
|
24
23
|
|
25
24
|
it { expect(subject).to eql 'file' }
|
26
25
|
end
|
27
26
|
|
28
|
-
describe
|
27
|
+
describe 'Virtus::Attribute::Boolean' do
|
29
28
|
let(:value) { { type: Virtus::Attribute::Boolean } }
|
30
29
|
|
31
30
|
it { expect(subject).to eql 'boolean' }
|
32
31
|
end
|
33
32
|
|
34
|
-
describe
|
33
|
+
describe 'BigDecimal' do
|
35
34
|
let(:value) { { type: BigDecimal } }
|
36
35
|
|
37
36
|
it { expect(subject).to eql 'double' }
|
38
37
|
end
|
39
38
|
|
40
|
-
describe
|
39
|
+
describe 'DateTime' do
|
41
40
|
let(:value) { { type: DateTime } }
|
42
41
|
|
43
42
|
it { expect(subject).to eql 'dateTime' }
|
44
43
|
end
|
45
44
|
|
46
|
-
describe
|
45
|
+
describe 'Numeric' do
|
47
46
|
let(:value) { { type: Numeric } }
|
48
47
|
|
49
48
|
it { expect(subject).to eql 'long' }
|
50
49
|
end
|
51
50
|
|
52
|
-
describe
|
51
|
+
describe 'Symbol' do
|
53
52
|
let(:value) { { type: Symbol } }
|
54
53
|
|
55
54
|
it { expect(subject).to eql 'string' }
|
data/spec/lib/endpoint_spec.rb
CHANGED
data/spec/lib/extensions_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GrapeSwagger::DocMethods::Extensions do
|
4
|
-
describe
|
4
|
+
describe '#extended? and extension' do
|
5
5
|
subject { described_class }
|
6
|
-
describe
|
7
|
-
let(:part) { {foo: 'bar', bar: 'foo'} }
|
6
|
+
describe 'return false (default)' do
|
7
|
+
let(:part) { { foo: 'bar', bar: 'foo' } }
|
8
8
|
|
9
9
|
specify do
|
10
10
|
expect(subject.extended?(part)).to be false
|
@@ -12,42 +12,42 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
15
|
+
describe 'return true' do
|
16
16
|
specify do
|
17
17
|
part = { foo: 'bar', bar: 'foo', x: 'something' }
|
18
18
|
expect(subject.extended?(part)).to be true
|
19
|
-
expect(subject.extension(part)).to eql(
|
19
|
+
expect(subject.extension(part)).to eql(x: 'something')
|
20
20
|
expect(subject.extended?(part, :x)).to be true
|
21
|
-
expect(subject.extension(part, :x)).to eql(
|
21
|
+
expect(subject.extension(part, :x)).to eql(x: 'something')
|
22
22
|
end
|
23
23
|
|
24
24
|
specify do
|
25
25
|
part = { foo: 'bar', bar: 'foo', x_path: 'something' }
|
26
26
|
expect(subject.extended?(part, :x_path)).to be true
|
27
|
-
expect(subject.extension(part, :x_path)).to eql(
|
27
|
+
expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
|
28
28
|
end
|
29
29
|
|
30
30
|
specify do
|
31
31
|
part = { foo: 'bar', bar: 'foo', x_def: 'something' }
|
32
32
|
expect(subject.extended?(part, :x_def)).to be true
|
33
|
-
expect(subject.extension(part, :x_def)).to eql(
|
33
|
+
expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
|
34
34
|
end
|
35
35
|
|
36
36
|
specify do
|
37
37
|
part = { foo: 'bar', bar: 'foo', x_path: 'something', x_def: 'something' }
|
38
38
|
expect(subject.extended?(part, :x_path)).to be true
|
39
|
-
expect(subject.extension(part, :x_path)).to eql(
|
39
|
+
expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
|
40
40
|
expect(subject.extended?(part, :x_def)).to be true
|
41
|
-
expect(subject.extension(part, :x_def)).to eql(
|
41
|
+
expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe
|
47
|
-
describe
|
48
|
-
describe
|
49
|
-
let(:extensions) { {x: {key_1: 'foo'}} }
|
50
|
-
let(:result) { {'x-key_1' => 'foo'} }
|
46
|
+
describe 'concatenate' do
|
47
|
+
describe 'not nested' do
|
48
|
+
describe 'simple' do
|
49
|
+
let(:extensions) { { x: { key_1: 'foo' } } }
|
50
|
+
let(:result) { { 'x-key_1' => 'foo' } }
|
51
51
|
subject { described_class.concatenate(extensions) }
|
52
52
|
|
53
53
|
specify do
|
@@ -55,9 +55,9 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe
|
59
|
-
let(:extensions) { {x: {key_1: 'foo', key_2: 'bar'}} }
|
60
|
-
let(:result) { {'x-key_1' => 'foo', 'x-key_2' => 'bar'} }
|
58
|
+
describe 'multiple' do
|
59
|
+
let(:extensions) { { x: { key_1: 'foo', key_2: 'bar' } } }
|
60
|
+
let(:result) { { 'x-key_1' => 'foo', 'x-key_2' => 'bar' } }
|
61
61
|
subject { described_class.concatenate(extensions) }
|
62
62
|
|
63
63
|
specify do
|
@@ -66,10 +66,10 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
describe
|
71
|
-
let(:extensions) { {x: {key_1: { key_2: 'foo'}}} }
|
72
|
-
let(:result) { {'x-key_1' => { key_2: 'foo'}} }
|
69
|
+
describe 'nested' do
|
70
|
+
describe 'simple' do
|
71
|
+
let(:extensions) { { x: { key_1: { key_2: 'foo' } } } }
|
72
|
+
let(:result) { { 'x-key_1' => { key_2: 'foo' } } }
|
73
73
|
subject { described_class.concatenate(extensions) }
|
74
74
|
|
75
75
|
specify do
|
@@ -77,9 +77,9 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe
|
81
|
-
let(:extensions) { {x: {key_1: { key_2: 'foo', key_3: 'bar'}}} }
|
82
|
-
let(:result) { {'x-key_1' => { key_2: 'foo', key_3: 'bar'}} }
|
80
|
+
describe 'simple multiple' do
|
81
|
+
let(:extensions) { { x: { key_1: { key_2: 'foo', key_3: 'bar' } } } }
|
82
|
+
let(:result) { { 'x-key_1' => { key_2: 'foo', key_3: 'bar' } } }
|
83
83
|
subject { described_class.concatenate(extensions) }
|
84
84
|
|
85
85
|
specify do
|
@@ -87,9 +87,9 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
describe
|
91
|
-
let(:extensions) { {x: {key_1: { key_2: {key_3: 'foo'}}}} }
|
92
|
-
let(:result) { {'x-key_1' => { key_2: {key_3: 'foo'}}} }
|
90
|
+
describe 'simple deeper' do
|
91
|
+
let(:extensions) { { x: { key_1: { key_2: { key_3: 'foo' } } } } }
|
92
|
+
let(:result) { { 'x-key_1' => { key_2: { key_3: 'foo' } } } }
|
93
93
|
subject { described_class.concatenate(extensions) }
|
94
94
|
|
95
95
|
specify do
|
@@ -97,9 +97,9 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
describe
|
101
|
-
let(:extensions) { {x: {key_1: { key_3: 'foo'}, key_2: { key_3: 'bar' }}} }
|
102
|
-
let(:result) { {'x-key_1' => { key_3: 'foo'}, 'x-key_2' => { key_3: 'bar' }} }
|
100
|
+
describe 'multiple' do
|
101
|
+
let(:extensions) { { x: { key_1: { key_3: 'foo' }, key_2: { key_3: 'bar' } } } }
|
102
|
+
let(:result) { { 'x-key_1' => { key_3: 'foo' }, 'x-key_2' => { key_3: 'bar' } } }
|
103
103
|
subject { described_class.concatenate(extensions) }
|
104
104
|
|
105
105
|
specify do
|
@@ -108,15 +108,19 @@ describe GrapeSwagger::DocMethods::Extensions do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
describe
|
112
|
-
let(:extensions)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
111
|
+
describe 'real example' do
|
112
|
+
let(:extensions) do
|
113
|
+
{ x: {
|
114
|
+
'amazon-apigateway-auth' => { type: 'none' },
|
115
|
+
'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
|
116
|
+
} }
|
117
|
+
end
|
118
|
+
let(:result) do
|
119
|
+
{
|
120
|
+
'x-amazon-apigateway-auth' => { type: 'none' },
|
121
|
+
'x-amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
|
122
|
+
}
|
123
|
+
end
|
120
124
|
subject { described_class.concatenate(extensions) }
|
121
125
|
|
122
126
|
specify do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GrapeSwagger::DocMethods::MoveParams do
|
4
|
-
include_context
|
4
|
+
include_context 'the api paths/defs'
|
5
5
|
|
6
6
|
subject { described_class }
|
7
7
|
|
@@ -15,22 +15,28 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'no post/put given' do
|
18
|
-
let(:paths)
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
let(:paths) do
|
19
|
+
{
|
20
|
+
:'/foo' => { get: {}, delete: {} },
|
21
|
+
:'/bar/{key}' => { get: {}, delete: {} }
|
22
|
+
}
|
23
|
+
end
|
22
24
|
specify { expect { |b| subject.find_post_put(paths, &b) }.not_to yield_control }
|
23
25
|
end
|
24
26
|
|
25
27
|
describe 'no post/put given' do
|
26
|
-
let(:paths)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
let(:paths) do
|
29
|
+
{
|
30
|
+
:'/foo' => { get: {}, delete: {}, post: {}, put: {}, patch: {} },
|
31
|
+
:'/bar/{key}' => { get: {}, delete: {}, post: {}, put: {}, patch: {} }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
let(:expected) do
|
35
|
+
[
|
36
|
+
{ post: {}, put: {}, patch: {} },
|
37
|
+
{ post: {}, put: {}, patch: {} }
|
38
|
+
]
|
39
|
+
end
|
34
40
|
specify { expect { |b| subject.find_post_put(paths, &b) }.to yield_control.twice }
|
35
41
|
specify { expect { |b| subject.find_post_put(paths, &b) }.to yield_successive_args *expected }
|
36
42
|
end
|
@@ -39,19 +45,18 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
39
45
|
describe 'find_definition_and_params' do
|
40
46
|
specify do
|
41
47
|
subject.instance_variable_set(:@definitions, definitions)
|
42
|
-
subject.find_definition_and_params(found_path)
|
43
|
-
|
44
|
-
expect(definitions.keys).to include 'InBody', 'postRequestInBody'
|
48
|
+
subject.find_definition_and_params(found_path, :post)
|
49
|
+
expect(definitions.keys).to include 'InBody'
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
describe 'move_params_to_new definition' do
|
49
54
|
let(:name) { 'Foo' }
|
50
|
-
let(:definitions) {{}}
|
55
|
+
let(:definitions) { {} }
|
51
56
|
|
52
57
|
describe 'post request' do
|
53
58
|
let(:verb) { 'post' }
|
54
|
-
let(:params) { paths[
|
59
|
+
let(:params) { paths['/in_body'][:post][:parameters] }
|
55
60
|
|
56
61
|
specify do
|
57
62
|
subject.instance_variable_set(:@definitions, definitions)
|
@@ -65,7 +70,7 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
65
70
|
|
66
71
|
describe 'put request' do
|
67
72
|
let(:verb) { 'put' }
|
68
|
-
let(:params) { paths[
|
73
|
+
let(:params) { paths['/in_body/{key}'][:put][:parameters] }
|
69
74
|
|
70
75
|
specify do
|
71
76
|
subject.instance_variable_set(:@definitions, definitions)
|
@@ -85,24 +90,24 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
85
90
|
end
|
86
91
|
|
87
92
|
describe 'simple' do
|
88
|
-
let(:params) {[{:
|
89
|
-
let(:expected) {[{:
|
93
|
+
let(:params) { [{ in: 'body', name: 'address[street]', description: 'street', type: 'string', required: true }] }
|
94
|
+
let(:expected) { [{ in: 'body', name: 'street', description: 'street', type: 'string', required: true }] }
|
90
95
|
specify do
|
91
96
|
expect(params).to eql expected
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
95
100
|
describe 'nested' do
|
96
|
-
let(:params) {[{:
|
97
|
-
let(:expected) {[{:
|
101
|
+
let(:params) { [{ in: 'body', name: 'address[street][name]', description: 'street', type: 'string', required: true }] }
|
102
|
+
let(:expected) { [{ in: 'body', name: 'street[name]', description: 'street', type: 'string', required: true }] }
|
98
103
|
specify do
|
99
104
|
expect(params).to eql expected
|
100
105
|
end
|
101
106
|
end
|
102
107
|
|
103
108
|
describe 'array' do
|
104
|
-
let(:params) {[{:
|
105
|
-
let(:expected) {[{:
|
109
|
+
let(:params) { [{ in: 'body', name: 'address[][street_lines]', description: 'street lines', type: 'array', required: true }] }
|
110
|
+
let(:expected) { [{ in: 'body', name: 'street_lines', description: 'street lines', type: 'array', required: true }] }
|
106
111
|
specify do
|
107
112
|
expect(params).to eql expected
|
108
113
|
end
|
@@ -120,36 +125,36 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
120
125
|
describe 'verb given' do
|
121
126
|
let(:verb) { 'post' }
|
122
127
|
let(:name) { 'Foo' }
|
123
|
-
let(:definitions) {{}}
|
128
|
+
let(:definitions) { {} }
|
124
129
|
|
125
130
|
specify do
|
126
131
|
definition = definitions.to_a.first
|
127
132
|
expect(definition.first).to eql 'postRequestFoo'
|
128
|
-
expect(definition.last).to eql(
|
133
|
+
expect(definition.last).to eql(type: 'object', properties: {}, required: [])
|
129
134
|
end
|
130
135
|
end
|
131
136
|
|
132
137
|
describe 'no verb given' do
|
133
138
|
let(:name) { 'FooBar' }
|
134
|
-
let(:definitions) {{}}
|
139
|
+
let(:definitions) { {} }
|
135
140
|
let(:verb) { nil }
|
136
141
|
|
137
142
|
specify do
|
138
143
|
definition = definitions.to_a.first
|
139
144
|
expect(definition.first).to eql 'FooBar'
|
140
|
-
expect(definition.last).to eql(
|
145
|
+
expect(definition.last).to eql(type: 'object', properties: {}, required: [])
|
141
146
|
end
|
142
147
|
end
|
143
148
|
end
|
144
149
|
|
145
150
|
describe 'build_body_parameter' do
|
146
|
-
let(:response) {{ schema: { '$ref' => '#/definitions/Somewhere'} }}
|
151
|
+
let(:response) { { schema: { '$ref' => '#/definitions/Somewhere' } } }
|
147
152
|
|
148
153
|
describe 'no name given' do
|
149
154
|
let(:name) { nil }
|
150
|
-
let(:expected_param)
|
151
|
-
{:
|
152
|
-
|
155
|
+
let(:expected_param) do
|
156
|
+
{ name: 'Somewhere', in: 'body', required: true, schema: { '$ref' => '#/definitions/Somewhere' } }
|
157
|
+
end
|
153
158
|
specify do
|
154
159
|
parameter = subject.send(:build_body_parameter, response)
|
155
160
|
expect(parameter).to eql expected_param
|
@@ -158,9 +163,9 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
158
163
|
|
159
164
|
describe 'name given' do
|
160
165
|
let(:name) { 'Foo' }
|
161
|
-
let(:expected_param)
|
162
|
-
{:
|
163
|
-
|
166
|
+
let(:expected_param) do
|
167
|
+
{ name: 'Somewhere', in: 'body', required: true, schema: { '$ref' => "#/definitions/#{name}" } }
|
168
|
+
end
|
164
169
|
specify do
|
165
170
|
parameter = subject.send(:build_body_parameter, response, name)
|
166
171
|
expect(parameter).to eql expected_param
|
@@ -177,63 +182,67 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
177
182
|
|
178
183
|
describe 'movable' do
|
179
184
|
describe 'path' do
|
180
|
-
let(:param) {{ in:
|
185
|
+
let(:param) { { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true } }
|
181
186
|
it { expect(subject.send(:movable?, param)).to be true }
|
182
187
|
end
|
183
188
|
|
184
189
|
describe 'body' do
|
185
|
-
let(:param) {{ in:
|
190
|
+
let(:param) { { in: 'body', name: 'in_body', description: 'in_body', type: 'integer', format: 'int32', required: true } }
|
186
191
|
it { expect(subject.send(:movable?, param)).to be true }
|
187
192
|
end
|
188
193
|
|
189
194
|
describe 'query' do
|
190
|
-
let(:param) {{ in:
|
195
|
+
let(:param) { { in: 'query', name: 'in_query', description: 'in_query', type: 'integer', format: 'int32', required: true } }
|
191
196
|
it { expect(subject.send(:movable?, param)).to be false }
|
192
197
|
end
|
193
198
|
|
194
199
|
describe 'header' do
|
195
|
-
let(:param) {{ in:
|
200
|
+
let(:param) { { in: 'header', name: 'in_header', description: 'in_header', type: 'integer', format: 'int32', required: true } }
|
196
201
|
it { expect(subject.send(:movable?, param)).to be false }
|
197
202
|
end
|
198
203
|
end
|
199
204
|
|
200
205
|
describe 'deletable' do
|
201
206
|
describe 'path' do
|
202
|
-
let(:param) {{ in:
|
207
|
+
let(:param) { { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true } }
|
203
208
|
it { expect(subject.send(:deletable?, param)).to be false }
|
204
209
|
end
|
205
210
|
|
206
211
|
describe 'body' do
|
207
|
-
let(:param) {{ in:
|
212
|
+
let(:param) { { in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true } }
|
208
213
|
it { expect(subject.send(:deletable?, param)).to be true }
|
209
214
|
end
|
210
215
|
|
211
216
|
describe 'query' do
|
212
|
-
let(:param) {{ in:
|
217
|
+
let(:param) { { in: 'query', name: 'in_query_1', description: 'in_query_1', type: 'integer', format: 'int32', required: true } }
|
213
218
|
it { expect(subject.send(:deletable?, param)).to be false }
|
214
219
|
end
|
215
220
|
|
216
221
|
describe 'header' do
|
217
|
-
let(:param) {{ in:
|
222
|
+
let(:param) { { in: 'header', name: 'in_header_1', description: 'in_header_1', type: 'integer', format: 'int32', required: true } }
|
218
223
|
it { expect(subject.send(:deletable?, param)).to be false }
|
219
224
|
end
|
220
225
|
end
|
221
226
|
|
222
227
|
describe 'should move' do
|
223
228
|
describe 'no move' do
|
224
|
-
let(:params)
|
225
|
-
|
226
|
-
|
227
|
-
|
229
|
+
let(:params) do
|
230
|
+
[
|
231
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
232
|
+
{ in: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
233
|
+
]
|
234
|
+
end
|
228
235
|
it { expect(subject.send(:should_move?, params)).to be false }
|
229
236
|
end
|
230
237
|
|
231
238
|
describe 'move' do
|
232
|
-
let(:params)
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
239
|
+
let(:params) do
|
240
|
+
[
|
241
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
242
|
+
{ in: 'body', name: 'in_bosy', description: 'in_bosy', type: 'integer', format: 'int32', required: true },
|
243
|
+
{ in: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
244
|
+
]
|
245
|
+
end
|
237
246
|
it { expect(subject.send(:should_move?, params)).to be true }
|
238
247
|
end
|
239
248
|
end
|
@@ -243,54 +252,65 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
243
252
|
subject.send(:unify!, params) if subject.send(:should_move?, params)
|
244
253
|
end
|
245
254
|
describe 'param type with `:in` given' do
|
246
|
-
let(:params)
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
255
|
+
let(:params) do
|
256
|
+
[
|
257
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
258
|
+
{ in: 'body', name: 'in_body', description: 'in_body', type: 'integer', format: 'int32', required: true },
|
259
|
+
{ in: 'query', name: 'in_query', description: 'in_query', type: 'integer', format: 'int32', required: true },
|
260
|
+
{ in: 'header', name: 'in_header', description: 'in_header', type: 'integer', format: 'int32', required: true },
|
261
|
+
{ in: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
262
|
+
]
|
263
|
+
end
|
264
|
+
|
265
|
+
let(:expected_params) do
|
266
|
+
[
|
267
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
268
|
+
{ in: 'body', name: 'in_body', description: 'in_body', type: 'integer', format: 'int32', required: true },
|
269
|
+
{ in: 'query', name: 'in_query', description: 'in_query', type: 'integer', format: 'int32', required: true },
|
270
|
+
{ in: 'header', name: 'in_header', description: 'in_header', type: 'integer', format: 'int32', required: true },
|
271
|
+
{ in: 'body', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
272
|
+
]
|
273
|
+
end
|
261
274
|
it { expect(params).to eql expected_params }
|
262
275
|
end
|
263
276
|
|
264
277
|
describe 'let it as is' do
|
265
|
-
let(:params)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
{ in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
|
272
|
-
{ in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
|
273
|
-
]}
|
274
|
-
it { expect(params).to eql expected_params }
|
278
|
+
let(:params) do
|
279
|
+
[
|
280
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
281
|
+
{ in: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
282
|
+
]
|
283
|
+
end
|
275
284
|
|
285
|
+
let(:expected_params) do
|
286
|
+
[
|
287
|
+
{ in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
288
|
+
{ in: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
289
|
+
]
|
290
|
+
end
|
291
|
+
it { expect(params).to eql expected_params }
|
276
292
|
end
|
277
293
|
|
278
294
|
describe 'param type with `:param_type` given' do
|
279
|
-
let(:params)
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
295
|
+
let(:params) do
|
296
|
+
[
|
297
|
+
{ param_type: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
298
|
+
{ param_type: 'body', name: 'in_body', description: 'in_body', type: 'integer', format: 'int32', required: true },
|
299
|
+
{ param_type: 'query', name: 'in_query', description: 'in_query', type: 'integer', format: 'int32', required: true },
|
300
|
+
{ param_type: 'header', name: 'in_header', description: 'in_header', type: 'integer', format: 'int32', required: true },
|
301
|
+
{ param_type: 'formData', name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true }
|
302
|
+
]
|
303
|
+
end
|
304
|
+
|
305
|
+
let(:expected_params) do
|
306
|
+
[
|
307
|
+
{ name: 'key', description: nil, type: 'integer', format: 'int32', required: true, in: 'path' },
|
308
|
+
{ name: 'in_body', description: 'in_body', type: 'integer', format: 'int32', required: true, in: 'body' },
|
309
|
+
{ name: 'in_query', description: 'in_query', type: 'integer', format: 'int32', required: true, in: 'query' },
|
310
|
+
{ name: 'in_header', description: 'in_header', type: 'integer', format: 'int32', required: true, in: 'header' },
|
311
|
+
{ name: 'in_form_data', description: 'in_form_data', type: 'integer', format: 'int32', required: true, in: 'body' }
|
312
|
+
]
|
313
|
+
end
|
294
314
|
it { expect(params).to eql expected_params }
|
295
315
|
end
|
296
316
|
end
|