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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -3
  3. data/.rubocop_todo.yml +43 -33
  4. data/.travis.yml +22 -13
  5. data/CHANGELOG.md +29 -53
  6. data/Gemfile +1 -1
  7. data/README.md +24 -24
  8. data/example/api/endpoints.rb +28 -29
  9. data/example/api/entities.rb +1 -1
  10. data/example/config.ru +5 -7
  11. data/grape-swagger.gemspec +1 -1
  12. data/lib/grape-swagger.rb +9 -6
  13. data/lib/grape-swagger/doc_methods.rb +1 -1
  14. data/lib/grape-swagger/doc_methods/extensions.rb +3 -3
  15. data/lib/grape-swagger/doc_methods/headers.rb +1 -1
  16. data/lib/grape-swagger/doc_methods/move_params.rb +25 -16
  17. data/lib/grape-swagger/doc_methods/operation_id.rb +2 -2
  18. data/lib/grape-swagger/doc_methods/parse_params.rb +12 -5
  19. data/lib/grape-swagger/doc_methods/path_string.rb +1 -1
  20. data/lib/grape-swagger/doc_methods/status_codes.rb +3 -1
  21. data/lib/grape-swagger/doc_methods/tag_name_description.rb +1 -1
  22. data/lib/grape-swagger/endpoint.rb +33 -46
  23. data/lib/grape-swagger/grape/route.rb +16 -0
  24. data/lib/grape-swagger/version.rb +1 -1
  25. data/spec/issues/403_versions_spec.rb +158 -0
  26. data/spec/lib/data_type_spec.rb +9 -10
  27. data/spec/lib/endpoint_spec.rb +1 -2
  28. data/spec/lib/extensions_spec.rb +44 -40
  29. data/spec/lib/move_params_spec.rb +113 -93
  30. data/spec/lib/operation_id_spec.rb +42 -12
  31. data/spec/lib/optional_object_spec.rb +3 -4
  32. data/spec/lib/path_string_spec.rb +2 -2
  33. data/spec/lib/produces_consumes_spec.rb +64 -53
  34. data/spec/markdown/redcarpet_adapter_spec.rb +1 -1
  35. data/spec/spec_helper.rb +1 -1
  36. data/spec/support/api_swagger_v2_result.rb +122 -128
  37. data/spec/support/namespace_tags.rb +17 -19
  38. data/spec/support/the_api_entities.rb +1 -3
  39. data/spec/support/the_paths_definitions.rb +95 -85
  40. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +1 -1
  41. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +19 -19
  42. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +21 -21
  43. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +34 -32
  44. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +5 -7
  45. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +19 -18
  46. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +9 -10
  47. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +21 -24
  48. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +90 -92
  49. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +54 -54
  50. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +65 -57
  51. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +17 -14
  52. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +79 -123
  53. data/spec/swagger_v2/api_swagger_v2_spec.rb +33 -34
  54. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +32 -36
  55. data/spec/swagger_v2/boolean_params_spec.rb +1 -1
  56. data/spec/swagger_v2/default_api_spec.rb +26 -29
  57. data/spec/swagger_v2/description_not_initialized.rb +3 -3
  58. data/spec/swagger_v2/float_api_spec.rb +1 -1
  59. data/spec/swagger_v2/form_params_spec.rb +4 -4
  60. data/spec/swagger_v2/hide_api_spec.rb +48 -51
  61. data/spec/swagger_v2/host.rb +1 -1
  62. data/spec/swagger_v2/mounted_target_class_spec.rb +31 -33
  63. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +23 -21
  64. data/spec/swagger_v2/namespace_tags_spec.rb +23 -20
  65. data/spec/swagger_v2/param_type_spec.rb +5 -6
  66. data/spec/swagger_v2/param_values_spec.rb +31 -37
  67. data/spec/swagger_v2/params_array_spec.rb +17 -15
  68. data/spec/swagger_v2/params_hash_spec.rb +17 -15
  69. data/spec/swagger_v2/params_nested_spec.rb +12 -10
  70. data/spec/swagger_v2/reference_entity.rb +9 -9
  71. data/spec/swagger_v2/response_model_spec.rb +58 -62
  72. data/spec/swagger_v2/simple_mounted_api_spec.rb +179 -147
  73. metadata +5 -10
  74. 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']["/action"]['post']['parameters']
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
- "in"=>"formData",
28
- "name"=>"input",
29
- "description"=>nil,
30
- "type"=>"string",
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
- "in"=>"formData",
49
- "name"=>"letter",
50
- "description"=>nil,
51
- "type"=>"string",
52
- "required"=>true,
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
- "in"=>"formData",
64
- "name"=>"letter",
65
- "description"=>nil,
66
- "type"=>"string",
67
- "required"=>true,
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
- "in"=>"formData",
79
- "name"=>"letter",
80
- "description"=>nil,
81
- "type"=>"string",
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
- "in"=>"formData",
91
- "name"=>"integer",
92
- "description"=>nil,
93
- "type"=>"integer",
94
- "required"=>true,
95
- "format"=>"int32",
96
- "minimum"=>-5,
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
- "in"=>"formData",
137
- "name"=>"letter",
138
- "description"=>nil,
139
- "type"=>"string",
140
- "required"=>true,
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
- "in"=>"formData",
152
- "name"=>"float",
153
- "description"=>nil,
154
- "type"=>"number",
155
- "required"=>true,
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: "integer given"
21
- requires :name, type: String, desc: "string given"
22
- optional :email, type: String, desc: "email given"
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 "retrieves the documentation for grouped parameters" do
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
- {"in"=>"formData", "name"=>"required_group[][required_param_1]", "description"=>nil, "required"=>true, "type"=>"array", "items"=>{"type"=>"string"}},
43
- {"in"=>"formData", "name"=>"required_group[][required_param_2]", "description"=>nil, "required"=>true, "type"=>"array", "items"=>{"type"=>"string"}}
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 "retrieves the documentation for typed group parameters" do
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
- {"in"=>"formData", "name"=>"typed_group[][id]", "description"=>"integer given", "required"=>true, "type"=>"array", "items"=>{"type"=>"integer"}},
57
- {"in"=>"formData", "name"=>"typed_group[][name]", "description"=>"string given", "required"=>true, "type"=>"array", "items"=>{"type"=>"string"}},
58
- {"in"=>"formData", "name"=>"typed_group[][email]", "description"=>"email given", "required"=>false, "type"=>"array", "items"=>{"type"=>"string"}},
59
- {"in"=>"formData", "name"=>"typed_group[][others]", "description"=>nil, "required"=>false, "type"=>"array", "items"=>{"type"=>"integer"}, "enum"=>[1, 2, 3]}
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: "integer given"
21
- requires :name, type: String, desc: "string given"
22
- optional :email, type: String, desc: "email given"
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 "grouped parameters" do
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
- {"in"=>"formData", "name"=>"required_group[required_param_1]", "description"=>nil, "type"=>"string", "required"=>true},
44
- {"in"=>"formData", "name"=>"required_group[required_param_2]", "description"=>nil, "type"=>"string", "required"=>true}
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 "grouped parameters with given type" do
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
- {"in"=>"formData", "name"=>"typed_group[id]", "description"=>"integer given", "type"=>"integer", "required"=>true, "format"=>"int32"},
59
- {"in"=>"formData", "name"=>"typed_group[name]", "description"=>"string given", "type"=>"string", "required"=>true},
60
- {"in"=>"formData", "name"=>"typed_group[email]", "description"=>"email given", "type"=>"string", "required"=>false},
61
- {"in"=>"formData", "name"=>"typed_group[others]", "description"=>nil, "type"=>"integer", "required"=>false, "format"=>"int32", "enum"=>[1, 2, 3]}
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 "retrieves the documentation for nested array parameters" do
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
- {"in"=>"formData", "name"=>"a_array[][param_1]", "description"=>nil, "required"=>true, "type"=>"array", "items"=>{"type"=>"integer"}},
45
- {"in"=>"formData", "name"=>"a_array[][b_array][][param_2]", "description"=>nil, "required"=>true, "type"=>"array", "items"=>{"type"=>"string"}}
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 "retrieves the documentation for nested hash parameters" do
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
- {"in"=>"formData", "name"=>"a_hash[param_1]", "description"=>nil, "required"=>true, "type"=>"integer", "format"=>"int32"},
59
- {"in"=>"formData", "name"=>"a_hash[b_hash][param_2]", "description"=>nil, "required"=>true, "type"=>"string"}
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
- "in"=>"query",
58
- "name"=>"something",
59
- "description"=>"something as parameter",
60
- "type"=>"string",
61
- "required"=>false,
62
- "allowMultiple"=>false
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
- "type"=>"object", "properties"=>{"text"=>{"type"=>"string"}}
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
- "properties" => {"something"=>{"$ref"=>"#/definitions/Something"}}
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
- is_array: true,
38
- http_codes: [ { code: 200, message: 'OK', model: Entities::Something } ]
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 "documents index action" do
79
- expect(subject['paths']["/something"]["get"]["responses"]).to eq(
80
- {
81
- "200"=>{
82
- "description"=>"OK",
83
- "schema"=>{
84
- "type"=>"array",
85
- "items"=>{"$ref"=>"#/definitions/Something"}}
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']["/something/{id}"]["get"]["responses"]).to eq(
92
- {
93
- "200"=>{
94
- "description"=>"OK",
95
- "schema"=>{"$ref"=>"#/definitions/Something"}
96
- },
97
- "403"=>{
98
- "description"=>"Refused to return something",
99
- "schema"=>{"$ref"=>"#/definitions/Error"}
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
- "type"=>"object",
106
- "description" => "This returns something or an error",
107
- "properties"=>{
108
- "code"=>{"type"=>"string","description"=>"Error code"},
109
- "message"=>{"type"=>"string","description"=>"Error message"}
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
- { "type"=>"object",
116
- "description" => "This returns something or an error",
117
- "properties"=>
118
- { "text"=>{"type"=>"string","description"=>"Content of something."},
119
- "kind"=>{"$ref"=>"#/definitions/Kind","description"=>"The kind of this something."},
120
- "kind2"=>{"$ref"=>"#/definitions/Kind","description"=>"Secondary kind."},
121
- "kind3"=>{"$ref"=>"#/definitions/Kind","description"=>"Tertiary kind."},
122
- "tags"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/Tag"},"description"=>"Tags."},
123
- "relation"=>{"$ref"=>"#/definitions/Relation","description"=>"A related model."}}}
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
- "type"=>"object", "properties"=>{"title"=>{"type"=>"string","description"=>"Title of the kind."}}
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
- "type"=>"object", "properties"=>{"name"=>{"type"=>"string","description"=>"Name"}}
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
- "type"=>"object", "properties"=>{"name"=>{"type"=>"string","description"=>"Name"}}
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
- is_array: true,
174
- entity: Entities::SomeEntity
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 "it prefer entity over others" do
195
- expect(subject['definitions']).to eql({
196
- "Kind"=>{"type"=>"object", "properties"=>{"id"=>{"type"=>"integer", "format"=>"int32", "description"=>"Title of the kind."}}},
197
- "Tag"=>{"type"=>"object", "properties"=>{"name"=>{"type"=>"string", "description"=>"Name"}}},
198
- "Relation"=>{"type"=>"object", "properties"=>{"name"=>{"type"=>"string", "description"=>"Name"}}},
199
- "SomeEntity"=>{
200
- "type"=>"object",
201
- "properties"=>{
202
- "text"=>{"type"=>"string", "description"=>"Content of something."},
203
- "kind"=>{"$ref"=>"#/definitions/Kind", "description"=>"The kind of this something."},
204
- "kind2"=>{"$ref"=>"#/definitions/Kind", "description"=>"Secondary kind."},
205
- "kind3"=>{"$ref"=>"#/definitions/Kind", "description"=>"Tertiary kind."},
206
- "tags"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/Tag"}, "description"=>"Tags."},
207
- "relation"=>{"$ref"=>"#/definitions/Relation", "description"=>"A related model."}
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
- "description"=>"This returns something"
210
- }})
205
+ 'description' => 'This returns something'
206
+ })
211
207
  end
212
208
  end