grape-swagger 0.26.1 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.rubocop_todo.yml +5 -11
  4. data/.travis.yml +1 -2
  5. data/CHANGELOG.md +20 -1
  6. data/Dangerfile +2 -0
  7. data/Gemfile +5 -2
  8. data/README.md +70 -17
  9. data/RELEASING.md +2 -2
  10. data/Rakefile +2 -1
  11. data/grape-swagger.gemspec +2 -0
  12. data/lib/grape-swagger.rb +3 -1
  13. data/lib/grape-swagger/doc_methods.rb +17 -2
  14. data/lib/grape-swagger/doc_methods/build_model_definition.rb +2 -0
  15. data/lib/grape-swagger/doc_methods/data_type.rb +2 -0
  16. data/lib/grape-swagger/doc_methods/extensions.rb +6 -0
  17. data/lib/grape-swagger/doc_methods/headers.rb +2 -0
  18. data/lib/grape-swagger/doc_methods/move_params.rb +7 -5
  19. data/lib/grape-swagger/doc_methods/operation_id.rb +5 -7
  20. data/lib/grape-swagger/doc_methods/optional_object.rb +2 -0
  21. data/lib/grape-swagger/doc_methods/parse_params.rb +3 -3
  22. data/lib/grape-swagger/doc_methods/path_string.rb +3 -1
  23. data/lib/grape-swagger/doc_methods/produces_consumes.rb +2 -0
  24. data/lib/grape-swagger/doc_methods/status_codes.rb +2 -2
  25. data/lib/grape-swagger/doc_methods/tag_name_description.rb +2 -0
  26. data/lib/grape-swagger/doc_methods/version.rb +1 -0
  27. data/lib/grape-swagger/endpoint.rb +36 -18
  28. data/lib/grape-swagger/errors.rb +2 -0
  29. data/lib/grape-swagger/model_parsers.rb +2 -0
  30. data/lib/grape-swagger/rake/oapi_tasks.rb +2 -0
  31. data/lib/grape-swagger/version.rb +3 -1
  32. data/spec/issues/403_versions_spec.rb +2 -0
  33. data/spec/issues/427_entity_as_string_spec.rb +2 -0
  34. data/spec/issues/430_entity_definitions_spec.rb +2 -0
  35. data/spec/issues/532_allow_custom_format_spec.rb +3 -1
  36. data/spec/issues/533_specify_status_code_spec.rb +2 -0
  37. data/spec/issues/537_enum_values_spec.rb +4 -2
  38. data/spec/issues/539_array_post_body_spec.rb +2 -0
  39. data/spec/issues/542_array_of_type_in_post_body_spec.rb +2 -0
  40. data/spec/issues/553_align_array_put_post_params_spec.rb +2 -0
  41. data/spec/issues/572_array_post_body_spec.rb +2 -0
  42. data/spec/issues/579_align_put_post_parameters_spec.rb +179 -0
  43. data/spec/issues/582_file_response_spec.rb +55 -0
  44. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
  45. data/spec/lib/data_type_spec.rb +2 -0
  46. data/spec/lib/endpoint_spec.rb +2 -0
  47. data/spec/lib/extensions_spec.rb +2 -0
  48. data/spec/lib/model_parsers_spec.rb +2 -0
  49. data/spec/lib/move_params_spec.rb +8 -5
  50. data/spec/lib/oapi_tasks_spec.rb +2 -0
  51. data/spec/lib/operation_id_spec.rb +2 -0
  52. data/spec/lib/optional_object_spec.rb +6 -1
  53. data/spec/lib/parse_params_spec.rb +2 -0
  54. data/spec/lib/path_string_spec.rb +10 -1
  55. data/spec/lib/produces_consumes_spec.rb +2 -0
  56. data/spec/lib/tag_name_description_spec.rb +10 -7
  57. data/spec/lib/version_spec.rb +5 -3
  58. data/spec/spec_helper.rb +3 -1
  59. data/spec/support/empty_model_parser.rb +2 -0
  60. data/spec/support/grape_version.rb +2 -0
  61. data/spec/support/mock_parser.rb +2 -0
  62. data/spec/support/model_parsers/entity_parser.rb +2 -0
  63. data/spec/support/model_parsers/mock_parser.rb +2 -0
  64. data/spec/support/model_parsers/representable_parser.rb +2 -0
  65. data/spec/support/namespace_tags.rb +2 -0
  66. data/spec/support/the_paths_definitions.rb +2 -0
  67. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +2 -0
  68. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +2 -0
  69. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +14 -12
  70. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +2 -0
  71. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +2 -0
  72. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +2 -0
  73. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +2 -0
  74. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +2 -0
  75. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +2 -0
  76. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +2 -0
  77. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +2 -0
  78. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +2 -0
  79. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +2 -0
  80. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +2 -0
  81. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +2 -0
  82. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +2 -0
  83. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +2 -0
  84. data/spec/swagger_v2/api_swagger_v2_spec.rb +2 -0
  85. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +2 -0
  86. data/spec/swagger_v2/boolean_params_spec.rb +2 -0
  87. data/spec/swagger_v2/default_api_spec.rb +43 -1
  88. data/spec/swagger_v2/description_not_initialized.rb +2 -0
  89. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +2 -0
  90. data/spec/swagger_v2/errors_spec.rb +2 -0
  91. data/spec/swagger_v2/float_api_spec.rb +2 -0
  92. data/spec/swagger_v2/form_params_spec.rb +3 -1
  93. data/spec/swagger_v2/grape-swagger_spec.rb +2 -0
  94. data/spec/swagger_v2/hide_api_spec.rb +2 -0
  95. data/spec/swagger_v2/host.rb +2 -0
  96. data/spec/swagger_v2/mounted_target_class_spec.rb +2 -0
  97. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +3 -1
  98. data/spec/swagger_v2/namespace_tags_spec.rb +2 -0
  99. data/spec/swagger_v2/namespaced_api_spec.rb +2 -0
  100. data/spec/swagger_v2/nicknamed_api_spec.rb +2 -0
  101. data/spec/swagger_v2/operation_id_api_spec.rb +2 -0
  102. data/spec/swagger_v2/param_multi_type_spec.rb +2 -0
  103. data/spec/swagger_v2/param_type_spec.rb +2 -0
  104. data/spec/swagger_v2/param_values_spec.rb +2 -0
  105. data/spec/swagger_v2/params_array_collection_fromat_spec.rb +2 -0
  106. data/spec/swagger_v2/params_array_spec.rb +2 -0
  107. data/spec/swagger_v2/params_hash_spec.rb +2 -0
  108. data/spec/swagger_v2/params_nested_spec.rb +2 -0
  109. data/spec/swagger_v2/parent_less_namespace.rb +2 -0
  110. data/spec/swagger_v2/reference_entity.rb +2 -0
  111. data/spec/swagger_v2/security_requirement_spec.rb +2 -0
  112. data/spec/swagger_v2/simple_mounted_api_spec.rb +2 -0
  113. data/spec/version_spec.rb +2 -0
  114. metadata +8 -2
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#582 respond with a file' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ let(:app) do
9
+ Class.new(Grape::API) do
10
+ namespace :issue_582 do
11
+ desc 'produces given',
12
+ success: File,
13
+ produces: ['application/pdf', 'text/csv']
14
+ get '/produces_given' do
15
+ 'responds a file'
16
+ end
17
+
18
+ desc 'automatic produces',
19
+ success: 'file'
20
+ get '/automatic_produces' do
21
+ 'responds a file'
22
+ end
23
+ end
24
+
25
+ add_swagger_documentation format: :json
26
+ end
27
+ end
28
+
29
+ subject do
30
+ get '/swagger_doc'
31
+ JSON.parse(last_response.body)
32
+ end
33
+
34
+ describe 'produces given' do
35
+ let(:produces) { subject['paths']['/issue_582/produces_given']['get']['produces'] }
36
+ let(:response) { subject['paths']['/issue_582/produces_given']['get']['responses']['200'] }
37
+
38
+ specify do
39
+ expect(produces).to eql ['application/pdf', 'text/csv']
40
+ expect(response).to include 'schema'
41
+ expect(response['schema']).to eql 'type' => 'file'
42
+ end
43
+ end
44
+
45
+ describe 'automatic_produces' do
46
+ let(:produces) { subject['paths']['/issue_582/automatic_produces']['get']['produces'] }
47
+ let(:response) { subject['paths']['/issue_582/automatic_produces']['get']['responses']['200'] }
48
+
49
+ specify do
50
+ expect(produces).to eql ['application/octet-stream']
51
+ expect(response).to include 'schema'
52
+ expect(response['schema']).to eql 'type' => 'file'
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#587 process route with parameters delimited by dash' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :range_parameter do
9
+ desc 'Get a array with range'
10
+ get '/range/:range_start-:range_end' do
11
+ present []
12
+ end
13
+ end
14
+
15
+ add_swagger_documentation format: :json
16
+ end
17
+ end
18
+
19
+ subject do
20
+ get '/swagger_doc'
21
+ JSON.parse(last_response.body)['paths']
22
+ end
23
+
24
+ specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
25
+ specify { expect(subject['/range_parameter/range/{range_start}-{range_end}']['get']['operationId']).to eql 'getRangeParameterRangeRangeStart-RangeEnd' }
26
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::DataType do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Grape::Endpoint do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::Extensions do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::ModelParsers do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::MoveParams do
@@ -91,18 +93,19 @@ describe GrapeSwagger::DocMethods::MoveParams do
91
93
  end
