grape-swagger 0.11.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -1
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +14 -22
  5. data/.travis.yml +7 -4
  6. data/CHANGELOG.md +53 -26
  7. data/Gemfile +1 -1
  8. data/README.md +414 -327
  9. data/RELEASING.md +3 -4
  10. data/example/api/endpoints.rb +132 -0
  11. data/example/api/entities.rb +18 -0
  12. data/example/config.ru +36 -2
  13. data/example/example_requests.postman_collection +146 -0
  14. data/example/swagger-example.png +0 -0
  15. data/grape-swagger.gemspec +9 -6
  16. data/lib/grape-swagger.rb +69 -99
  17. data/lib/grape-swagger/doc_methods.rb +69 -544
  18. data/lib/grape-swagger/doc_methods/data_type.rb +77 -0
  19. data/lib/grape-swagger/doc_methods/extensions.rb +75 -0
  20. data/lib/grape-swagger/doc_methods/move_params.rb +153 -0
  21. data/lib/grape-swagger/doc_methods/operation_id.rb +27 -0
  22. data/lib/grape-swagger/doc_methods/optional_object.rb +15 -0
  23. data/lib/grape-swagger/doc_methods/parse_params.rb +113 -0
  24. data/lib/grape-swagger/doc_methods/path_string.rb +29 -0
  25. data/lib/grape-swagger/doc_methods/produces_consumes.rb +12 -0
  26. data/lib/grape-swagger/doc_methods/status_codes.rb +17 -0
  27. data/lib/grape-swagger/doc_methods/tag_name_description.rb +26 -0
  28. data/lib/grape-swagger/endpoint.rb +317 -0
  29. data/lib/grape-swagger/version.rb +1 -1
  30. data/spec/lib/data_type_spec.rb +57 -0
  31. data/spec/lib/endpoint_spec.rb +6 -0
  32. data/spec/lib/extensions_spec.rb +127 -0
  33. data/spec/lib/move_params_spec.rb +298 -0
  34. data/spec/lib/operation_id_spec.rb +24 -0
  35. data/spec/lib/optional_object_spec.rb +40 -0
  36. data/spec/lib/path_string_spec.rb +38 -0
  37. data/spec/lib/produces_consumes_spec.rb +98 -0
  38. data/spec/markdown/kramdown_adapter_spec.rb +2 -9
  39. data/spec/markdown/redcarpet_adapter_spec.rb +2 -16
  40. data/spec/spec_helper.rb +7 -13
  41. data/spec/support/api_swagger_v2_result.rb +204 -0
  42. data/spec/support/namespace_tags.rb +73 -0
  43. data/spec/support/the_api_entities.rb +52 -0
  44. data/spec/support/the_paths_definitions.rb +94 -0
  45. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +32 -0
  46. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +151 -0
  47. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +109 -0
  48. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +124 -0
  49. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +51 -0
  50. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +44 -0
  51. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +56 -0
  52. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +146 -0
  53. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +197 -0
  54. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +151 -0
  55. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +217 -0
  56. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +64 -0
  57. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +184 -0
  58. data/spec/swagger_v2/api_swagger_v2_spec.rb +207 -0
  59. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +121 -0
  60. data/spec/{boolean_params_spec.rb → swagger_v2/boolean_params_spec.rb} +2 -2
  61. data/spec/{default_api_spec.rb → swagger_v2/default_api_spec.rb} +40 -36
  62. data/spec/swagger_v2/description_not_initialized.rb +39 -0
  63. data/spec/{float_api_spec.rb → swagger_v2/float_api_spec.rb} +2 -2
  64. data/spec/{form_params_spec.rb → swagger_v2/form_params_spec.rb} +9 -9
  65. data/spec/{grape-swagger_spec.rb → swagger_v2/grape-swagger_spec.rb} +0 -0
  66. data/spec/swagger_v2/hide_api_spec.rb +131 -0
  67. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  68. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +84 -0
  69. data/spec/swagger_v2/namespace_tags_spec.rb +76 -0
  70. data/spec/{namespaced_api_spec.rb → swagger_v2/namespaced_api_spec.rb} +6 -26
  71. data/spec/{param_type_spec.rb → swagger_v2/param_type_spec.rb} +10 -8
  72. data/spec/{param_values_spec.rb → swagger_v2/param_values_spec.rb} +52 -22
  73. data/spec/swagger_v2/params_array_spec.rb +63 -0
  74. data/spec/swagger_v2/params_hash_spec.rb +65 -0
  75. data/spec/swagger_v2/params_nested_spec.rb +63 -0
  76. data/spec/{reference_entity.rb → swagger_v2/reference_entity.rb} +18 -23
  77. data/spec/swagger_v2/response_model_spec.rb +212 -0
  78. data/spec/swagger_v2/simple_mounted_api_spec.rb +264 -0
  79. metadata +175 -90
  80. data/example/api.rb +0 -66
  81. data/lib/grape-swagger/markdown.rb +0 -23
  82. data/spec/api_description_spec.rb +0 -43
  83. data/spec/api_global_models_spec.rb +0 -77
  84. data/spec/api_models_spec.rb +0 -364
  85. data/spec/api_paths_spec.rb +0 -128
  86. data/spec/api_root_spec.rb +0 -30
  87. data/spec/api_with_nil_types.rb +0 -50
  88. data/spec/api_with_path_versioning_spec.rb +0 -33
  89. data/spec/api_with_prefix_and_namespace_spec.rb +0 -32
  90. data/spec/api_with_standalone_namespace_spec.rb +0 -215
  91. data/spec/array_entity_spec.rb +0 -34
  92. data/spec/array_params_spec.rb +0 -85
  93. data/spec/grape-swagger_helper_spec.rb +0 -152
  94. data/spec/group_params_spec.rb +0 -31
  95. data/spec/hash_params_spec.rb +0 -30
  96. data/spec/hide_api_spec.rb +0 -124
  97. data/spec/i18n_spec.rb +0 -364
  98. data/spec/markdown/markdown_spec.rb +0 -27
  99. data/spec/mounted_target_class_spec.rb +0 -63
  100. data/spec/mutually_exclusive_spec.rb +0 -36
  101. data/spec/non_default_api_spec.rb +0 -733
  102. data/spec/response_model_spec.rb +0 -121
  103. data/spec/simple_mounted_api_spec.rb +0 -213
  104. data/spec/support/i18n_helper.rb +0 -8
