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
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'details' do
|
4
|
+
describe 'details, pass markdown with redcarpet even with nil description and detail', unless: RUBY_PLATFORM.eql?('java') do
|
5
|
+
include_context "the api entities"
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
module TheApi
|
9
|
+
class GfmRcDetailApi < Grape::API
|
10
|
+
format :json
|
11
|
+
|
12
|
+
desc nil,
|
13
|
+
detail: nil,
|
14
|
+
entity: Entities::UseResponse,
|
15
|
+
failure: [{code: 400, model: Entities::ApiError}]
|
16
|
+
get '/use_gfm_rc_detail' do
|
17
|
+
{ "declared_params" => declared(params) }
|
18
|
+
end
|
19
|
+
|
20
|
+
add_swagger_documentation markdown: GrapeSwagger::Markdown::RedcarpetAdapter.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def app
|
26
|
+
TheApi::GfmRcDetailApi
|
27
|
+
end
|
28
|
+
|
29
|
+
subject do
|
30
|
+
get '/swagger_doc'
|
31
|
+
JSON.parse(last_response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
specify do
|
35
|
+
expect(subject['paths']['/use_gfm_rc_detail']['get']).not_to include('description')
|
36
|
+
expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(nil)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -19,12 +19,12 @@ describe 'Float Params' do
|
|
19
19
|
get '/swagger_doc/splines'
|
20
20
|
expect(last_response.status).to eq 200
|
21
21
|
body = JSON.parse last_response.body
|
22
|
-
body['
|
22
|
+
body['paths']['/splines']['post']['parameters']
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'converts float types' do
|
26
26
|
expect(subject).to eq [
|
27
|
-
{
|
27
|
+
{"in"=>"formData", "name"=>"a_float", "description"=>nil, "type"=>"number", "required"=>true, "format"=>"float"}
|
28
28
|
]
|
29
29
|
end
|
30
30
|
end
|
@@ -49,17 +49,17 @@ describe 'Form Params' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'retrieves the documentation form params' do
|
52
|
-
expect(subject['
|
53
|
-
expect(subject['
|
54
|
-
expect(subject['
|
55
|
-
expect(subject['
|
56
|
-
expect(subject['apis'][1]['operations'][0]['method']).to eq 'PUT'
|
57
|
-
expect(subject['apis'][1]['operations'][1]['method']).to eq 'PATCH'
|
58
|
-
expect(subject['apis'][1]['operations'][2]['method']).to eq 'POST'
|
52
|
+
expect(subject['paths'].length).to eq 2
|
53
|
+
expect(subject['paths'].keys).to include('/items','/items/{id}')
|
54
|
+
expect(subject['paths']['/items'].keys).to include 'post'
|
55
|
+
expect(subject['paths']['/items/{id}'].keys).to include('post', 'patch', 'put')
|
59
56
|
end
|
60
57
|
|
61
58
|
it 'treats Symbol parameter as form param' do
|
62
|
-
expect(subject['
|
63
|
-
|
59
|
+
expect(subject['paths']['/items/{id}']['post']['parameters']).to eq [
|
60
|
+
{"in"=>"path", "name"=>"id", "description"=>"id of item", "type"=>"integer", "required"=>true, "format"=>"int32"},
|
61
|
+
{"in"=>"formData", "name"=>"name", "description"=>"name of item", "type"=>"string", "required"=>true},
|
62
|
+
{"in"=>"formData", "name"=>"conditions", "description"=>"conditions of item", "type"=>"string", "required"=>false, "enum"=>["one", "two"]}
|
63
|
+
]
|
64
64
|
end
|
65
65
|
end
|
File without changes
|
@@ -0,0 +1,131 @@
|
|
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', hidden: true
|
12
|
+
get '/hide' do
|
13
|
+
{ foo: 'bar' }
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Lazily show endpoint', hidden: -> { false }
|
17
|
+
get '/lazy' do
|
18
|
+
{ foo: 'bar' }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class HideApi < Grape::API
|
23
|
+
mount HideMountedApi
|
24
|
+
add_swagger_documentation
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def app
|
29
|
+
HideApi
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
get '/swagger_doc.json'
|
34
|
+
JSON.parse(last_response.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "retrieves swagger-documentation that doesn't include hidden endpoints" do
|
38
|
+
expect(subject).to eq({
|
39
|
+
"info"=>{"title"=>"API title", "version"=>"v1"},
|
40
|
+
"swagger"=>"2.0",
|
41
|
+
"produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
|
42
|
+
"host"=>"example.org",
|
43
|
+
"tags" => [{"name"=>"simple", "description"=>"Operations about simples"}, {"name"=>"lazy", "description"=>"Operations about lazies"}],
|
44
|
+
"schemes" => ["https", "http"],
|
45
|
+
"paths"=>{
|
46
|
+
"/simple"=>{
|
47
|
+
"get"=>{
|
48
|
+
"description"=>"Show this endpoint",
|
49
|
+
"produces"=>["application/json"],
|
50
|
+
"tags"=>["simple"],
|
51
|
+
"operationId"=>"getSimple",
|
52
|
+
"responses"=>{"200"=>{"description"=>"Show this endpoint"}}}},
|
53
|
+
"/lazy"=>{
|
54
|
+
"get"=>{
|
55
|
+
"description"=>"Lazily show endpoint",
|
56
|
+
"produces"=>["application/json"],
|
57
|
+
"tags"=>["lazy"],
|
58
|
+
"operationId"=>"getLazy",
|
59
|
+
"responses"=>{"200"=>{"description"=>"Lazily show endpoint"}}}}}
|
60
|
+
})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'a hide mounted api with same namespace' do
|
65
|
+
before :all do
|
66
|
+
class HideNamespaceMountedApi < Grape::API
|
67
|
+
desc 'Show this endpoint'
|
68
|
+
get '/simple/show' do
|
69
|
+
{ foo: 'bar' }
|
70
|
+
end
|
71
|
+
|
72
|
+
desc 'Hide this endpoint', hidden: true
|
73
|
+
get '/simple/hide' do
|
74
|
+
{ foo: 'bar' }
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'Lazily hide endpoint', hidden: -> { true }
|
78
|
+
get '/simple/lazy' do
|
79
|
+
{ foo: 'bar' }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class HideNamespaceApi < Grape::API
|
84
|
+
mount HideNamespaceMountedApi
|
85
|
+
add_swagger_documentation
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def app
|
90
|
+
HideNamespaceApi
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'retrieves swagger-documentation on /swagger_doc' do
|
94
|
+
get '/swagger_doc.json'
|
95
|
+
expect(JSON.parse(last_response.body)).to eq({
|
96
|
+
"info"=>{"title"=>"API title", "version"=>"v1"},
|
97
|
+
"swagger"=>"2.0",
|
98
|
+
"produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
|
99
|
+
"host"=>"example.org",
|
100
|
+
"tags" => [{"name"=>"simple", "description"=>"Operations about simples"}],
|
101
|
+
"schemes" => ["https", "http"],
|
102
|
+
"paths"=>{
|
103
|
+
"/simple/show"=>{
|
104
|
+
"get"=>{
|
105
|
+
"description"=>"Show this endpoint",
|
106
|
+
"produces"=>["application/json"],
|
107
|
+
"operationId"=>"getSimpleShow",
|
108
|
+
"tags"=>["simple"], "responses"=>{"200"=>{"description"=>"Show this endpoint"}}}}}
|
109
|
+
})
|
110
|
+
end
|
111
|
+
|
112
|
+
it "retrieves the documentation for mounted-api that doesn't include hidden endpoints" do
|
113
|
+
get '/swagger_doc/simple.json'
|
114
|
+
expect(JSON.parse(last_response.body)).to eq({
|
115
|
+
"info"=>{"title"=>"API title", "version"=>"v1"},
|
116
|
+
"swagger"=>"2.0",
|
117
|
+
"produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
|
118
|
+
"host"=>"example.org",
|
119
|
+
"tags" => [{"name"=>"simple", "description"=>"Operations about simples"}],
|
120
|
+
"schemes" => ["https", "http"],
|
121
|
+
"paths"=>{
|
122
|
+
"/simple/show"=>{
|
123
|
+
"get"=>{
|
124
|
+
"description"=>"Show this endpoint",
|
125
|
+
"produces"=>["application/json"],
|
126
|
+
"tags"=>["simple"],
|
127
|
+
"operationId"=>"getSimpleShow",
|
128
|
+
"responses"=>{"200"=>{"description"=>"Show this endpoint"}}}}}
|
129
|
+
})
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'docs mounted separately from api' do
|
4
|
+
before :all do
|
5
|
+
class ActualApi < Grape::API
|
6
|
+
desc 'Document root'
|
7
|
+
|
8
|
+
desc 'This gets something.',
|
9
|
+
notes: '_test_'
|
10
|
+
get '/simple' do
|
11
|
+
{ bla: 'something' }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MountedDocs < Grape::API
|
16
|
+
add_swagger_documentation(target_class: ActualApi)
|
17
|
+
end
|
18
|
+
|
19
|
+
class WholeApp < Grape::API
|
20
|
+
mount ActualApi
|
21
|
+
mount MountedDocs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def app
|
26
|
+
WholeApp
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'retrieves docs for actual api class' do
|
30
|
+
get '/swagger_doc.json'
|
31
|
+
expect(JSON.parse(last_response.body)).to eq({
|
32
|
+
"info"=>{"title"=>"API title", "version"=>"v1"},
|
33
|
+
"swagger"=>"2.0",
|
34
|
+
"produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
|
35
|
+
"host"=>"example.org",
|
36
|
+
"tags"=>[{"name"=>"simple", "description"=>"Operations about simples"}],
|
37
|
+
"schemes"=>["https", "http"],
|
38
|
+
"paths"=>{
|
39
|
+
"/simple"=>{
|
40
|
+
"get"=>{
|
41
|
+
"description"=>"This gets something.",
|
42
|
+
"produces"=>["application/json"],
|
43
|
+
"responses"=>{"200"=>{"description"=>"This gets something."}},
|
44
|
+
"tags"=>["simple"],
|
45
|
+
"operationId"=>"getSimple"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'retrieves docs for endpoint in actual api class' do
|
53
|
+
get '/swagger_doc/simple.json'
|
54
|
+
expect(JSON.parse(last_response.body)).to eq({
|
55
|
+
"info"=>{"title"=>"API title", "version"=>"v1"},
|
56
|
+
"swagger"=>"2.0",
|
57
|
+
"tags" => [{"name"=>"simple", "description"=>"Operations about simples"}],
|
58
|
+
"produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
|
59
|
+
"host"=>"example.org",
|
60
|
+
"schemes" => ["https", "http"],
|
61
|
+
"paths" => {
|
62
|
+
"/simple"=>{
|
63
|
+
"get"=>{
|
64
|
+
"description"=>"This gets something.",
|
65
|
+
"produces"=>["application/json"],
|
66
|
+
"responses"=>{
|
67
|
+
"200"=>{"description"=>"This gets something."}
|
68
|
+
},
|
69
|
+
"tags"=>["simple"],
|
70
|
+
"operationId"=>"getSimple"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
})
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'namespace tags check while using prefix and version' do
|
4
|
+
include_context "namespace example"
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
module TheApi
|
8
|
+
class NamespaceApi < Grape::API
|
9
|
+
version :v1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TagApi < Grape::API
|
14
|
+
prefix :api
|
15
|
+
mount TheApi::NamespaceApi
|
16
|
+
add_swagger_documentation version: 'v1'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def app
|
21
|
+
TagApi
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "retrieves swagger-documentation on /swagger_doc" do
|
25
|
+
subject do
|
26
|
+
get '/api/swagger_doc.json'
|
27
|
+
JSON.parse(last_response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
specify do
|
31
|
+
expect(subject['tags']).to eql([
|
32
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
33
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
34
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
35
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
36
|
+
])
|
37
|
+
|
38
|
+
expect(subject['paths']['/api/v1/hudson']['get']['tags']).to eql(['hudson'])
|
39
|
+
expect(subject['paths']['/api/v1/colorado/simple']['get']['tags']).to eql(['colorado'])
|
40
|
+
expect(subject['paths']['/api/v1/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
41
|
+
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
42
|
+
expect(subject['paths']['/api/v1/niles/items']['post']['tags']).to eql(['niles'])
|
43
|
+
expect(subject['paths']['/api/v1/niles/custom']['get']['tags']).to eql(['niles'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
describe 'retrieves the documentation for mounted-api' do
|
49
|
+
subject do
|
50
|
+
get '/api/swagger_doc/colorado.json'
|
51
|
+
JSON.parse(last_response.body)
|
52
|
+
end
|
53
|
+
|
54
|
+
specify do
|
55
|
+
expect(subject['tags']).to eql([
|
56
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
57
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
58
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
59
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
60
|
+
])
|
61
|
+
|
62
|
+
expect(subject['paths']['/api/v1/colorado/simple']['get']['tags']).to eql(['colorado'])
|
63
|
+
expect(subject['paths']['/api/v1/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'includes headers' do
|
67
|
+
subject do
|
68
|
+
get '/api/swagger_doc/thames.json'
|
69
|
+
JSON.parse(last_response.body)
|
70
|
+
end
|
71
|
+
|
72
|
+
specify do
|
73
|
+
expect(subject['tags']).to eql([
|
74
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
75
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
76
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
77
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
78
|
+
])
|
79
|
+
|
80
|
+
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'namespace tags check' do
|
4
|
+
include_context "namespace example"
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class TestApi < Grape::API
|
8
|
+
mount TheApi::NamespaceApi
|
9
|
+
add_swagger_documentation
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
TestApi
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "retrieves swagger-documentation on /swagger_doc" do
|
18
|
+
subject do
|
19
|
+
get '/swagger_doc.json'
|
20
|
+
JSON.parse(last_response.body)
|
21
|
+
end
|
22
|
+
|
23
|
+
specify do
|
24
|
+
expect(subject['tags']).to eql([
|
25
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
26
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
27
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
28
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
29
|
+
])
|
30
|
+
|
31
|
+
expect(subject['paths']['/hudson']['get']['tags']).to eql(['hudson'])
|
32
|
+
expect(subject['paths']['/colorado/simple']['get']['tags']).to eql(['colorado'])
|
33
|
+
expect(subject['paths']['/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
34
|
+
expect(subject['paths']['/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
35
|
+
expect(subject['paths']['/niles/items']['post']['tags']).to eql(['niles'])
|
36
|
+
expect(subject['paths']['/niles/custom']['get']['tags']).to eql(['niles'])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'retrieves the documentation for mounted-api' do
|
41
|
+
subject do
|
42
|
+
get '/swagger_doc/colorado.json'
|
43
|
+
JSON.parse(last_response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
specify do
|
47
|
+
expect(subject['tags']).to eql([
|
48
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
49
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
50
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
51
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
52
|
+
])
|
53
|
+
|
54
|
+
expect(subject['paths']['/colorado/simple']['get']['tags']).to eql(['colorado'])
|
55
|
+
expect(subject['paths']['/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'includes headers' do
|
59
|
+
subject do
|
60
|
+
get '/swagger_doc/thames.json'
|
61
|
+
JSON.parse(last_response.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
specify do
|
65
|
+
expect(subject['tags']).to eql([
|
66
|
+
{"name"=>"hudson", "description"=>"Operations about hudsons"},
|
67
|
+
{"name"=>"colorado", "description"=>"Operations about colorados"},
|
68
|
+
{"name"=>"thames", "description"=>"Operations about thames"},
|
69
|
+
{"name"=>"niles", "description"=>"Operations about niles"}
|
70
|
+
])
|
71
|
+
|
72
|
+
expect(subject['paths']['/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|