92
94
 
93
95
  describe 'parent_definition_of_params' do
96
+ let(:path) { '/in_body' }
94
97
  describe 'POST' do
95
- let(:params) { paths['/in_body'][:post][:parameters] }
98
+ let(:params) { paths[path][:post][:parameters] }
96
99
  let(:options) do
97
100
  {
98
101
  method: 'POST'
99
102
  }
100
103
  end
101
- let(:env) { Rack::MockRequest.env_for('/in_body', options) }
104
+ let(:env) { Rack::MockRequest.env_for(path, options) }
102
105
  let(:request) { Grape::Request.new(env) }
103
106
 
104
107
  specify do
105
- subject.to_definition(params, request, definitions)
108
+ subject.to_definition(path, params, request, definitions)
106
109
  expect(params).to eql(
107
110
  [
108
111
  { name: 'InBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/postInBody' } }
@@ -120,11 +123,11 @@ describe GrapeSwagger::DocMethods::MoveParams do
120
123
  method: 'PUT'
121
124
  }
122
125
  end
123
- let(:env) { Rack::MockRequest.env_for('/in_body', options) }
126
+ let(:env) { Rack::MockRequest.env_for(path, options) }
124
127
  let(:request) { Grape::Request.new(env) }
125
128
 
126
129
  specify do