@@ -4,8 +4,8 @@ describe 'namespace' do
4
4
  context 'at root level' do
5
5
  def app
6
6
  Class.new(Grape::API) do
7
- namespace :aspace, desc: 'Description for aspace' do
8
- get '/'
7
+ namespace :aspace do
8
+ get '/', desc: 'Description for aspace'
9
9
  end
10
10
  add_swagger_documentation format: :json
11
11
  end
@@ -13,7 +13,7 @@ describe 'namespace' do
13
13
 
14
14
  subject do
15
15
  get '/swagger_doc'
16
- JSON.parse(last_response.body)['apis'][0]
16
+ JSON.parse(last_response.body)['paths']['/aspace']['get']
17
17
  end
18
18
 
19
19
  it 'shows the namespace description in the json spec' do
@@ -24,8 +24,8 @@ describe 'namespace' do
24
24
  context 'mounted' do
25
25
  def app
26
26
  namespaced_api = Class.new(Grape::API) do
27
- namespace :aspace, desc: 'Description for aspace' do
28
- get '/'
27
+ namespace :bspace do
28
+ get '/', desc: 'Description for aspace'
29
29
  end
30
30
  end
31
31
 
@@ -37,31 +37,11 @@ describe 'namespace' do
37
37
 
38
38
  subject do
39
39
  get '/swagger_doc'
40
- JSON.parse(last_response.body)['apis'][0]
40
+ JSON.parse(last_response.body)['paths']['/bspace']['get']
41
41
  end
42
42
 
43
43
  it 'shows the namespace description in the json spec' do
44
44
  expect(subject['description']).to eql('Description for aspace')
45
45
  end
46
46
  end
