grape-swagger 0.20.2 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -19,16 +19,15 @@ describe 'Params Types' do
|
|
19
19
|
get '/swagger_doc/action'
|
20
20
|
expect(last_response.status).to eq 200
|
21
21
|
body = JSON.parse last_response.body
|
22
|
-
body['paths'][
|
22
|
+
body['paths']['/action']['post']['parameters']
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'reads param type correctly' do
|
26
26
|
expect(subject).to eq [{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
"required"=>true
|
27
|
+
'in' => 'formData',
|
28
|
+
'name' => 'input',
|
29
|
+
'type' => 'string',
|
30
|
+
'required' => true
|
32
31
|
}]
|
33
32
|
end
|
34
33
|
|
@@ -45,12 +45,11 @@ describe 'Convert values to enum or Range' do
|
|
45
45
|
subject(:plain_array) { first_parameter_info('plain_array') }
|
46
46
|
it 'has values as array in enum' do
|
47
47
|
expect(plain_array).to eq [{
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
"enum"=>["a", "b", "c"]
|
48
|
+
'in' => 'formData',
|
49
|
+
'name' => 'letter',
|
50
|
+
'type' => 'string',
|
51
|
+
'required' => true,
|
52
|
+
'enum' => %w(a b c)
|
54
53
|
}]
|
55
54
|
end
|
56
55
|
end
|
@@ -60,12 +59,11 @@ describe 'Convert values to enum or Range' do
|
|
60
59
|
|
61
60
|
it 'has proc returned values as array in enum' do
|
62
61
|
expect(array_in_proc).to eq [{
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"enum"=>["d", "e", "f"]
|
62
|
+
'in' => 'formData',
|
63
|
+
'name' => 'letter',
|
64
|
+
'type' => 'string',
|
65
|
+
'required' => true,
|
66
|
+
'enum' => %w(d e f)
|
69
67
|
}]
|
70
68
|
end
|
71
69
|
end
|
@@ -75,11 +73,10 @@ describe 'Convert values to enum or Range' do
|
|
75
73
|
|
76
74
|
it 'has letter range values' do
|
77
75
|
expect(range_letter).to eq [{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
"required"=>true
|
76
|
+
'in' => 'formData',
|
77
|
+
'name' => 'letter',
|
78
|
+
'type' => 'string',
|
79
|
+
'required' => true
|
83
80
|
}]
|
84
81
|
end
|
85
82
|
|
@@ -87,14 +84,13 @@ describe 'Convert values to enum or Range' do
|
|
87
84
|
|
88
85
|
it 'has integer range values' do
|
89
86
|
expect(range_integer).to eq [{
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
"maximum"=>5
|
87
|
+
'in' => 'formData',
|
88
|
+
'name' => 'integer',
|
89
|
+
'type' => 'integer',
|
90
|
+
'required' => true,
|
91
|
+
'format' => 'int32',
|
92
|
+
'minimum' => -5,
|
93
|
+
'maximum' => 5
|
98
94
|
}]
|
99
95
|
end
|
100
96
|
end
|
@@ -133,12 +129,11 @@ describe 'Convert values to enum for float range and not arrays inside a proc',
|
|
133
129
|
|
134
130
|
it 'has proc returned value as string in enum' do
|
135
131
|
expect(non_array_in_proc).to eq [{
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
"enum"=>"string"
|
132
|
+
'in' => 'formData',
|
133
|
+
'name' => 'letter',
|
134
|
+
'type' => 'string',
|
135
|
+
'required' => true,
|
136
|
+
'enum' => 'string'
|
142
137
|
}]
|
143
138
|
end
|
144
139
|
end
|
@@ -148,12 +143,11 @@ describe 'Convert values to enum for float range and not arrays inside a proc',
|
|
148
143
|
|
149
144
|
it 'has float range values as string' do
|
150
145
|
expect(range_float).to eq [{
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
"format"=>"float"
|
146
|
+
'in' => 'formData',
|
147
|
+
'name' => 'float',
|
148
|
+
'type' => 'number',
|
149
|
+
'required' => true,
|
150
|
+
'format' => 'float'
|
157
151
|
}]
|
158
152
|
end
|
159
153
|
end
|
@@ -17,9 +17,9 @@ describe 'Group Params as Array' do
|
|
17
17
|
|
18
18
|
params do
|
19
19
|
requires :typed_group, type: Array do
|
20
|
-
requires :id, type: Integer, desc:
|
21
|
-
requires :name, type: String, desc:
|
22
|
-
optional :email, type: String, desc:
|
20
|
+
requires :id, type: Integer, desc: 'integer given'
|
21
|
+
requires :name, type: String, desc: 'string given'
|
22
|
+
optional :email, type: String, desc: 'email given'
|
23
23
|
optional :others, type: Integer, values: [1, 2, 3]
|
24
24
|
end
|
25
25
|
end
|
@@ -31,33 +31,35 @@ describe 'Group Params as Array' do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe 'retrieves the documentation for grouped parameters' do
|
35
35
|
subject do
|
36
36
|
get '/swagger_doc/groups'
|
37
37
|
JSON.parse(last_response.body)
|
38
38
|
end
|
39
39
|
|
40
40
|
specify do
|
41
|
-
expect(subject['paths']['/groups']['post']['parameters']).to eql(
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
expect(subject['paths']['/groups']['post']['parameters']).to eql(
|
42
|
+
[
|
43
|
+
{ 'in' => 'formData', 'name' => 'required_group[][required_param_1]', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
44
|
+
{ 'in' => 'formData', 'name' => 'required_group[][required_param_2]', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } }
|
45
|
+
])
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
describe
|
49
|
+
describe 'retrieves the documentation for typed group parameters' do
|
49
50
|
subject do
|
50
51
|
get '/swagger_doc/type_given'
|
51
52
|
JSON.parse(last_response.body)
|
52
53
|
end
|
53
54
|
|
54
55
|
specify do
|
55
|
-
expect(subject['paths']['/type_given']['post']['parameters']).to eql(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
expect(subject['paths']['/type_given']['post']['parameters']).to eql(
|
57
|
+
[
|
58
|
+
{ 'in' => 'formData', 'name' => 'typed_group[][id]', 'description' => 'integer given', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'integer' } },
|
59
|
+
{ 'in' => 'formData', 'name' => 'typed_group[][name]', 'description' => 'string given', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
60
|
+
{ 'in' => 'formData', 'name' => 'typed_group[][email]', 'description' => 'email given', 'required' => false, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
61
|
+
{ 'in' => 'formData', 'name' => 'typed_group[][others]', 'required' => false, 'type' => 'array', 'items' => { 'type' => 'integer' }, 'enum' => [1, 2, 3] }
|
62
|
+
])
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
@@ -17,9 +17,9 @@ describe 'Group Params as Hash' do
|
|
17
17
|
|
18
18
|
params do
|
19
19
|
requires :typed_group, type: Hash do
|
20
|
-
requires :id, type: Integer, desc:
|
21
|
-
requires :name, type: String, desc:
|
22
|
-
optional :email, type: String, desc:
|
20
|
+
requires :id, type: Integer, desc: 'integer given'
|
21
|
+
requires :name, type: String, desc: 'string given'
|
22
|
+
optional :email, type: String, desc: 'email given'
|
23
23
|
optional :others, type: Integer, values: [1, 2, 3]
|
24
24
|
end
|
25
25
|
end
|
@@ -31,7 +31,7 @@ describe 'Group Params as Hash' do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe 'grouped parameters' do
|
35
35
|
subject do
|
36
36
|
get '/swagger_doc/use_groups'
|
37
37
|
JSON.parse(last_response.body)
|
@@ -39,14 +39,15 @@ describe 'Group Params as Hash' do
|
|
39
39
|
|
40
40
|
specify do
|
41
41
|
expect(subject['paths']['/use_groups']['post']).to include('parameters')
|
42
|
-
expect(subject['paths']['/use_groups']['post']['parameters']).to eql(
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
expect(subject['paths']['/use_groups']['post']['parameters']).to eql(
|
43
|
+
[
|
44
|
+
{ 'in' => 'formData', 'name' => 'required_group[required_param_1]', 'type' => 'string', 'required' => true },
|
45
|
+
{ 'in' => 'formData', 'name' => 'required_group[required_param_2]', 'type' => 'string', 'required' => true }
|
46
|
+
])
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
describe
|
50
|
+
describe 'grouped parameters with given type' do
|
50
51
|
subject do
|
51
52
|
get '/swagger_doc/use_given_type'
|
52
53
|
JSON.parse(last_response.body)
|
@@ -54,12 +55,13 @@ describe 'Group Params as Hash' do
|
|
54
55
|
|
55
56
|
specify do
|
56
57
|
expect(subject['paths']['/use_given_type']['post']).to include('parameters')
|
57
|
-
expect(subject['paths']['/use_given_type']['post']['parameters']).to eql(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
expect(subject['paths']['/use_given_type']['post']['parameters']).to eql(
|
59
|
+
[
|
60
|
+
{ 'in' => 'formData', 'name' => 'typed_group[id]', 'description' => 'integer given', 'type' => 'integer', 'required' => true, 'format' => 'int32' },
|
61
|
+
{ 'in' => 'formData', 'name' => 'typed_group[name]', 'description' => 'string given', 'type' => 'string', 'required' => true },
|
62
|
+
{ 'in' => 'formData', 'name' => 'typed_group[email]', 'description' => 'email given', 'type' => 'string', 'required' => false },
|
63
|
+
{ 'in' => 'formData', 'name' => 'typed_group[others]', 'type' => 'integer', 'required' => false, 'format' => 'int32', 'enum' => [1, 2, 3] }
|
64
|
+
])
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -33,31 +33,33 @@ describe 'nested group params' do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
36
|
+
describe 'retrieves the documentation for nested array parameters' do
|
37
37
|
subject do
|
38
38
|
get '/swagger_doc/nested_array'
|
39
39
|
JSON.parse(last_response.body)
|
40
40
|
end
|
41
41
|
|
42
42
|
specify do
|
43
|
-
expect(subject['paths']['/nested_array']['post']['parameters']).to eql(
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
expect(subject['paths']['/nested_array']['post']['parameters']).to eql(
|
44
|
+
[
|
45
|
+
{ 'in' => 'formData', 'name' => 'a_array[][param_1]', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'integer' } },
|
46
|
+
{ 'in' => 'formData', 'name' => 'a_array[][b_array][][param_2]', 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } }
|
47
|
+
])
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
describe
|
51
|
+
describe 'retrieves the documentation for nested hash parameters' do
|
51
52
|
subject do
|
52
53
|
get '/swagger_doc/nested_hash'
|
53
54
|
JSON.parse(last_response.body)
|
54
55
|
end
|
55
56
|
|
56
57
|
specify do
|
57
|
-
expect(subject['paths']['/nested_hash']['post']['parameters']).to eql(
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
expect(subject['paths']['/nested_hash']['post']['parameters']).to eql(
|
59
|
+
[
|
60
|
+
{ 'in' => 'formData', 'name' => 'a_hash[param_1]', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
|
61
|
+
{ 'in' => 'formData', 'name' => 'a_hash[b_hash][param_2]', 'required' => true, 'type' => 'string' }
|
62
|
+
])
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
@@ -38,7 +38,7 @@ describe 'referenceEntity' do
|
|
38
38
|
present kind, with: Entities::Kind
|
39
39
|
end
|
40
40
|
|
41
|
-
add_swagger_documentation #models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
|
41
|
+
add_swagger_documentation # models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -54,22 +54,22 @@ describe 'referenceEntity' do
|
|
54
54
|
|
55
55
|
it 'should document specified models' do
|
56
56
|
expect(subject['paths']['/kind']['get']['parameters']).to eq [{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
'in' => 'query',
|
58
|
+
'name' => 'something',
|
59
|
+
'description' => 'something as parameter',
|
60
|
+
'type' => 'string',
|
61
|
+
'required' => false,
|
62
|
+
'allowMultiple' => false
|
63
63
|
}]
|
64
64
|
|
65
65
|
expect(subject['definitions'].keys).to include 'Something'
|
66
66
|
expect(subject['definitions']['Something']).to eq(
|
67
|
-
|
67
|
+
'type' => 'object', 'properties' => { 'text' => { 'type' => 'string' } }
|
68
68
|
)
|
69
69
|
|
70
70
|
expect(subject['definitions'].keys).to include 'Kind'
|
71
71
|
expect(subject['definitions']['Kind']).to eq(
|
72
|
-
|
72
|
+
'properties' => { 'something' => { '$ref' => '#/definitions/Something' } }
|
73
73
|
)
|
74
74
|
end
|
75
75
|
end
|
@@ -10,11 +10,9 @@ describe 'responseModel' do
|
|
10
10
|
|
11
11
|
class Relation < Grape::Entity
|
12
12
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
13
|
-
|
14
13
|
end
|
15
14
|
class Tag < Grape::Entity
|
16
15
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
17
|
-
|
18
16
|
end
|
19
17
|
class Error < Grape::Entity
|
20
18
|
expose :code, documentation: { type: 'string', desc: 'Error code' }
|
@@ -34,8 +32,8 @@ describe 'responseModel' do
|
|
34
32
|
class ResponseModelApi < Grape::API
|
35
33
|
format :json
|
36
34
|
desc 'This returns something',
|
37
|
-
|
38
|
-
|
35
|
+
is_array: true,
|
36
|
+
http_codes: [{ code: 200, message: 'OK', model: Entities::Something }]
|
39
37
|
get '/something' do
|
40
38
|
something = OpenStruct.new text: 'something'
|
41
39
|
present something, with: Entities::Something
|
@@ -75,67 +73,64 @@ describe 'responseModel' do
|
|
75
73
|
JSON.parse(last_response.body)
|
76
74
|
end
|
77
75
|
|
78
|
-
it
|
79
|
-
expect(subject['paths'][
|
80
|
-
{
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}}
|
76
|
+
it 'documents index action' do
|
77
|
+
expect(subject['paths']['/something']['get']['responses']).to eq(
|
78
|
+
'200' => {
|
79
|
+
'description' => 'OK',
|
80
|
+
'schema' => {
|
81
|
+
'type' => 'array',
|
82
|
+
'items' => { '$ref' => '#/definitions/Something' } }
|
83
|
+
}
|
87
84
|
)
|
88
85
|
end
|
89
86
|
|
90
87
|
it 'should document specified models as show action' do
|
91
|
-
expect(subject['paths'][
|
92
|
-
{
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}}
|
88
|
+
expect(subject['paths']['/something/{id}']['get']['responses']).to eq(
|
89
|
+
'200' => {
|
90
|
+
'description' => 'OK',
|
91
|
+
'schema' => { '$ref' => '#/definitions/Something' }
|
92
|
+
},
|
93
|
+
'403' => {
|
94
|
+
'description' => 'Refused to return something',
|
95
|
+
'schema' => { '$ref' => '#/definitions/Error' }
|
96
|
+
}
|
101
97
|
)
|
102
98
|
expect(subject['definitions'].keys).to include 'Error'
|
103
99
|
expect(subject['definitions']['Error']).to eq(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
}}
|
100
|
+
'type' => 'object',
|
101
|
+
'description' => 'This returns something or an error',
|
102
|
+
'properties' => {
|
103
|
+
'code' => { 'type' => 'string', 'description' => 'Error code' },
|
104
|
+
'message' => { 'type' => 'string', 'description' => 'Error message' }
|
105
|
+
}
|
111
106
|
)
|
112
107
|
|
113
108
|
expect(subject['definitions'].keys).to include 'Something'
|
114
109
|
expect(subject['definitions']['Something']).to eq(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
110
|
+
'type' => 'object',
|
111
|
+
'description' => 'This returns something or an error',
|
112
|
+
'properties' =>
|
113
|
+
{ 'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
114
|
+
'kind' => { '$ref' => '#/definitions/Kind', 'description' => 'The kind of this something.' },
|
115
|
+
'kind2' => { '$ref' => '#/definitions/Kind', 'description' => 'Secondary kind.' },
|
116
|
+
'kind3' => { '$ref' => '#/definitions/Kind', 'description' => 'Tertiary kind.' },
|
117
|
+
'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/Tag' }, 'description' => 'Tags.' },
|
118
|
+
'relation' => { '$ref' => '#/definitions/Relation', 'description' => 'A related model.' } }
|
124
119
|
)
|
125
120
|
|
126
121
|
expect(subject['definitions'].keys).to include 'Kind'
|
127
122
|
expect(subject['definitions']['Kind']).to eq(
|
128
|
-
|
123
|
+
'type' => 'object', 'properties' => { 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' } }
|
129
124
|
)
|
130
125
|
|
131
126
|
expect(subject['definitions'].keys).to include 'Relation'
|
132
127
|
expect(subject['definitions']['Relation']).to eq(
|
133
|
-
|
128
|
+
'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } }
|
134
129
|
)
|
135
130
|
|
136
131
|
expect(subject['definitions'].keys).to include 'Tag'
|
137
132
|
expect(subject['definitions']['Tag']).to eq(
|
138
|
-
|
133
|
+
'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } }
|
139
134
|
)
|
140
135
|
end
|
141
136
|
end
|
@@ -150,11 +145,9 @@ describe 'should build definition from given entity' do
|
|
150
145
|
|
151
146
|
class Relation < Grape::Entity
|
152
147
|
expose :name, documentation: { type: String, desc: 'Name' }
|
153
|
-
|
154
148
|
end
|
155
149
|
class Tag < Grape::Entity
|
156
150
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
157
|
-
|
158
151
|
end
|
159
152
|
|
160
153
|
class SomeEntity < Grape::Entity
|
@@ -170,8 +163,8 @@ describe 'should build definition from given entity' do
|
|
170
163
|
class ResponseEntityApi < Grape::API
|
171
164
|
format :json
|
172
165
|
desc 'This returns something',
|
173
|
-
|
174
|
-
|
166
|
+
is_array: true,
|
167
|
+
entity: Entities::SomeEntity
|
175
168
|
get '/some_entity' do
|
176
169
|
something = OpenStruct.new text: 'something'
|
177
170
|
present something, with: Entities::SomeEntity
|
@@ -191,22 +184,25 @@ describe 'should build definition from given entity' do
|
|
191
184
|
JSON.parse(last_response.body)
|
192
185
|
end
|
193
186
|
|
194
|
-
it
|
195
|
-
expect(subject['definitions']).to eql(
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
187
|
+
it 'it prefer entity over others' do
|
188
|
+
expect(subject['definitions']).to eql(
|
189
|
+
'Kind' => {
|
190
|
+
'type' => 'object',
|
191
|
+
'properties' => {
|
192
|
+
'id' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Title of the kind.' } } },
|
193
|
+
'Tag' => { 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } },
|
194
|
+
'Relation' => { 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } },
|
195
|
+
'SomeEntity' => {
|
196
|
+
'type' => 'object',
|
197
|
+
'properties' => {
|
198
|
+
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
199
|
+
'kind' => { '$ref' => '#/definitions/Kind', 'description' => 'The kind of this something.' },
|
200
|
+
'kind2' => { '$ref' => '#/definitions/Kind', 'description' => 'Secondary kind.' },
|
201
|
+
'kind3' => { '$ref' => '#/definitions/Kind', 'description' => 'Tertiary kind.' },
|
202
|
+
'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/Tag' }, 'description' => 'Tags.' },
|
203
|
+
'relation' => { '$ref' => '#/definitions/Relation', 'description' => 'A related model.' }
|
208
204
|
},
|
209
|
-
|
210
|
-
}
|
205
|
+
'description' => 'This returns something'
|
206
|
+
})
|
211
207
|
end
|
212
208
|
end
|