127
- subject.to_definition(params, request, definitions)
130
+ subject.to_definition(path, params, request, definitions)
128
131
  expect(params).to eql(
129
132
  [
130
133
  { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GrapeSwagger::Rake::OapiTasks do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::OperationId do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::OptionalObject do
@@ -34,7 +36,10 @@ describe GrapeSwagger::DocMethods::OptionalObject do
34
36
  end
35
37
 
36
38
  describe 'option is a proc' do
37
- let(:options) { { host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } } }
39
+ # rubocop:disable RegexpMatch
40
+ let(:options) do
41
+ { host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
42
+ end
38
43
  specify do
39
44
  expect(subject.build(key, options, request)).to eql '/api-example'
40
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::ParseParams do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::PathString do
@@ -6,7 +8,14 @@ describe GrapeSwagger::DocMethods::PathString do
6
8
  specify { expect(subject).to eql GrapeSwagger::DocMethods::PathString }
7
9
  specify { expect(subject).to respond_to :build }
8
10
 
9
- describe 'operation_id_object' do
11
+ describe 'path_string_object' do
12
+ specify 'The original route path is not mutated' do
13
+ route = Struct.new(:version, :path).new
14
+ route.path = '/foo/:dynamic/bar'
15
+ subject.build(route, add_version: true)
16
+ expect(route.path).to eq '/foo/:dynamic/bar'
17
+ end
18
+
10
19
  describe 'version' do
11
20
  describe 'defaults: given, true' do
12
21
  let(:options) { { add_version: true } }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::ProducesConsumes do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::TagNameDescription do
@@ -6,7 +8,7 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
6
8
  subject { described_class.send(:build_memo, tag) }
7
9
 
8
10
  specify do
9
- expect(subject.keys).to eql [:name, :description]
11
+ expect(subject.keys).to eql %i(name description)
10
12
  expect(subject).to eql(
11
13
  name: tag,
12
14
  description: "Operations about #{tag.pluralize}"
@@ -15,11 +17,12 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
15
17
  end
16
18
 
17
19
  describe '#build' do
18
- subject { described_class.build(paths) }
20
+ let(:object) { described_class.build(paths) }
21
+
19
22
  describe 'empty paths' do
20
23
  let(:paths) { {} }
21
24
  specify do
22
- expect(subject).to eql([])
25
+ expect(object).to eql([])
23
26
  end
24
27
  end
25
28
 
@@ -30,7 +33,7 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
30
33
  end
31
34
 
32
35
  specify do
33
- expect(subject).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
36
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
34
37
  end
35
38
  end
36
39
 
@@ -40,7 +43,7 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
40
43
  end
41
44
 
42
45
  specify do
43
- expect(subject).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
46
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
44
47
  end
45
48
  end
46
49
 
@@ -53,7 +56,7 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
53
56
  end
54
57
 
55
58
  specify do
56
- expect(subject).to eql [
59
+ expect(object).to eql [
57
60
  { name: 'tags_given', description: 'Operations about tags_givens' },
58
61
  { name: 'another_tag_given', description: 'Operations about another_tag_givens' }
59
62
  ]
@@ -68,7 +71,7 @@ describe GrapeSwagger::DocMethods::TagNameDescription do
68
71
  end
69
72
 
70
73
  specify do
71
- expect(subject).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
74
+ expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
72
75
  end
73
76
  end
74
77
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwagger::DocMethods::Version do
@@ -7,7 +9,7 @@ describe GrapeSwagger::DocMethods::Version do
7
9
  describe 'grape 0.16.2 version' do
8
10
  let(:version) { '[:v1, :v2]' }
9
11
  it { is_expected.to be_a Array }
10
- it { is_expected.to eql [:v1, :v2] }
12
+ it { is_expected.to eql %i(v1 v2) }
11
13
  end
12
14
 
13
15
  describe 'newer grape versions' do
@@ -18,9 +20,9 @@ describe GrapeSwagger::DocMethods::Version do
18
20
  end
19
21
 
20
22
  describe 'as Array' do
21
- let(:version) { [:v1, :v2] }
23
+ let(:version) { %i(v1 v2) }
22
24
  it { is_expected.to be_a Array }
23
- it { is_expected.to eql [:v1, :v2] }
25
+ it { is_expected.to eql %i(v1 v2) }
24
26
  end
25
27
  end
26
28
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  require 'coveralls'
3
5
 
6
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
4
7
  SimpleCov.start do
5
8
  add_filter 'spec/'
6
9
  add_filter 'example/'
7
10
  end
8
-
9
11
  Coveralls.wear!
10
12
 
11
13
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EmptyClass
2
4
  end
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class GrapeVersion
2
4
  class << self
3
5
  def current_version
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  class MockParser
3
5
  attr_reader :model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_context 'entity swagger example' do
2
4
  before :all do
3
5
  module Entities
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_context 'mock swagger example' do
2
4
  before :all do
3
5
  module Entities
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'representable/json'
2
4
 
3
5
  RSpec.shared_context 'representable swagger example' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_context 'namespace example' do
2
4
  before :all do
3
5
  module TheApi
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_context 'the api paths/defs' do
2
4
  let(:paths) do
3
5
  {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'body parameter definitions' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'definitions/models' do
@@ -1,23 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  def details
4
6
  <<-DETAILS
5
- # Burgers in Heaven
7
+ # Burgers in Heaven
6
8
 
7
- > A burger doesn't come for free
9
+ > A burger doesn't come for free
8
10
 
9
- If you want to reserve a burger in heaven, you have to do
10
- some crazy stuff on earth.
11
+ If you want to reserve a burger in heaven, you have to do
12
+ some crazy stuff on earth.
11
13
 
12
- ```
13
- def do_good
14
- puts 'help people'
15
- end
16
- ```
14
+ ```
15
+ def do_good
16
+ puts 'help people'
17
+ end
18
+ ```
17
19
 
18
- * _Will go to Heaven:_ Probably
19
- * _Will go to Hell:_ Probably not
20
- DETAILS
20
+ * _Will go to Heaven:_ Probably
21
+ * _Will go to Hell:_ Probably not
22
+ DETAILS
21
23
  end
22
24
 
23
25
  describe 'details' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'extensions' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'format, content_type' do