47
-
48
- context 'with camelcase endpoints' do
49
- def app
50
- Class.new(Grape::API) do
51
- namespace :SomeSpace, desc: 'Description for some space' do
52
- get '/'
53
- end
54
- add_swagger_documentation format: :json
55
- end
56
- end
57
-
58
- subject do
59
- get '/swagger_doc'
60
- JSON.parse(last_response.body)['apis'][0]
61
- end
62
-
63
- it 'shows the namespace description in the json spec' do
64
- expect(subject['description']).to eql('Description for some space')
65
- end
66
- end
67
47
  end
@@ -5,9 +5,8 @@ describe 'Params Types' do
5
5
  Class.new(Grape::API) do
6
6
  format :json
7
7
 
8
- desc 'description', nickname: 'desc', params: { input1: { type: Integer, param_type: 'query' } }
9
8
  params do
10
- requires :input2, type: String, documentation: { param_type: 'query' }
9
+ requires :input, type: String
11
10
  end
12
11
  post :action do
13
12
  end
@@ -20,14 +19,17 @@ describe 'Params Types' do
20
19
  get '/swagger_doc/action'
21
20
  expect(last_response.status).to eq 200
22
21
  body = JSON.parse last_response.body
23
- body['apis'].first['operations'].flat_map { |o| o['parameters'] }
22
+ body['paths']["/action"]['post']['parameters']
24
23
  end
25
24
 
26
25
  it 'reads param type correctly' do
27
- expect(subject).to match_array [
28
- { 'paramType' => 'query', 'name' => 'input1', 'description' => '', 'type' => 'integer', 'required' => false, 'allowMultiple' => false, 'format' => 'int32' },
29
- { 'paramType' => 'query', 'name' => 'input2', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false }
30
- ]
26
+ expect(subject).to eq [{
27
+ "in"=>"formData",
28
+ "name"=>"input",
29
+ "description"=>nil,
30
+ "type"=>"string",
31
+ "required"=>true
32
+ }]
31
33
  end
32
34
 
33
35
  describe 'header params' do
@@ -48,7 +50,7 @@ describe 'Params Types' do
48
50
 
49
51
  it 'has consistent types' do
50
52
  types = subject.map { |param| param['type'] }
51
- expect(types).to eq(%w(string string))
53
+ expect(types).to eq(%w(string))
52
54
  end
53
55
  end
54
56
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'grape_version'
2
+ # require 'grape_version'
3
3
 
4
4
  describe 'Convert values to enum or Range' do
5
5
  def app
@@ -38,16 +38,20 @@ describe 'Convert values to enum or Range' do
38
38
  get "/swagger_doc/#{request}"
39
39
  expect(last_response.status).to eq 200
40
40
  body = JSON.parse last_response.body
41
- body['apis'].first['operations'].first['parameters']
41
+ body['paths']["/#{request}"]['post']['parameters']
42
42
  end
43
43
 
44
44
  context 'Plain array values' do
45
45
  subject(:plain_array) { first_parameter_info('plain_array') }
46
-
47
46
  it 'has values as array in enum' do
48
- expect(plain_array).to eq [
49
- { 'paramType' => 'form', 'name' => 'letter', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false, 'enum' => %w(a b c) }
50
- ]
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"]
54
+ }]
51
55
  end
52
56
  end
53
57
 
@@ -55,9 +59,14 @@ describe 'Convert values to enum or Range' do
55
59
  subject(:array_in_proc) { first_parameter_info('array_in_proc') }
56
60
 
57
61
  it 'has proc returned values as array in enum' do
58
- expect(array_in_proc).to eq [
59
- { 'paramType' => 'form', 'name' => 'letter', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false, 'enum' => %w(d e f) }
60
- ]
62
+ 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"]
69
+ }]
61
70
  end
62
71
  end
63
72
 
@@ -65,17 +74,28 @@ describe 'Convert values to enum or Range' do
65
74
  subject(:range_letter) { first_parameter_info('range_letter') }
66
75
 
67
76
  it 'has letter range values' do
68
- expect(range_letter).to eq [
69
- { 'paramType' => 'form', 'name' => 'letter', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false }
70
- ]
77
+ expect(range_letter).to eq [{
78
+ "in"=>"formData",
79
+ "name"=>"letter",
80
+ "description"=>nil,
81
+ "type"=>"string",
82
+ "required"=>true
83
+ }]
71
84
  end
