grape-swagger 1.4.0 → 1.5.0

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/ci.yml +45 -0
  4. data/.gitignore +1 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +8 -1
  7. data/.rubocop_todo.yml +31 -11
  8. data/CHANGELOG.md +49 -1
  9. data/CONTRIBUTING.md +1 -1
  10. data/Gemfile +6 -3
  11. data/README.md +40 -8
  12. data/UPGRADING.md +15 -0
  13. data/example/config.ru +2 -2
  14. data/grape-swagger.gemspec +3 -2
  15. data/lib/grape-swagger/doc_methods/build_model_definition.rb +1 -20
  16. data/lib/grape-swagger/doc_methods/format_data.rb +2 -0
  17. data/lib/grape-swagger/doc_methods/move_params.rb +13 -15
  18. data/lib/grape-swagger/doc_methods/parse_params.rb +34 -6
  19. data/lib/grape-swagger/endpoint.rb +27 -1
  20. data/lib/grape-swagger/rake/oapi_tasks.rb +37 -17
  21. data/lib/grape-swagger/version.rb +1 -1
  22. data/lib/grape-swagger.rb +2 -2
  23. data/spec/issues/579_align_put_post_parameters_spec.rb +5 -5
  24. data/spec/issues/751_deeply_nested_objects_spec.rb +2 -2
  25. data/spec/issues/832_array_hash_float_decimal_spec.rb +111 -0
  26. data/spec/issues/847_route_param_options_spec.rb +37 -0
  27. data/spec/lib/move_params_spec.rb +55 -41
  28. data/spec/lib/oapi_tasks_spec.rb +16 -9
  29. data/spec/spec_helper.rb +0 -4
  30. data/spec/support/the_paths_definitions.rb +4 -4
  31. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  32. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +79 -7
  33. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +7 -7
  34. data/spec/swagger_v2/boolean_params_spec.rb +3 -1
  35. data/spec/swagger_v2/param_values_spec.rb +1 -1
  36. metadata +11 -111
  37. data/.github/workflows/rubocop.yml +0 -26
  38. data/.github/workflows/ruby.yml +0 -32
@@ -348,13 +348,39 @@ module Grape
348
348
  end
349
349
 
350
350
  def merge_params(route)
351
+ path_params = get_path_params(route.app&.inheritable_setting&.namespace_stackable)
351
352
  param_keys = route.params.keys
353
+
354
+ # Merge path params options into route params
355
+ route_params = route.params
356
+ route_params.each_key do |key|
357
+ path = path_params[key] || {}
358
+ params = route_params[key]
359
+ params = {} unless params.is_a? Hash
360
+ route_params[key] = path.merge(params)
361
+ end
362
+
352
363
  route.params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
353
364
  end
354
365
 
366
+ # Iterates over namespaces recursively
367
+ # to build a hash of path params with options, including type
368
+ def get_path_params(stackable_values)
369
+ params = {}
370
+ return param unless stackable_values
371
+ return params unless stackable_values.is_a? Grape::Util::StackableValues
372
+
373
+ stackable_values&.new_values&.dig(:namespace)&.each do |namespace|
374
+ space = namespace.space.to_s.gsub(':', '')
375
+ params[space] = namespace.options || {}
376
+ end
377
+ inherited_params = get_path_params(stackable_values.inherited_values)
378
+ inherited_params.merge(params)
379
+ end
380
+
355
381
  def default_type(params)
356
382
  default_param_type = { required: true, type: 'Integer' }
357
- params.each { |param| param[-1] = param.last == '' ? default_param_type : param.last }
383
+ params.each { |param| param[-1] = param.last.empty? ? default_param_type : param.last }
358
384
  end
359
385
 
360
386
  def expose_params(value)
@@ -46,9 +46,12 @@ module GrapeSwagger
46
46
  resource - if given only for that it would be generated (optional)'
47
47
  task fetch: :environment do
48
48
  # :nocov:
49
- make_request
49
+ urls_for(api_class).each do |url|
50
+ make_request(url)
51
+
52
+ save_to_file? ? File.write(file(url), @oapi) : $stdout.print(@oapi)
53
+ end
50
54
 
51
- save_to_file? ? File.write(file, @oapi) : $stdout.print(@oapi)
52
55
  # :nocov:
53
56
  end
54
57
  end
@@ -64,10 +67,15 @@ module GrapeSwagger
64
67
  ::Rake::Task['oapi:fetch'].invoke
