grape-swagger 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +6 -5
- data/grape-swagger.gemspec +5 -5
- data/lib/grape-swagger/doc_methods/extensions.rb +2 -1
- data/lib/grape-swagger/doc_methods/format_data.rb +2 -2
- data/lib/grape-swagger/doc_methods/move_params.rb +1 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +1 -1
- data/lib/grape-swagger/version.rb +1 -1
- metadata +26 -129
- data/.coveralls.yml +0 -1
- data/.github/dependabot.yml +0 -20
- data/.github/workflows/ci.yml +0 -45
- data/.gitignore +0 -45
- data/.rspec +0 -3
- data/.rubocop.yml +0 -136
- data/.rubocop_todo.yml +0 -60
- data/Dangerfile +0 -3
- data/Gemfile +0 -43
- data/Rakefile +0 -20
- data/example/api/endpoints.rb +0 -131
- data/example/api/entities.rb +0 -18
- data/example/config.ru +0 -42
- data/example/example_requests.postman_collection +0 -146
- data/example/splines.png +0 -0
- data/example/swagger-example.png +0 -0
- data/spec/issues/267_nested_namespaces.rb +0 -55
- data/spec/issues/403_versions_spec.rb +0 -124
- data/spec/issues/427_entity_as_string_spec.rb +0 -39
- data/spec/issues/430_entity_definitions_spec.rb +0 -94
- data/spec/issues/532_allow_custom_format_spec.rb +0 -38
- data/spec/issues/533_specify_status_code_spec.rb +0 -78
- data/spec/issues/537_enum_values_spec.rb +0 -50
- data/spec/issues/539_array_post_body_spec.rb +0 -65
- data/spec/issues/542_array_of_type_in_post_body_spec.rb +0 -46
- data/spec/issues/553_align_array_put_post_params_spec.rb +0 -144
- data/spec/issues/572_array_post_body_spec.rb +0 -51
- data/spec/issues/579_align_put_post_parameters_spec.rb +0 -179
- data/spec/issues/582_file_response_spec.rb +0 -55
- data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +0 -26
- data/spec/issues/605_root_route_documentation_spec.rb +0 -23
- data/spec/issues/650_params_array_spec.rb +0 -59
- data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +0 -100
- data/spec/issues/680_keep_204_error_schemas_spec.rb +0 -55
- data/spec/issues/751_deeply_nested_objects_spec.rb +0 -190
- data/spec/issues/776_multiple_presents_spec.rb +0 -59
- data/spec/issues/784_extensions_on_params_spec.rb +0 -38
- data/spec/issues/809_utf8_routes_spec.rb +0 -55
- data/spec/issues/832_array_hash_float_decimal_spec.rb +0 -111
- data/spec/issues/847_route_param_options_spec.rb +0 -37
- data/spec/lib/data_type_spec.rb +0 -111
- data/spec/lib/endpoint/params_parser_spec.rb +0 -124
- data/spec/lib/endpoint_spec.rb +0 -153
- data/spec/lib/extensions_spec.rb +0 -185
- data/spec/lib/format_data_spec.rb +0 -115
- data/spec/lib/model_parsers_spec.rb +0 -104
- data/spec/lib/move_params_spec.rb +0 -444
- data/spec/lib/oapi_tasks_spec.rb +0 -163
- data/spec/lib/operation_id_spec.rb +0 -55
- data/spec/lib/optional_object_spec.rb +0 -47
- data/spec/lib/parse_params_spec.rb +0 -68
- data/spec/lib/path_string_spec.rb +0 -101
- data/spec/lib/produces_consumes_spec.rb +0 -116
- data/spec/lib/tag_name_description_spec.rb +0 -80
- data/spec/lib/version_spec.rb +0 -28
- data/spec/spec_helper.rb +0 -39
- data/spec/support/empty_model_parser.rb +0 -23
- data/spec/support/grape_version.rb +0 -13
- data/spec/support/mock_parser.rb +0 -23
- data/spec/support/model_parsers/entity_parser.rb +0 -334
- data/spec/support/model_parsers/mock_parser.rb +0 -346
- data/spec/support/model_parsers/representable_parser.rb +0 -406
- data/spec/support/namespace_tags.rb +0 -93
- data/spec/support/the_paths_definitions.rb +0 -109
- data/spec/swagger_v2/api_documentation_spec.rb +0 -28
- data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +0 -83
- data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +0 -48
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +0 -36
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +0 -79
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +0 -145
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +0 -137
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +0 -56
- data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +0 -64
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +0 -58
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +0 -57
- data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +0 -103
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +0 -48
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +0 -145
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +0 -355
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +0 -217
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +0 -239
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +0 -72
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +0 -143
- data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +0 -135
- data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +0 -216
- data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +0 -55
- data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +0 -153
- data/spec/swagger_v2/api_swagger_v2_spec.rb +0 -237
- data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +0 -93
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +0 -89
- data/spec/swagger_v2/boolean_params_spec.rb +0 -35
- data/spec/swagger_v2/default_api_spec.rb +0 -175
- data/spec/swagger_v2/deprecated_field_spec.rb +0 -25
- data/spec/swagger_v2/description_not_initialized_spec.rb +0 -39
- data/spec/swagger_v2/endpoint_versioned_path_spec.rb +0 -130
- data/spec/swagger_v2/errors_spec.rb +0 -77
- data/spec/swagger_v2/float_api_spec.rb +0 -33
- data/spec/swagger_v2/form_params_spec.rb +0 -67
- data/spec/swagger_v2/grape-swagger_spec.rb +0 -17
- data/spec/swagger_v2/guarded_endpoint_spec.rb +0 -162
- data/spec/swagger_v2/hide_api_spec.rb +0 -147
- data/spec/swagger_v2/host_spec.rb +0 -43
- data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +0 -57
- data/spec/swagger_v2/mount_override_api_spec.rb +0 -58
- data/spec/swagger_v2/mounted_target_class_spec.rb +0 -76
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +0 -122
- data/spec/swagger_v2/namespace_tags_spec.rb +0 -78
- data/spec/swagger_v2/namespaced_api_spec.rb +0 -121
- data/spec/swagger_v2/nicknamed_api_spec.rb +0 -25
- data/spec/swagger_v2/operation_id_api_spec.rb +0 -27
- data/spec/swagger_v2/param_multi_type_spec.rb +0 -77
- data/spec/swagger_v2/param_type_spec.rb +0 -87
- data/spec/swagger_v2/param_values_spec.rb +0 -162
- data/spec/swagger_v2/params_array_collection_format_spec.rb +0 -105
- data/spec/swagger_v2/params_array_spec.rb +0 -203
- data/spec/swagger_v2/params_example_spec.rb +0 -40
- data/spec/swagger_v2/params_hash_spec.rb +0 -71
- data/spec/swagger_v2/params_nested_spec.rb +0 -86
- data/spec/swagger_v2/parent_less_namespace_spec.rb +0 -32
- data/spec/swagger_v2/reference_entity_spec.rb +0 -129
- data/spec/swagger_v2/security_requirement_spec.rb +0 -46
- data/spec/swagger_v2/simple_mounted_api_spec.rb +0 -326
- data/spec/version_spec.rb +0 -10
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::OptionalObject do
|
6
|
-
subject { described_class }
|
7
|
-
|
8
|
-
specify { expect(subject).to eql GrapeSwagger::DocMethods::OptionalObject }
|
9
|
-
specify { expect(subject).to respond_to :build }
|
10
|
-
|
11
|
-
describe 'build' do
|
12
|
-
let(:key) { :host }
|
13
|
-
let!(:request) { Rack::Request.new(Rack::MockRequest.env_for('http://example.com:8080/')) }
|
14
|
-
|
15
|
-
describe 'no option given for host, take from request' do
|
16
|
-
let(:options) { { foo: 'foo' } }
|
17
|
-
specify do
|
18
|
-
expect(subject.build(key, options, request)).to eql request.host_with_port
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:value) { 'grape-swagger.example.com' }
|
23
|
-
|
24
|
-
describe 'option is a string' do
|
25
|
-
let(:options) { { host: value } }
|
26
|
-
specify do
|
27
|
-
expect(subject.build(key, options, request)).to eql value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'option is a lambda' do
|
32
|
-
let(:options) { { host: -> { value } } }
|
33
|
-
specify do
|
34
|
-
expect(subject.build(key, options, request)).to eql value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'option is a proc' do
|
39
|
-
let(:options) do
|
40
|
-
{ host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
|
41
|
-
end
|
42
|
-
specify do
|
43
|
-
expect(subject.build(key, options, request)).to eql '/api-example'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::ParseParams do
|
6
|
-
subject { described_class }
|
7
|
-
let(:start_value) { -5 }
|
8
|
-
let(:end_value) { 5 }
|
9
|
-
|
10
|
-
describe '#parse_range_values' do
|
11
|
-
specify do
|
12
|
-
parsed_range = subject.send(:parse_range_values, start_value..end_value)
|
13
|
-
expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#parse_enum_or_range_values' do
|
18
|
-
describe 'value as Range' do
|
19
|
-
describe 'first Integer' do
|
20
|
-
specify do
|
21
|
-
parsed_range = subject.send(:parse_enum_or_range_values, start_value..end_value)
|
22
|
-
expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'first String' do
|
27
|
-
specify do
|
28
|
-
parsed_range = subject.send(:parse_enum_or_range_values, 'a'..'z')
|
29
|
-
expect(parsed_range).to be_nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'value as Proc' do
|
35
|
-
describe 'as Range' do
|
36
|
-
let(:values) { proc { start_value..end_value } }
|
37
|
-
specify do
|
38
|
-
parsed_range = subject.send(:parse_enum_or_range_values, values)
|
39
|
-
expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'as Array' do
|
44
|
-
let(:values) { proc { %w[a b c] } }
|
45
|
-
specify do
|
46
|
-
parsed_range = subject.send(:parse_enum_or_range_values, values)
|
47
|
-
expect(parsed_range).to eql(enum: %w[a b c])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'with arity one' do
|
52
|
-
let(:values) { proc { |v| v < 25 } }
|
53
|
-
specify do
|
54
|
-
parsed_range = subject.send(:parse_enum_or_range_values, values)
|
55
|
-
expect(parsed_range).to be_nil
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'values as Array -> enums' do
|
61
|
-
let(:values) { %w[a b c] }
|
62
|
-
specify do
|
63
|
-
parsed_range = subject.send(:parse_enum_or_range_values, values)
|
64
|
-
expect(parsed_range).to eql(enum: %w[a b c])
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::PathString do
|
6
|
-
subject { described_class }
|
7
|
-
|
8
|
-
specify { expect(subject).to eql GrapeSwagger::DocMethods::PathString }
|
9
|
-
specify { expect(subject).to respond_to :build }
|
10
|
-
|
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
|
-
|
19
|
-
describe 'version' do
|
20
|
-
describe 'defaults: given, true' do
|
21
|
-
let(:options) { { add_version: true } }
|
22
|
-
let(:route) { Struct.new(:version, :path).new('v1') }
|
23
|
-
|
24
|
-
specify 'The returned path includes version' do
|
25
|
-
route.path = '/{version}/thing(.json)'
|
26
|
-
expect(subject.build(route, options)).to eql ['Thing', '/v1/thing']
|
27
|
-
route.path = '/{version}/thing/foo(.json)'
|
28
|
-
expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo']
|
29
|
-
route.path = '/{version}/thing(.:format)'
|
30
|
-
expect(subject.build(route, options)).to eql ['Thing', '/v1/thing']
|
31
|
-
route.path = '/{version}/thing/foo(.:format)'
|
32
|
-
expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo']
|
33
|
-
route.path = '/{version}/thing/:id'
|
34
|
-
expect(subject.build(route, options)).to eql ['Thing', '/v1/thing/{id}']
|
35
|
-
route.path = '/{version}/thing/foo/:id'
|
36
|
-
expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo/{id}']
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'defaults: not given, both false' do
|
41
|
-
let(:options) { { add_version: false } }
|
42
|
-
let(:route) { Struct.new(:version, :path).new }
|
43
|
-
|
44
|
-
specify 'The returned path does not include version' do
|
45
|
-
route.path = '/{version}/thing(.json)'
|
46
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
47
|
-
route.path = '/{version}/thing/foo(.json)'
|
48
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
49
|
-
route.path = '/{version}/thing(.:format)'
|
50
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
51
|
-
route.path = '/{version}/thing/foo(.:format)'
|
52
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
53
|
-
route.path = '/{version}/thing/:id'
|
54
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}']
|
55
|
-
route.path = '/{version}/thing/foo/:id'
|
56
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}']
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'defaults: add_version false' do
|
61
|
-
let(:options) { { add_version: false } }
|
62
|
-
let(:route) { Struct.new(:version, :path).new('v1') }
|
63
|
-
|
64
|
-
specify 'The returned path does not include version' do
|
65
|
-
route.path = '/{version}/thing(.json)'
|
66
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
67
|
-
route.path = '/{version}/thing/foo(.json)'
|
68
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
69
|
-
route.path = '/{version}/thing(.:format)'
|
70
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
71
|
-
route.path = '/{version}/thing/foo(.:format)'
|
72
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
73
|
-
route.path = '/{version}/thing/:id'
|
74
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}']
|
75
|
-
route.path = '/{version}/thing/foo/:id'
|
76
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}']
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'defaults: root_version nil' do
|
81
|
-
let(:options) { { add_version: true } }
|
82
|
-
let(:route) { Struct.new(:version, :path).new }
|
83
|
-
|
84
|
-
specify 'The returned path does not include version' do
|
85
|
-
route.path = '/{version}/thing(.json)'
|
86
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
87
|
-
route.path = '/{version}/thing/foo(.json)'
|
88
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
89
|
-
route.path = '/{version}/thing(.:format)'
|
90
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing']
|
91
|
-
route.path = '/{version}/thing/foo(.:format)'
|
92
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo']
|
93
|
-
route.path = '/{version}/thing/:id'
|
94
|
-
expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}']
|
95
|
-
route.path = '/{version}/thing/foo/:id'
|
96
|
-
expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}']
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::ProducesConsumes do
|
6
|
-
describe ':json (default)' do
|
7
|
-
subject { described_class.call }
|
8
|
-
|
9
|
-
specify do
|
10
|
-
expect(subject).to eql(['application/json'])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'accept symbols of' do
|
15
|
-
describe 'single' do
|
16
|
-
subject { described_class.call(:xml) }
|
17
|
-
|
18
|
-
specify do
|
19
|
-
expect(subject).to eql(['application/xml'])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'multiple' do
|
24
|
-
subject { described_class.call(:xml, :serializable_hash, :json, :binary, :txt) }
|
25
|
-
|
26
|
-
specify do
|
27
|
-
expect(subject).to eql(
|
28
|
-
[
|
29
|
-
'application/xml',
|
30
|
-
'application/json',
|
31
|
-
'application/octet-stream',
|
32
|
-
'text/plain'
|
33
|
-
]
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'accept mime_types of' do
|
40
|
-
describe 'single' do
|
41
|
-
subject { described_class.call('application/xml') }
|
42
|
-
|
43
|
-
specify do
|
44
|
-
expect(subject).to eql(['application/xml'])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'multiple' do
|
49
|
-
subject do
|
50
|
-
described_class.call(
|
51
|
-
'application/xml',
|
52
|
-
'application/json',
|
53
|
-
'application/octet-stream',
|
54
|
-
'text/plain'
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
specify do
|
59
|
-
expect(subject).to eql(
|
60
|
-
[
|
61
|
-
'application/xml',
|
62
|
-
'application/json',
|
63
|
-
'application/octet-stream',
|
64
|
-
'text/plain'
|
65
|
-
]
|
66
|
-
)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'mix it up' do
|
72
|
-
subject do
|
73
|
-
described_class.call(
|
74
|
-
:xml,
|
75
|
-
:serializable_hash,
|
76
|
-
'application/json',
|
77
|
-
'application/octet-stream',
|
78
|
-
:txt
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
specify do
|
83
|
-
expect(subject).to eql(
|
84
|
-
[
|
85
|
-
'application/xml',
|
86
|
-
'application/json',
|
87
|
-
'application/octet-stream',
|
88
|
-
'text/plain'
|
89
|
-
]
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
subject do
|
94
|
-
described_class.call(
|
95
|
-
[
|
96
|
-
:xml,
|
97
|
-
:serializable_hash,
|
98
|
-
'application/json',
|
99
|
-
'application/octet-stream',
|
100
|
-
:txt
|
101
|
-
]
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
specify do
|
106
|
-
expect(subject).to eql(
|
107
|
-
[
|
108
|
-
'application/xml',
|
109
|
-
'application/json',
|
110
|
-
'application/octet-stream',
|
111
|
-
'text/plain'
|
112
|
-
]
|
113
|
-
)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::TagNameDescription do
|
6
|
-
describe '#build_memo' do
|
7
|
-
let(:tag) { 'some_string' }
|
8
|
-
subject { described_class.send(:build_memo, tag) }
|
9
|
-
|
10
|
-
specify do
|
11
|
-
expect(subject.keys).to eql %i[name description]
|
12
|
-
expect(subject).to eql(
|
13
|
-
name: tag,
|
14
|
-
description: "Operations about #{tag.pluralize}"
|
15
|
-
)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#build' do
|
20
|
-
let(:object) { described_class.build(paths) }
|
21
|
-
|
22
|
-
describe 'empty paths' do
|
23
|
-
let(:paths) { {} }
|
24
|
-
specify do
|
25
|
-
expect(object).to eql([])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'paths given' do
|
30
|
-
describe 'uniq as String' do
|
31
|
-
let(:paths) do
|
32
|
-
{ key_1: { post: { tags: 'tags_given' } } }
|
33
|
-
end
|
34
|
-
|
35
|
-
specify do
|
36
|
-
expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'uniq as Array' do
|
41
|
-
let(:paths) do
|
42
|
-
{ key_1: { post: { tags: ['tags_given'] } } }
|
43
|
-
end
|
44
|
-
|
45
|
-
specify do
|
46
|
-
expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'multiple' do
|
51
|
-
describe 'uniq key' do
|
52
|
-
let(:paths) do
|
53
|
-
{
|
54
|
-
key_1: { post: { tags: %w[tags_given another_tag_given] } }
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
specify do
|
59
|
-
expect(object).to eql [
|
60
|
-
{ name: 'tags_given', description: 'Operations about tags_givens' },
|
61
|
-
{ name: 'another_tag_given', description: 'Operations about another_tag_givens' }
|
62
|
-
]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
describe 'under different keys' do
|
66
|
-
let(:paths) do
|
67
|
-
{
|
68
|
-
key_1: { post: { tags: ['tags_given'] } },
|
69
|
-
key_2: { post: { tags: ['tags_given'] } }
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
specify do
|
74
|
-
expect(object).to eql [{ name: 'tags_given', description: 'Operations about tags_givens' }]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/spec/lib/version_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::Version do
|
6
|
-
let(:route) { OpenStruct.new(version: version) }
|
7
|
-
subject { described_class.get(route) }
|
8
|
-
|
9
|
-
describe 'grape 0.16.2 version' do
|
10
|
-
let(:version) { '[:v1, :v2]' }
|
11
|
-
it { is_expected.to be_a Array }
|
12
|
-
it { is_expected.to eql %i[v1 v2] }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'newer grape versions' do
|
16
|
-
describe 'as String' do
|
17
|
-
let(:version) { 'v1' }
|
18
|
-
it { is_expected.to be_a String }
|
19
|
-
it { is_expected.to eql 'v1' }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'as Array' do
|
23
|
-
let(:version) { %i[v1 v2] }
|
24
|
-
it { is_expected.to be_a Array }
|
25
|
-
it { is_expected.to eql %i[v1 v2] }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if RUBY_ENGINE == 'ruby'
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
8
|
-
Coveralls.wear!
|
9
|
-
end
|
10
|
-
|
11
|
-
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
12
|
-
|
13
|
-
MODEL_PARSER = ENV.key?('MODEL_PARSER') ? ENV['MODEL_PARSER'].to_s.downcase.sub('grape-swagger-', '') : 'mock'
|
14
|
-
|
15
|
-
require 'grape'
|
16
|
-
require 'grape-swagger'
|
17
|
-
|
18
|
-
Dir[File.join(Dir.getwd, 'spec/support/*.rb')].each { |f| require f }
|
19
|
-
require "grape-swagger/#{MODEL_PARSER}" if MODEL_PARSER != 'mock'
|
20
|
-
require File.join(Dir.getwd, "spec/support/model_parsers/#{MODEL_PARSER}_parser.rb")
|
21
|
-
|
22
|
-
require 'grape-entity'
|
23
|
-
require 'grape-swagger-entity'
|
24
|
-
|
25
|
-
Bundler.setup :default, :test
|
26
|
-
|
27
|
-
require 'rack'
|
28
|
-
require 'rack/test'
|
29
|
-
|
30
|
-
RSpec.configure do |config|
|
31
|
-
require 'rspec/expectations'
|
32
|
-
config.include RSpec::Matchers
|
33
|
-
config.mock_with :rspec
|
34
|
-
config.include Rack::Test::Methods
|
35
|
-
config.raise_errors_for_deprecations!
|
36
|
-
|
37
|
-
config.order = 'random'
|
38
|
-
config.seed = 40_834
|
39
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/EmptyClass
|
4
|
-
class EmptyClass
|
5
|
-
end
|
6
|
-
# rubocop:enable Lint/EmptyClass
|
7
|
-
|
8
|
-
module GrapeSwagger
|
9
|
-
class EmptyModelParser
|
10
|
-
attr_reader :model, :endpoint
|
11
|
-
|
12
|
-
def initialize(model, endpoint)
|
13
|
-
@model = model
|
14
|
-
@endpoint = endpoint
|
15
|
-
end
|
16
|
-
|
17
|
-
def call
|
18
|
-
{}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
GrapeSwagger.model_parsers.register(GrapeSwagger::EmptyModelParser, EmptyClass)
|
data/spec/support/mock_parser.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GrapeSwagger
|
4
|
-
class MockParser
|
5
|
-
attr_reader :model, :endpoint
|
6
|
-
|
7
|
-
def initialize(model, endpoint)
|
8
|
-
@model = model
|
9
|
-
@endpoint = endpoint
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
{
|
14
|
-
mock_data: {
|
15
|
-
type: :string,
|
16
|
-
description: "it's a mock"
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
GrapeSwagger.model_parsers.register(GrapeSwagger::MockParser, OpenStruct)
|