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.
- checksums.yaml +4 -4
- data/.gitignore +8 -1
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +14 -22
- data/.travis.yml +7 -4
- data/CHANGELOG.md +53 -26
- data/Gemfile +1 -1
- data/README.md +414 -327
- data/RELEASING.md +3 -4
- data/example/api/endpoints.rb +132 -0
- data/example/api/entities.rb +18 -0
- data/example/config.ru +36 -2
- data/example/example_requests.postman_collection +146 -0
- data/example/swagger-example.png +0 -0
- data/grape-swagger.gemspec +9 -6
- data/lib/grape-swagger.rb +69 -99
- data/lib/grape-swagger/doc_methods.rb +69 -544
- data/lib/grape-swagger/doc_methods/data_type.rb +77 -0
- data/lib/grape-swagger/doc_methods/extensions.rb +75 -0
- data/lib/grape-swagger/doc_methods/move_params.rb +153 -0
- data/lib/grape-swagger/doc_methods/operation_id.rb +27 -0
- data/lib/grape-swagger/doc_methods/optional_object.rb +15 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +113 -0
- data/lib/grape-swagger/doc_methods/path_string.rb +29 -0
- data/lib/grape-swagger/doc_methods/produces_consumes.rb +12 -0
- data/lib/grape-swagger/doc_methods/status_codes.rb +17 -0
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +26 -0
- data/lib/grape-swagger/endpoint.rb +317 -0
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/lib/data_type_spec.rb +57 -0
- data/spec/lib/endpoint_spec.rb +6 -0
- data/spec/lib/extensions_spec.rb +127 -0
- data/spec/lib/move_params_spec.rb +298 -0
- data/spec/lib/operation_id_spec.rb +24 -0
- data/spec/lib/optional_object_spec.rb +40 -0
- data/spec/lib/path_string_spec.rb +38 -0
- data/spec/lib/produces_consumes_spec.rb +98 -0
- data/spec/markdown/kramdown_adapter_spec.rb +2 -9
- data/spec/markdown/redcarpet_adapter_spec.rb +2 -16
- data/spec/spec_helper.rb +7 -13
- data/spec/support/api_swagger_v2_result.rb +204 -0
- data/spec/support/namespace_tags.rb +73 -0
- data/spec/support/the_api_entities.rb +52 -0
- data/spec/support/the_paths_definitions.rb +94 -0
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +32 -0
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +151 -0
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +109 -0
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +124 -0
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +51 -0
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +44 -0
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +56 -0
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +146 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +197 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +151 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +217 -0
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +64 -0
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +184 -0
- data/spec/swagger_v2/api_swagger_v2_spec.rb +207 -0
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +121 -0
- data/spec/{boolean_params_spec.rb → swagger_v2/boolean_params_spec.rb} +2 -2
- data/spec/{default_api_spec.rb → swagger_v2/default_api_spec.rb} +40 -36
- data/spec/swagger_v2/description_not_initialized.rb +39 -0
- data/spec/{float_api_spec.rb → swagger_v2/float_api_spec.rb} +2 -2
- data/spec/{form_params_spec.rb → swagger_v2/form_params_spec.rb} +9 -9
- data/spec/{grape-swagger_spec.rb → swagger_v2/grape-swagger_spec.rb} +0 -0
- data/spec/swagger_v2/hide_api_spec.rb +131 -0
- data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +84 -0
- data/spec/swagger_v2/namespace_tags_spec.rb +76 -0
- data/spec/{namespaced_api_spec.rb → swagger_v2/namespaced_api_spec.rb} +6 -26
- data/spec/{param_type_spec.rb → swagger_v2/param_type_spec.rb} +10 -8
- data/spec/{param_values_spec.rb → swagger_v2/param_values_spec.rb} +52 -22
- data/spec/swagger_v2/params_array_spec.rb +63 -0
- data/spec/swagger_v2/params_hash_spec.rb +65 -0
- data/spec/swagger_v2/params_nested_spec.rb +63 -0
- data/spec/{reference_entity.rb → swagger_v2/reference_entity.rb} +18 -23
- data/spec/swagger_v2/response_model_spec.rb +212 -0
- data/spec/swagger_v2/simple_mounted_api_spec.rb +264 -0
- metadata +175 -90
- data/example/api.rb +0 -66
- data/lib/grape-swagger/markdown.rb +0 -23
- data/spec/api_description_spec.rb +0 -43
- data/spec/api_global_models_spec.rb +0 -77
- data/spec/api_models_spec.rb +0 -364
- data/spec/api_paths_spec.rb +0 -128
- data/spec/api_root_spec.rb +0 -30
- data/spec/api_with_nil_types.rb +0 -50
- data/spec/api_with_path_versioning_spec.rb +0 -33
- data/spec/api_with_prefix_and_namespace_spec.rb +0 -32
- data/spec/api_with_standalone_namespace_spec.rb +0 -215
- data/spec/array_entity_spec.rb +0 -34
- data/spec/array_params_spec.rb +0 -85
- data/spec/grape-swagger_helper_spec.rb +0 -152
- data/spec/group_params_spec.rb +0 -31
- data/spec/hash_params_spec.rb +0 -30
- data/spec/hide_api_spec.rb +0 -124
- data/spec/i18n_spec.rb +0 -364
- data/spec/markdown/markdown_spec.rb +0 -27
- data/spec/mounted_target_class_spec.rb +0 -63
- data/spec/mutually_exclusive_spec.rb +0 -36
- data/spec/non_default_api_spec.rb +0 -733
- data/spec/response_model_spec.rb +0 -121
- data/spec/simple_mounted_api_spec.rb +0 -213
- data/spec/support/i18n_helper.rb +0 -8
data/spec/array_entity_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Array Entity' do
|
4
|
-
before :all do
|
5
|
-
class Something < Grape::Entity
|
6
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def app
|
11
|
-
Class.new(Grape::API) do
|
12
|
-
format :json
|
13
|
-
|
14
|
-
desc 'This returns something or an error',
|
15
|
-
is_array: true,
|
16
|
-
entity: Something
|
17
|
-
post :action do
|
18
|
-
end
|
19
|
-
|
20
|
-
add_swagger_documentation
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
subject do
|
25
|
-
get '/swagger_doc/action'
|
26
|
-
JSON.parse(last_response.body)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'reads param type correctly' do
|
30
|
-
expect(subject['models'].keys).to include 'Something'
|
31
|
-
expect(subject['apis'][0]['operations'][0]['type']).to eq('array')
|
32
|
-
expect(subject['apis'][0]['operations'][0]['items']).to eq('$ref' => 'Something')
|
33
|
-
end
|
34
|
-
end
|
data/spec/array_params_spec.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Array 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 :param_2, type: String
|
12
|
-
end
|
13
|
-
end
|
14
|
-
post :splines do
|
15
|
-
end
|
16
|
-
|
17
|
-
params do
|
18
|
-
optional :raw_array, type: Array
|
19
|
-
end
|
20
|
-
get :raw_array_splines do
|
21
|
-
end
|
22
|
-
|
23
|
-
params do
|
24
|
-
optional :raw_array, type: Array[Integer], documentation: { is_array: true }
|
25
|
-
end
|
26
|
-
get :raw_array_integers do
|
27
|
-
end
|
28
|
-
|
29
|
-
params do
|
30
|
-
requires :a_array, type: Array do
|
31
|
-
requires :param_1, type: Integer
|
32
|
-
requires :b_array, type: Array do
|
33
|
-
requires :param_2, type: String
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
post :nested_array do
|
38
|
-
end
|
39
|
-
|
40
|
-
add_swagger_documentation
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'gets array types' do
|
45
|
-
get '/swagger_doc/splines'
|
46
|
-
expect(last_response.status).to eq 200
|
47
|
-
body = JSON.parse last_response.body
|
48
|
-
parameters = body['apis'].first['operations'].first['parameters']
|
49
|
-
expect(parameters).to eq [
|
50
|
-
{ 'paramType' => 'form', 'name' => 'a_array[][param_1]', 'description' => '', 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32' },
|
51
|
-
{ 'paramType' => 'form', 'name' => 'a_array[][param_2]', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false }
|
52
|
-
]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'get raw array type' do
|
56
|
-
get '/swagger_doc/raw_array_splines'
|
57
|
-
expect(last_response.status).to eq 200
|
58
|
-
body = JSON.parse last_response.body
|
59
|
-
parameters = body['apis'].first['operations'].first['parameters']
|
60
|
-
expect(parameters).to eq [
|
61
|
-
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => '', 'type' => 'Array', 'required' => false, 'allowMultiple' => false }
|
62
|
-
]
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'get raw array integer' do
|
66
|
-
get '/swagger_doc/raw_array_integers'
|
67
|
-
expect(last_response.status).to eq 200
|
68
|
-
body = JSON.parse last_response.body
|
69
|
-
parameters = body['apis'].first['operations'].first['parameters']
|
70
|
-
expect(parameters).to eq [
|
71
|
-
{ 'paramType' => 'query', 'name' => 'raw_array', 'description' => '', 'type' => 'array', 'required' => false, 'allowMultiple' => false, 'items' => { 'type' => 'integer', 'format' => 'int32' } }
|
72
|
-
]
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'get nested array integer' do
|
76
|
-
get '/swagger_doc/nested_array'
|
77
|
-
expect(last_response.status).to eq 200
|
78
|
-
body = JSON.parse last_response.body
|
79
|
-
parameters = body['apis'].first['operations'].first['parameters']
|
80
|
-
expect(parameters).to eq [
|
81
|
-
{ 'paramType' => 'form', 'name' => 'a_array[][param_1]', 'description' => '', 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32' },
|
82
|
-
{ 'paramType' => 'form', 'name' => 'a_array[][b_array][][param_2]', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false }
|
83
|
-
]
|
84
|
-
end
|
85
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'helpers' do
|
4
|
-
before :all do
|
5
|
-
class HelperTestAPI < Grape::API
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
subject do
|
10
|
-
HelperTestAPI.add_swagger_documentation
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'parsing parameters' do
|
14
|
-
it 'parses params as query strings for a GET' do
|
15
|
-
params = {
|
16
|
-
name: { type: 'String', desc: 'A name', required: true, default: 'default' },
|
17
|
-
level: 'max'
|
18
|
-
}
|
19
|
-
path = '/coolness'
|
20
|
-
method = 'GET'
|
21
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
22
|
-
{ paramType: 'query', name: :name, description: 'A name', type: 'string', required: true, allowMultiple: false, defaultValue: 'default' },
|
23
|
-
{ paramType: 'query', name: :level, description: '', type: 'string', required: false, allowMultiple: false }
|
24
|
-
]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'parses params as query strings for a GET with an example' do
|
28
|
-
params = {
|
29
|
-
name: { type: 'String', desc: 'A name', required: true, default: 'default api value', documentation: { example: 'default swagger value' } },
|
30
|
-
level: 'max'
|
31
|
-
}
|
32
|
-
path = '/coolness'
|
33
|
-
method = 'GET'
|
34
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
35
|
-
{ paramType: 'query', name: :name, description: 'A name', type: 'string', required: true, allowMultiple: false, defaultValue: 'default swagger value' },
|
36
|
-
{ paramType: 'query', name: :level, description: '', type: 'string', required: false, allowMultiple: false }
|
37
|
-
]
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'parses params as form for a POST' do
|
41
|
-
params = {
|
42
|
-
name: { type: 'String', desc: 'A name', required: true },
|
43
|
-
level: 'max'
|
44
|
-
}
|
45
|
-
path = '/coolness'
|
46
|
-
method = 'POST'
|
47
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
48
|
-
{ paramType: 'form', name: :name, description: 'A name', type: 'string', required: true, allowMultiple: false },
|
49
|
-
{ paramType: 'form', name: :level, description: '', type: 'string', required: false, allowMultiple: false }
|
50
|
-
]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'parses file param' do
|
54
|
-
params = {
|
55
|
-
rack: {
|
56
|
-
type: 'Rack::Multipart::UploadedFile',
|
57
|
-
desc: 'rack file',
|
58
|
-
datafile: 'content',
|
59
|
-
required: true
|
60
|
-
}
|
61
|
-
}
|
62
|
-
path = '/coolness'
|
63
|
-
method = 'POST'
|
64
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
65
|
-
{
|
66
|
-
paramType: 'body',
|
67
|
-
name: :rack,
|
68
|
-
description: 'rack file',
|
69
|
-
type: 'File',
|
70
|
-
required: true,
|
71
|
-
allowMultiple: false
|
72
|
-
}
|
73
|
-
]
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'parses symbol param as string' do
|
77
|
-
params = {
|
78
|
-
animal: { type: 'Symbol', desc: 'An animal you like', required: true, values: [:cat, :dog] }
|
79
|
-
}
|
80
|
-
path = '/coolness'
|
81
|
-
method = 'POST'
|
82
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
83
|
-
{
|
84
|
-
paramType: 'form',
|
85
|
-
name: :animal,
|
86
|
-
description: 'An animal you like',
|
87
|
-
type: 'string',
|
88
|
-
required: true,
|
89
|
-
allowMultiple: false,
|
90
|
-
enum: [:cat, :dog]
|
91
|
-
}
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'custom type' do
|
96
|
-
before :all do
|
97
|
-
class CustomType
|
98
|
-
end
|
99
|
-
end
|
100
|
-
it 'parses a custom parameters' do
|
101
|
-
params = {
|
102
|
-
option: { type: CustomType, desc: 'Custom option' }
|
103
|
-
}
|
104
|
-
path = '/coolness'
|
105
|
-
method = 'GET'
|
106
|
-
expect(subject.parse_params(params, path, method)).to eq [
|
107
|
-
{ paramType: 'query', name: :option, description: 'Custom option', type: 'CustomType', required: false, allowMultiple: false }
|
108
|
-
]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'parsing the path' do
|
114
|
-
it 'parses the path' do
|
115
|
-
path = ':abc/def(.:format)'
|
116
|
-
expect(subject.parse_path(path, nil)).to eq '{abc}/def.{format}'
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'parses a path that has vars with underscores in the name' do
|
120
|
-
path = 'abc/:def_g(.:format)'
|
121
|
-
expect(subject.parse_path(path, nil)).to eq 'abc/{def_g}.{format}'
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'parses a path that has vars with numbers in the name' do
|
125
|
-
path = 'abc/:sha1(.:format)'
|
126
|
-
expect(subject.parse_path(path, nil)).to eq 'abc/{sha1}.{format}'
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'parses a path that has multiple variables' do
|
130
|
-
path1 = 'abc/:def/:geh(.:format)'
|
131
|
-
path2 = 'abc/:def:geh(.:format)'
|
132
|
-
expect(subject.parse_path(path1, nil)).to eq 'abc/{def}/{geh}.{format}'
|
133
|
-
expect(subject.parse_path(path2, nil)).to eq 'abc/{def}{geh}.{format}'
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'parses the path with a specified version' do
|
137
|
-
path = ':abc/{version}/def(.:format)'
|
138
|
-
expect(subject.parse_path(path, 'v1')).to eq '{abc}/v1/def.{format}'
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'parsing header parameters' do
|
143
|
-
it 'parses params for the header' do
|
144
|
-
params = {
|
145
|
-
'XAuthToken' => { description: 'A required header.', required: true, default: 'default' }
|
146
|
-
}
|
147
|
-
expect(subject.parse_header_params(params)).to eq [
|
148
|
-
{ paramType: 'header', name: 'XAuthToken', description: 'A required header.', type: 'string', required: true, defaultValue: 'default' }
|
149
|
-
]
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
data/spec/group_params_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Group Params' 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 '/groups' do
|
15
|
-
{}
|
16
|
-
end
|
17
|
-
|
18
|
-
add_swagger_documentation
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'retrieves the documentation for group parameters' do
|
23
|
-
get '/swagger_doc/groups'
|
24
|
-
|
25
|
-
body = JSON.parse last_response.body
|
26
|
-
parameters = body['apis'].first['operations'].first['parameters']
|
27
|
-
expect(parameters).to eq [
|
28
|
-
{ 'paramType' => 'form', 'name' => 'required_group[required_param_1]', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false },
|
29
|
-
{ 'paramType' => 'form', 'name' => 'required_group[required_param_2]', 'description' => '', 'type' => 'string', 'required' => true, 'allowMultiple' => false }]
|
30
|
-
end
|
31
|
-
end
|
data/spec/hash_params_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Hash Params' do
|
4
|
-
def app
|
5
|
-
Class.new(Grape::API) do
|
6
|
-
format :json
|
7
|
-
|
8
|
-
params do
|
9
|
-
requires :a_hash, type: Hash
|
10
|
-
end
|
11
|
-
post :splines do
|
12
|
-
end
|
13
|
-
|
14
|
-
add_swagger_documentation
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
subject do
|
19
|
-
get '/swagger_doc/splines'
|
20
|
-
expect(last_response.status).to eq 200
|
21
|
-
body = JSON.parse last_response.body
|
22
|
-
body['apis'].first['operations'].first['parameters']
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'declares hash types as object' do
|
26
|
-
expect(subject).to eq [
|
27
|
-
{ 'paramType' => 'form', 'name' => 'a_hash', 'description' => '', 'type' => 'object', 'required' => true, 'allowMultiple' => false }
|
28
|
-
]
|
29
|
-
end
|
30
|
-
end
|
data/spec/hide_api_spec.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'a hide mounted api' do
|
4
|
-
before :all do
|
5
|
-
class HideMountedApi < Grape::API
|
6
|
-
desc 'Show this endpoint'
|
7
|
-
get '/simple' do
|
8
|
-
{ foo: 'bar' }
|
9
|
-
end
|
10
|
-
|
11
|
-
desc 'Hide this endpoint',
|
12
|
-
hidden: true
|
13
|
-
|
14
|
-
get '/hide' do
|
15
|
-
{ foo: 'bar' }
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'Lazily show endpoint',
|
19
|
-
hidden: -> { false }
|
20
|
-
|
21
|
-
get '/lazy' do
|
22
|
-
{ foo: 'bar' }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class HideApi < Grape::API
|
27
|
-
mount HideMountedApi
|
28
|
-
add_swagger_documentation
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def app
|
33
|
-
HideApi
|
34
|
-
end
|
35
|
-
|
36
|
-
subject do
|
37
|
-
get '/swagger_doc.json'
|
38
|
-
JSON.parse(last_response.body)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "retrieves swagger-documentation that doesn't include hidden endpoints" do
|
42
|
-
expect(subject).to eq(
|
43
|
-
'apiVersion' => '0.1',
|
44
|
-
'swaggerVersion' => '1.2',
|
45
|
-
'info' => {},
|
46
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
47
|
-
'apis' => [
|
48
|
-
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
49
|
-
{ 'path' => '/lazy.{format}', 'description' => 'Operations about lazies' },
|
50
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
51
|
-
]
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'a hide mounted api with same namespace' do
|
57
|
-
before :all do
|
58
|
-
class HideNamespaceMountedApi < Grape::API
|
59
|
-
desc 'Show this endpoint'
|
60
|
-
get '/simple/show' do
|
61
|
-
{ foo: 'bar' }
|
62
|
-
end
|
63
|
-
|
64
|
-
desc 'Hide this endpoint',
|
65
|
-
hidden: true
|
66
|
-
|
67
|
-
get '/simple/hide' do
|
68
|
-
{ foo: 'bar' }
|
69
|
-
end
|
70
|
-
|
71
|
-
desc 'Lazily hide endpoint',
|
72
|
-
hidden: -> { true }
|
73
|
-
|
74
|
-
get '/simple/lazy' do
|
75
|
-
{ foo: 'bar' }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class HideNamespaceApi < Grape::API
|
80
|
-
mount HideNamespaceMountedApi
|
81
|
-
add_swagger_documentation
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def app
|
86
|
-
HideNamespaceApi
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'retrieves swagger-documentation on /swagger_doc' do
|
90
|
-
get '/swagger_doc.json'
|
91
|
-
expect(JSON.parse(last_response.body)).to eq(
|
92
|
-
'apiVersion' => '0.1',
|
93
|
-
'swaggerVersion' => '1.2',
|
94
|
-
'info' => {},
|
95
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
96
|
-
'apis' => [
|
97
|
-
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
98
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
99
|
-
]
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "retrieves the documentation for mounted-api that doesn't include hidden endpoints" do
|
104
|
-
get '/swagger_doc/simple.json'
|
105
|
-
expect(JSON.parse(last_response.body)).to eq(
|
106
|
-
'apiVersion' => '0.1',
|
107
|
-
'swaggerVersion' => '1.2',
|
108
|
-
'basePath' => 'http://example.org',
|
109
|
-
'resourcePath' => '/simple',
|
110
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
111
|
-
'apis' => [{
|
112
|
-
'path' => '/simple/show.{format}',
|
113
|
-
'operations' => [{
|
114
|
-
'notes' => '',
|
115
|
-
'summary' => 'Show this endpoint',
|
116
|
-
'nickname' => 'GET-simple-show---format-',
|
117
|
-
'method' => 'GET',
|
118
|
-
'parameters' => [],
|
119
|
-
'type' => 'void'
|
120
|
-
}]
|
121
|
-
}]
|
122
|
-
)
|
123
|
-
end
|
124
|
-
end
|