65
68
  exit if error?
66
69
 
67
- output = system "swagger validate #{file}"
70
+ urls_for(api_class).each do |url|
71
+ @output = system "swagger-cli validate #{file(url)}"
72
+
73
+ FileUtils.rm(
74
+ file(url)
75
+ )
76
+ end
68
77
 
69
- $stdout.puts 'install swagger-cli with `npm install swagger-cli -g`' if output.nil?
70
- FileUtils.rm(file)
78
+ $stdout.puts 'install swagger-cli with `npm install swagger-cli -g`' if @output.nil?
71
79
  # :nocov:
72
80
  end
73
81
  end
@@ -75,23 +83,28 @@ module GrapeSwagger
75
83
  # helper methods
76
84
  #
77
85
  # rubocop:disable Style/StringConcatenation
78
- def make_request
79
- get url_for
86
+ def make_request(url)
87
+ get url
80
88
 
81
89
  @oapi = JSON.pretty_generate(
82
- JSON.parse(
83
- last_response.body, symolize_names: true
84
- )
90
+ JSON.parse(last_response.body, symolize_names: true)
85
91
  ) + "\n"
86
92
  end
87
93
  # rubocop:enable Style/StringConcatenation
88
94
 
89
- def url_for
90
- oapi_route = api_class.routes[-2]
91
- path = oapi_route.path.sub(/\(\.\w+\)$/, '').sub(/\(\.:\w+\)$/, '')
92
- path.sub!(':version', oapi_route.version.to_s)
95
+ def urls_for(api_class)
96
+ api_class.routes
97
+ .map(&:path)
98
+ .select { |e| e.include?('doc') }
99
+ .reject { |e| e.include?(':name') }
100
+ .map { |e| format_path(e) }
101
+ .map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }
102
+ end
93
103
 
94
- [path, ENV['resource']].join('/').chomp('/')
104
+ def format_path(path)
105
+ oapi_route = api_class.routes.select { |e| e.path == path }.first
106
+ path = path.sub(/\(\.\w+\)$/, '').sub(/\(\.:\w+\)$/, '')
107
+ path.sub(':version', oapi_route.version.to_s)
95
108
  end
96
109
 
97
110
  def save_to_file?
@@ -102,8 +115,15 @@ module GrapeSwagger
102
115
  JSON.parse(@oapi).keys.first == 'error'
103
116
  end
104
117
 
105
- def file
106
- name = ENV['store'] == 'true' || ENV['store'].blank? ? 'swagger_doc.json' : ENV['store']
118
+ def file(url)
119
+ api_version = url.split('/').last
120
+
121
+ name = if ENV['store'] == 'true' || ENV['store'].blank?
122
+ "swagger_doc_#{api_version}.json"
123
+ else
124
+ ENV['store'].sub('.json', "_#{api_version}.json")
125
+ end
126
+
107
127
  File.join(Dir.getwd, name)
108
128
  end
109
129
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '1.4.0'
4
+ VERSION = '1.5.0'
5
5
  end
data/lib/grape-swagger.rb CHANGED
@@ -31,8 +31,8 @@ module SwaggerRouting
31
31
 
32
32
  # want to match emojis … ;)
33
33
  # route_match = route_match
34
- # .match('\/([\p{Alnum}|\p{Emoji}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\p{Emoji}|\-|\_]*)$')
35
- route_match = route_match.match('\/([\p{Alnum}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\-|\_]*)$')
34
+ # .match('\/([\p{Alnum}p{Emoji}\-\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}\p{Emoji}\-\_]*)$')
35
+ route_match = route_match.match('\/([\p{Alnum}\-\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}\-\_]*)$')
36
36
  next unless route_match
37
37
 
38
38
  resource = route_match.captures.first
@@ -103,8 +103,8 @@ describe '#579 put / post parameters spec' do
103
103
  [
104
104
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
105
105
  {
106
- 'name' => 'Issue579ImplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
107
- '$ref' => '#/definitions/putIssue579ImplicitBodyParameter'
106
+ 'name' => 'putIssue579ImplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
107
+ '$ref' => '#/definitions/putIssue579ImplicitBodyParameterGuid'
108
108
  }
109
109
  }
110
110
  ]