72
85
 
73
86
  subject(:range_integer) { first_parameter_info('range_integer') }
74
87
 
75
88
  it 'has integer range values' do
76
- expect(range_integer).to eq [
77
- { 'paramType' => 'form', 'name' => 'integer', 'description' => '', 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32', 'minimum' => -5, 'maximum' => 5 }
78
- ]
89
+ 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
98
+ }]
79
99
  end
80
100
  end
81
101
  end
@@ -105,16 +125,21 @@ describe 'Convert values to enum for float range and not arrays inside a proc',
105
125
  get "/swagger_doc/#{request}"
106
126
  expect(last_response.status).to eq 200
107
127
  body = JSON.parse last_response.body
108
- body['apis'].first['operations'].first['parameters']
128
+ body['paths']["/#{request}"]['post']['parameters']
109
129
  end
110
130
 
111
131
  context 'Non array in proc values' do
112
132
  subject(:non_array_in_proc) { first_parameter_info('non_array_in_proc') }
113
133
 
114
134
  it 'has proc returned value as string in enum' do
115
- expect(non_array_in_proc).to eq [
116
- { 'paramType' => 'form', 'name' => 'letter', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false, 'enum' => 'string' }
117
- ]
135
+ 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"
142
+ }]
118
143
  end
119
144
  end
120
145
 
@@ -122,9 +147,14 @@ describe 'Convert values to enum for float range and not arrays inside a proc',
122
147
  subject(:range_float) { first_parameter_info('range_float') }
123
148
 
124
149
  it 'has float range values as string' do
125
- expect(range_float).to eq [
126
- { 'paramType' => 'form', 'name' => 'float', 'description' => '', 'type' => 'number', 'format' => 'float', 'required' => true, 'allowMultiple' => false }
127
- ]
150
+ expect(range_float).to eq [{
151
+ "in"=>"formData",
152
+ "name"=>"float",
153
+ "description"=>nil,
154
+ "type"=>"number",
155
+ "required"=>true,
156
+ "format"=>"float"
157
+ }]
128
158
  end
129
159
  end
130
160
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Group Params as Array' do
4
+ def app
5
+ Class.new(Grape::API) do
6
+ format :json
7
+
8
+ params do
9
+ requires :required_group, type: Array do
10
+ requires :required_param_1
11
+ requires :required_param_2
12
+ end
13
+ end
14
+ post '/groups' do
15
+ { 'declared_params' => declared(params) }
16
+ end
17
+
18
+ params do
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"
23
+ optional :others, type: Integer, values: [1, 2, 3]
24
+ end
25
+ end
26
+ post '/type_given' do
27
+ { 'declared_params' => declared(params) }
28
+ end
29
+
30
+ add_swagger_documentation
31
+ end
32
+ end
33
+
34
+ describe "retrieves the documentation for grouped parameters" do
35
+ subject do
36
+ get '/swagger_doc/groups'
37
+ JSON.parse(last_response.body)
38
+ end
39
+
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
+ ])
45
+ end
46
+ end
47
+
48
+ describe "retrieves the documentation for typed group parameters" do
49
+ subject do
50
+ get '/swagger_doc/type_given'
51
+ JSON.parse(last_response.body)
52
+ end
53
+
54
+ 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
+ ])
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Group Params as Hash' do
4
+ def app
5
+ Class.new(Grape::API) do
6
+ format :json
7
+
8
+ params do
9
+ requires :required_group, type: Hash do
10
+ requires :required_param_1
11
+ requires :required_param_2
12
+ end
13
+ end
14
+ post '/use_groups' do
15
+ { 'declared_params' => declared(params) }
16
+ end
17
+
18
+ params do
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"
23
+ optional :others, type: Integer, values: [1, 2, 3]
24
+ end
25
+ end
26
+ post '/use_given_type' do
27
+ { 'declared_params' => declared(params) }
28
+ end
29
+
30
+ add_swagger_documentation
31
+ end
32
+ end
33
+
34
+ describe "grouped parameters" do
35
+ subject do
36
+ get '/swagger_doc/use_groups'
37
+ JSON.parse(last_response.body)
38
+ end
39
+
40
+ specify do
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
+ ])
46
+ end
47
+ end
48
+
49
+ describe "grouped parameters with given type" do
50
+ subject do
51
+ get '/swagger_doc/use_given_type'
52
+ JSON.parse(last_response.body)
53
+ end
54
+
55
+ specify do
56
+ 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
+ ])
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'nested group params' do
4
+ def app
5
+ Class.new(Grape::API) do
6
+ format :json
7
+
8
+ params do
9
+ requires :a_array, type: Array do
10
+ requires :param_1, type: Integer
11
+ requires :b_array, type: Array do
12
+ requires :param_2, type: String
13
+ end
14
+ end
15
+ end
16
+ post '/nested_array' do
17
+ { 'declared_params' => declared(params) }
18
+ end
19
+
20
+ params do
21
+ requires :a_hash, type: Hash do
22
+ requires :param_1, type: Integer
23
+ requires :b_hash, type: Hash do
24
+ requires :param_2, type: String
25
+ end
26
+ end
27
+ end
28
+ post '/nested_hash' do
29
+ { 'declared_params' => declared(params) }
30
+ end
31
+
32
+ add_swagger_documentation
33
+ end
34
+ end
35
+
36
+ describe "retrieves the documentation for nested array parameters" do
37
+ subject do
38
+ get '/swagger_doc/nested_array'
39
+ JSON.parse(last_response.body)
40
+ end
41
+
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
+ ])
47
+ end
48
+ end
49
+
50
+ describe "retrieves the documentation for nested hash parameters" do
51
+ subject do
52
+ get '/swagger_doc/nested_hash'
53
+ JSON.parse(last_response.body)
54
+ end
55
+
56
+ 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
+ ])
61
+ end
62
+ end
63
+ end
@@ -28,15 +28,17 @@ describe 'referenceEntity' do
28
28
  params: Entities::Kind.documentation.slice(:something),
29
29
  entity: Entities::Kind,
30
30
  http_codes: [
31
- [200, 'OK', Entities::Kind]
31
+ { code: 200, message: 'OK', model: Entities::Kind }
32
32
  ]
33
-
33
+ params do
34
+ optional :something, desc: 'something as parameter'
35
+ end
34
36
  get '/kind' do
35
37
  kind = OpenStruct.new text: 'kind'
36
38
  present kind, with: Entities::Kind
37
39
  end
38
40
 
39
- add_swagger_documentation models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
41
+ add_swagger_documentation #models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
40
42
  end
41
43
  end
42
44
  end
@@ -51,30 +53,23 @@ describe 'referenceEntity' do
51
53
  end
52
54
 
53
55
  it 'should document specified models' do
54
- expect(subject['apis'][0]['operations'][0]['parameters']).to eq [{
55
- 'paramType' => 'query',
56
- 'name' => 'something',
57
- 'description' => 'Something interesting.',
58
- 'type' => 'MySomething',
59
- 'required' => false,
60
- 'allowMultiple' => false
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
61
63
  }]
62
64
 
63
- expect(subject['models'].keys).to include 'MySomething'
64
- expect(subject['models']['MySomething']).to eq(
65
- 'id' => 'MyAPI::Something',
66
- 'properties' => {
67
- 'text' => { 'type' => 'string', 'description' => 'Content of something.' }
68
- }
65
+ expect(subject['definitions'].keys).to include 'Something'
66
+ expect(subject['definitions']['Something']).to eq(
67
+ "type"=>"object", "properties"=>{"text"=>{"type"=>"string"}}
69
68
  )
70
69
 
71
- expect(subject['models'].keys).to include 'MyKind'
72
- expect(subject['models']['MyKind']).to eq(
73
- 'id' => 'MyKind',
74
- 'properties' => {
75
- 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' },
76
- 'something' => { '$ref' => 'MySomething', 'description' => 'Something interesting.' }
77
- }
70
+ expect(subject['definitions'].keys).to include 'Kind'
71
+ expect(subject['definitions']['Kind']).to eq(
72
+ "properties" => {"something"=>{"$ref"=>"#/definitions/Something"}}
78
73
  )
79
74
  end
80
75
  end