@@ -130,8 +130,8 @@ describe '#579 put / post parameters spec' do
130
130
  [
131
131
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
132
132
  {
133
- 'name' => 'Issue579ExplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
134
- '$ref' => '#/definitions/putIssue579ExplicitBodyParameter'
133
+ 'name' => 'putIssue579ExplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
134
+ '$ref' => '#/definitions/putIssue579ExplicitBodyParameterGuid'
135
135
  }
136
136
  }
137
137
  ]
@@ -157,7 +157,7 @@ describe '#579 put / post parameters spec' do
157
157
  [
158
158
  { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
159
159
  {
160
- 'name' => 'Issue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
160
+ 'name' => 'putIssue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
161
161
  '$ref' => '#/definitions/putIssue579NamespaceParamGuidBodyParameter'
162
162
  }
163
163
  }
@@ -75,7 +75,7 @@ describe '751 deeply nested objects' do
75
75
  end
76
76
 
77
77
  describe 'Correctness of vrp Points' do
78
- let(:get_points_response) { subject['definitions']['postVrpSubmit']['properties']['vrp']['properties']['points'] }
78
+ let(:get_points_response) { subject['definitions']['vrp']['properties']['vrp']['properties']['points'] }
79
79
  specify do
80
80
  expect(get_points_response).to eql(
81
81
  'type' => 'array',
@@ -111,7 +111,7 @@ describe '751 deeply nested objects' do
111
111
  end
112
112
 
113
113
  describe 'Correctness of vrp Services' do
114
- let(:get_service_response) { subject['definitions']['postVrpSubmit']['properties']['vrp']['properties']['services'] }
114
+ let(:get_service_response) { subject['definitions']['vrp']['properties']['vrp']['properties']['services'] }
115
115
  specify do
116
116
  expect(get_service_response).to include(
117
117
  'type' => 'array',
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#832 array of objects with nested Float/BigDecimal fields' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ resource :issue_832 do
9
+ params do
10
+ requires :array_param, type: Array do
11
+ requires :float_param, type: Float
12
+ requires :big_decimal_param, type: BigDecimal
13
+ requires :object_param, type: Hash do
14
+ requires :float_param, type: Float
15
+ requires :big_decimal_param, type: BigDecimal
16
+ requires :object_param, type: Hash do
17
+ requires :float_param, type: Float
18
+ requires :big_decimal_param, type: BigDecimal
19
+ requires :array_param, type: Array do
20
+ requires :integer_param, type: Integer
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ post do
27
+ { message: 'hello world' }
28
+ end
29
+ end
30
+
31
+ add_swagger_documentation
32
+ end
33
+ end
34
+ let(:parameters) { subject['paths']['/issue_832']['post']['parameters'] }
35
+
36
+ subject do
37
+ get '/swagger_doc'
38
+ JSON.parse(last_response.body)
39
+ end
40
+
41
+ specify do
42
+ expect(parameters).to eql(
43
+ [
44
+ {
45
+ 'in' => 'formData',
46
+ 'name' => 'array_param[float_param]',
47
+ 'type' => 'array',
48
+ 'required' => true,
49
+ 'items' => {
50
+ 'type' => 'number',
51
+ 'format' => 'float'
52
+ }
53
+ }, {
54
+ 'in' => 'formData',
55
+ 'name' => 'array_param[big_decimal_param]',
56
+ 'type' => 'array',
57
+ 'required' => true,
58
+ 'items' => {
59
+ 'type' => 'number',
60
+ 'format' => 'double'
61
+ }
62
+ }, {
63
+ 'in' => 'formData',
64
+ 'name' => 'array_param[object_param][float_param]',
65
+ 'type' => 'array',
66
+ 'required' => true,
67
+ 'items' => {
68
+ 'type' => 'number',
69
+ 'format' => 'float'
70
+ }
71
+ }, {
72
+ 'in' => 'formData',
73
+ 'name' => 'array_param[object_param][big_decimal_param]',
74
+ 'type' => 'array',
75
+ 'required' => true,
76
+ 'items' => {
77
+ 'type' => 'number',
78
+ 'format' => 'double'
79
+ }
80
+ }, {
81
+ 'in' => 'formData',
82
+ 'name' => 'array_param[object_param][object_param][float_param]',
83
+ 'type' => 'array',
84
+ 'required' => true,
85
+ 'items' => {
86
+ 'type' => 'number',
87
+ 'format' => 'float'
88
+ }
89
+ }, {
90
+ 'in' => 'formData',
91
+ 'name' => 'array_param[object_param][object_param][big_decimal_param]',
92
+ 'type' => 'array',
93
+ 'required' => true,
94
+ 'items' => {
95
+ 'type' => 'number',
96
+ 'format' => 'double'
97
+ }
98
+ }, {
99
+ 'in' => 'formData',
100
+ 'name' => 'array_param[object_param][object_param][array_param][integer_param]',
101
+ 'type' => 'array',
102
+ 'required' => true,
103
+ 'items' => {
104
+ 'type' => 'integer',
105
+ 'format' => 'int32'
106
+ }
107
+ }
108
+ ]
109
+ )
110
+ end
111
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#847 route_param type is included in documentation' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ resource :accounts do
9
+ route_param :account_number, type: String do
10
+ resource :records do
11
+ route_param :id do
12
+ get do
13
+ { message: 'hello world' }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ add_swagger_documentation
21
+ end
22
+ end
23
+ let(:parameters) { subject['paths']['/accounts/{account_number}/records/{id}']['get']['parameters'] }
24
+
25
+ subject do
26
+ get '/swagger_doc'
27
+ JSON.parse(last_response.body)
28
+ end
29
+
30
+ specify do
31
+ account_number_param = parameters.find { |param| param['name'] == 'account_number' }
32
+ expect(account_number_param['type']).to eq 'string'
33
+ id_param = parameters.find { |param| param['name'] == 'id' }
34
+ # Default is still integer
35
+ expect(id_param['type']).to eq 'integer'
36
+ end
37
+ end
@@ -103,15 +103,30 @@ describe GrapeSwagger::DocMethods::MoveParams do
103
103
  subject.to_definition(path, params, route, definitions)
104
104
  expect(params).to eql(
105
105
  [
106
- { name: 'InBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/postInBody' } }
106
+ { name: 'postInBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/postInBody' } }
107
107
  ]
108
108
  )
109
109
  expect(subject.definitions['postInBody']).not_to include :description
110
110
  expect(subject.definitions['postInBody']).to eql expected_post_defs
111
111
  end
112
+
113
+ context 'with a nickname' do
114
+ let(:route_options) { { nickname: 'post-body' } }
115
+
116
+ specify do
117
+ subject.to_definition(path, params, route, definitions)
118
+ expect(params).to eql(
119
+ [
120
+ { name: 'post-body', in: 'body', required: true, schema: { '$ref' => '#/definitions/post-body' } }
121
+ ]
122
+ )
123
+ expect(subject.definitions['post-body']).not_to include :description
124
+ expect(subject.definitions['post-body']).to eql expected_post_defs
125
+ end
126
+ end
112
127
  end
113
128
 
114
- describe 'POST' do
129
+ describe 'PUT' do
115
130
  let(:params) { paths['/in_body/{key}'][:put][:parameters] }
116
131
  let(:route) { Grape::Router::Route.new('PUT', path.dup, **route_options) }
117
132
 
@@ -120,12 +135,28 @@ describe GrapeSwagger::DocMethods::MoveParams do
120
135
  expect(params).to eql(
121
136
  [
122
137
  { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
123
- { name: 'InBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/putInBody' } }
138
+ { name: 'putInBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/putInBody' } }
124
139
  ]
125
140
  )
126
141
  expect(subject.definitions['putInBody']).not_to include :description
127
142
  expect(subject.definitions['putInBody']).to eql expected_put_defs
128
143
  end
144
+
145
+ context 'with a nickname' do
146
+ let(:route_options) { { nickname: 'put-body' } }
147
+
148
+ specify do
149
+ subject.to_definition(path, params, route, definitions)
150
+ expect(params).to eql(
151
+ [
152
+ { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
153
+ { name: 'put-body', in: 'body', required: true, schema: { '$ref' => '#/definitions/put-body' } }
154
+ ]
155
+ )
156
+ expect(subject.definitions['put-body']).not_to include :description
157
+ expect(subject.definitions['put-body']).to eql expected_put_defs
158
+ end
159
+ end
129
160
  end
130
161
  end
131
162
 
@@ -167,56 +198,39 @@ describe GrapeSwagger::DocMethods::MoveParams do
167
198
  let(:params) { [{ in: 'body', name: 'address[street][name]', description: 'street', type: 'string', required: true }] }
168
199
  before do
169
200
  subject.instance_variable_set(:@definitions, definitions)
170
- subject.send(:build_definition, name, params, verb)
201
+ subject.send(:build_definition, name, params)
171
202
  end
172
203
 
173
- describe 'verb given' do
174
- let(:verb) { 'post' }
175
- let(:name) { 'Foo' }
176
- let(:definitions) { {} }
204
+ let(:name) { 'FooBar' }
205
+ let(:definitions) { {} }
177
206
 
178
- specify do
179
- definition = definitions.to_a.first
180
- expect(definition.first).to eql 'postFoo'
181
- expect(definition.last).to eql(type: 'object', properties: {})
182
- end
183
- end
184
-
185
- describe 'no verb given' do
186
- let(:name) { 'FooBar' }
187
- let(:definitions) { {} }
188
- let(:verb) { nil }
189
-
190
- specify do
191
- definition = definitions.to_a.first
192
- expect(definition.first).to eql 'FooBar'
193
- expect(definition.last).to eql(type: 'object', properties: {})
194
- end
207
+ specify do
208
+ definition = definitions.to_a.first
209
+ expect(definition.first).to eql 'FooBar'
210
+ expect(definition.last).to eql(type: 'object', properties: {})
195
211
  end
196
212
  end
197
213
 
198
214
  describe 'build_body_parameter' do
199
- describe 'name given' do
200
- let(:name) { 'Foo' }
201
- let(:reference) { 'Bar' }
215
+ let(:name) { 'Foo' }
216
+ let(:reference) { 'Bar' }
217
+ let(:expected_param) do
218
+ { name: name, in: 'body', required: true, schema: { '$ref' => "#/definitions/#{name}" } }
219
+ end
220
+ specify do
221
+ parameter = subject.send(:build_body_parameter, name, {})
222
+ expect(parameter).to eql expected_param
223
+ end
224
+
225
+ describe 'body_name option specified' do
226
+ let(:route_options) { { body_name: 'body' } }
202
227
  let(:expected_param) do
203
- { name: name, in: 'body', required: true, schema: { '$ref' => "#/definitions/#{reference}" } }
228
+ { name: route_options[:body_name], in: 'body', required: true, schema: { '$ref' => "#/definitions/#{name}" } }
204
229
  end
205
230
  specify do
206
- parameter = subject.send(:build_body_parameter, reference, name, {})
231
+ parameter = subject.send(:build_body_parameter, name, route_options)
207
232
  expect(parameter).to eql expected_param
208
233
  end
209
-
210
- describe 'body_name option specified' do
211
- let(:route_options) { { body_name: 'body' } }
212
- let(:expected_param) do
213
- { name: route_options[:body_name], in: 'body', required: true, schema: { '$ref' => "#/definitions/#{reference}" } }
214
- end
215
- specify do
216
- parameter = subject.send(:build_body_parameter, reference, name, route_options)
217
- expect(parameter).to eql expected_param
218
- end
219
- end
220
234
  end
221
235
  end
222
236
 
@@ -25,6 +25,9 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
25
25
 
26
26
  subject { described_class.new(Api::Base) }
27
27
 
28
+ let(:api_class) { subject.send(:api_class) }
29
+ let(:docs_url) { subject.send(:urls_for, api_class).first }
30
+
28
31
  describe '.new' do
29
32
  it 'accepts class name as a constant' do
30
33
  expect(described_class.new(::Api::Base).send(:api_class)).to eq(Api::Base)
@@ -38,7 +41,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
38
41
  describe '#make_request' do
39
42
  describe 'complete documentation' do
40
43
  before do
41
- subject.send(:make_request)
44
+ subject.send(:make_request, docs_url)
42
45
  end
43
46
 
44
47
  describe 'not storing' do
@@ -51,7 +54,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
51
54
  end
52
55
 
53
56
  it 'requests doc url' do
54
- expect(subject.send(:url_for)).to eql '/api/swagger_doc'
57
+ expect(docs_url).to eql '/api/swagger_doc'
55
58
  end
56
59
  end
57
60
 
@@ -68,10 +71,14 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
68
71
  describe 'documentation for resource' do
69
72
  before do
70
73
  ENV['resource'] = resource
71
- subject.send(:make_request)
74
+ subject.send(:make_request, docs_url)
72
75
  end
73
76
 
74
- let(:response) { JSON.parse(subject.send(:make_request)) }
77
+ let(:response) do
78
+ JSON.parse(
79
+ subject.send(:make_request, docs_url)
80
+ )
81
+ end
75
82
 
76
83
  after { ENV.delete('resource') }
77
84
 
@@ -83,7 +90,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
83
90
  end
84
91
 
85
92
  it 'requests doc url' do
86
- expect(subject.send(:url_for)).to eql "/api/swagger_doc/#{resource}"
93
+ expect(docs_url).to eql "/api/swagger_doc/#{resource}"
87
94
  end
88
95
 
89
96
  it 'has only one resource path' do
@@ -115,7 +122,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
115
122
 
116
123
  describe 'call it' do
117
124
  before do
118
- subject.send(:make_request)
125
+ subject.send(:make_request, docs_url)
119
126
  end
120
127
  specify do
121
128
  expect(subject).to respond_to :oapi
@@ -128,7 +135,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
128
135
  describe '#file' do
129
136
  describe 'no store given' do
130
137
  it 'returns swagger_doc.json' do
131
- expect(subject.send(:file)).to end_with 'swagger_doc.json'
138
+ expect(subject.send(:file, docs_url)).to end_with 'swagger_doc.json'
132
139
  end
133
140
  end
134
141
 
@@ -139,7 +146,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
139
146
  before { ENV['store'] = 'true' }
140
147
 
141
148
  it 'returns swagger_doc.json' do
142
- expect(subject.send(:file)).to end_with 'swagger_doc.json'
149
+ expect(subject.send(:file, docs_url)).to end_with 'swagger_doc.json'
143
150
  end
144
151
  end
145
152
 
@@ -148,7 +155,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
148
155
  before { ENV['store'] = name }
149
156
 
150
157
  it 'returns swagger_doc.json' do
151
- expect(subject.send(:file)).to end_with name
158
+ expect(subject.send(:file, docs_url)).to include(name.split('.')[0])
152
159
  end
153
160
  end
154
161
  end
data/spec/spec_helper.rb CHANGED
@@ -5,10 +5,6 @@ if RUBY_ENGINE == 'ruby'
5
5
  require 'coveralls'
6
6
 
7
7
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
8
- SimpleCov.start do
9
- add_filter 'spec/'
10
- add_filter 'example/'
11
- end
12
8
  Coveralls.wear!
13
9
  end
14
10
 
@@ -8,7 +8,7 @@ RSpec.shared_context 'the api paths/defs' do
8
8
  produces: ['application/json'],
9
9
  consumes: ['application/json'],
10
10
  parameters: [
11
- { in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true },
11
+ { in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true, example: 23 },
12
12
  { in: 'body', name: 'in_body_2', description: 'in_body_2', type: 'string', required: false },
13
13
  { in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false }
14
14
  ],
@@ -31,7 +31,7 @@ RSpec.shared_context 'the api paths/defs' do
31
31
  { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
32
32
  { in: 'body', name: 'in_body_1', description: 'in_body_1', type: 'integer', format: 'int32', required: true },
33
33
  { in: 'body', name: 'in_body_2', description: 'in_body_2', type: 'string', required: false },
34
- { in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false }
34
+ { in: 'body', name: 'in_body_3', description: 'in_body_3', type: 'string', required: false, example: 'my example string' }
35
35
  ],
36
36
  responses: { 200 => { description: 'put in body /wo entity', schema: { '$ref' => '#/definitions/InBody' } } },
37
37
  tags: ['in_body'],
@@ -85,7 +85,7 @@ RSpec.shared_context 'the api paths/defs' do
85
85
  {
86
86
  type: 'object',
87
87
  properties: {
88
- in_body_1: { type: 'integer', format: 'int32', description: 'in_body_1' },
88
+ in_body_1: { type: 'integer', format: 'int32', description: 'in_body_1', example: 23 },
89
89
  in_body_2: { type: 'string', description: 'in_body_2' },
90
90
  in_body_3: { type: 'string', description: 'in_body_3' }
91
91
  },
@@ -99,7 +99,7 @@ RSpec.shared_context 'the api paths/defs' do
99
99
  properties: {
100
100
  in_body_1: { type: 'integer', format: 'int32', description: 'in_body_1' },
101
101
  in_body_2: { type: 'string', description: 'in_body_2' },
102
- in_body_3: { type: 'string', description: 'in_body_3' }
102
+ in_body_3: { type: 'string', description: 'in_body_3', example: 'my example string' }
103
103
  },
104
104
  required: [:in_body_1]
105
105
  }