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/api_paths_spec.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'simple api with prefix' do
|
4
|
-
before :all do
|
5
|
-
class ApiWithPrefix < Grape::API
|
6
|
-
prefix :api
|
7
|
-
|
8
|
-
desc 'This gets apitest'
|
9
|
-
get '/apitest' do
|
10
|
-
{ test: 'something' }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class SimpleApiWithPrefix < Grape::API
|
15
|
-
mount ApiWithPrefix
|
16
|
-
add_swagger_documentation
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def app
|
21
|
-
SimpleApiWithPrefix
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should not raise TypeError exception' do
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'retrieves swagger-documentation on /swagger_doc that contains apitest' do
|
28
|
-
get '/swagger_doc.json'
|
29
|
-
expect(JSON.parse(last_response.body)).to eq(
|
30
|
-
'apiVersion' => '0.1',
|
31
|
-
'swaggerVersion' => '1.2',
|
32
|
-
'info' => {},
|
33
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
34
|
-
'apis' => [
|
35
|
-
{ 'path' => '/apitest.{format}', 'description' => 'Operations about apitests' },
|
36
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
37
|
-
]
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'retrieves the documentation for apitest that' do
|
42
|
-
it 'contains returns something in URL' do
|
43
|
-
get '/swagger_doc/apitest.json'
|
44
|
-
expect(JSON.parse(last_response.body)).to eq(
|
45
|
-
'apiVersion' => '0.1',
|
46
|
-
'swaggerVersion' => '1.2',
|
47
|
-
'basePath' => 'http://example.org',
|
48
|
-
'resourcePath' => '/apitest',
|
49
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
50
|
-
'apis' => [{
|
51
|
-
'path' => '/api/apitest.{format}',
|
52
|
-
'operations' => [{
|
53
|
-
'notes' => '',
|
54
|
-
'summary' => 'This gets apitest',
|
55
|
-
'nickname' => 'GET-api-apitest---format-',
|
56
|
-
'method' => 'GET',
|
57
|
-
'parameters' => [],
|
58
|
-
'type' => 'void'
|
59
|
-
}]
|
60
|
-
}]
|
61
|
-
)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'simple api with partially same path as docs mount and hidden doc path' do
|
67
|
-
before :all do
|
68
|
-
class SamePathApi < Grape::API
|
69
|
-
desc 'This gets the documents'
|
70
|
-
get '/documents' do
|
71
|
-
{ test: 'something' }
|
72
|
-
end
|
73
|
-
|
74
|
-
desc 'This gets the doc types'
|
75
|
-
get '/doc-types' do
|
76
|
-
{ test: 'something' }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class SimpleSamePathApi < Grape::API
|
81
|
-
mount SamePathApi
|
82
|
-
add_swagger_documentation(
|
83
|
-
mount_path: '/doc',
|
84
|
-
hide_documentation_path: true
|
85
|
-
)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def app
|
90
|
-
SimpleSamePathApi
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'retrieves swagger-documentation on /doc that contains documents' do
|
94
|
-
get '/doc.json'
|
95
|
-
expect(JSON.parse(last_response.body)).to eq(
|
96
|
-
'apiVersion' => '0.1',
|
97
|
-
'swaggerVersion' => '1.2',
|
98
|
-
'info' => {},
|
99
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
100
|
-
'apis' => [
|
101
|
-
{ 'path' => '/documents.{format}', 'description' => 'Operations about documents' },
|
102
|
-
{ 'path' => '/doc-types.{format}', 'description' => 'Operations about doc-types' }
|
103
|
-
]
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'retrieves the documentation for apis' do
|
108
|
-
get '/doc/documents.json'
|
109
|
-
expect(JSON.parse(last_response.body)).to eq(
|
110
|
-
'apiVersion' => '0.1',
|
111
|
-
'swaggerVersion' => '1.2',
|
112
|
-
'basePath' => 'http://example.org',
|
113
|
-
'resourcePath' => '/documents',
|
114
|
-
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
115
|
-
'apis' => [{
|
116
|
-
'path' => '/documents.{format}',
|
117
|
-
'operations' => [{
|
118
|
-
'notes' => '',
|
119
|
-
'summary' => 'This gets the documents',
|
120
|
-
'nickname' => 'GET-documents---format-',
|
121
|
-
'method' => 'GET',
|
122
|
-
'parameters' => [],
|
123
|
-
'type' => 'void'
|
124
|
-
}]
|
125
|
-
}]
|
126
|
-
)
|
127
|
-
end
|
128
|
-
end
|
data/spec/api_root_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'simple root api' do
|
4
|
-
before :all do
|
5
|
-
class ApiRoot < Grape::API
|
6
|
-
format :json
|
7
|
-
prefix 'api'
|
8
|
-
version 'v2', using: :header, vendor: 'artsy', strict: false
|
9
|
-
get do
|
10
|
-
{}
|
11
|
-
end
|
12
|
-
add_swagger_documentation
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def app
|
17
|
-
ApiRoot
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'retrieves swagger-documentation on /swagger_doc' do
|
21
|
-
get '/api/swagger_doc'
|
22
|
-
expect(JSON.parse(last_response.body)).to eq(
|
23
|
-
'apiVersion' => '0.1',
|
24
|
-
'swaggerVersion' => '1.2',
|
25
|
-
'info' => {},
|
26
|
-
'produces' => ['application/json'],
|
27
|
-
'apis' => [{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }]
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
data/spec/api_with_nil_types.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'API with minimally documented models' do
|
4
|
-
def app
|
5
|
-
entity_klass = Class.new do
|
6
|
-
def self.exposures
|
7
|
-
{}
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.documentation
|
11
|
-
{
|
12
|
-
bar: { type: String },
|
13
|
-
foo: {}
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.entity_name
|
18
|
-
'Foo'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Class.new(Grape::API) do
|
23
|
-
format :json
|
24
|
-
|
25
|
-
get :foo do
|
26
|
-
end
|
27
|
-
|
28
|
-
add_swagger_documentation \
|
29
|
-
format: :json,
|
30
|
-
models: [Class.new(entity_klass)]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
subject do
|
35
|
-
get '/swagger_doc/foo'
|
36
|
-
JSON.parse(last_response.body)['models']
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns model' do
|
40
|
-
expect(subject).to eq(
|
41
|
-
'Foo' => {
|
42
|
-
'id' => 'Foo',
|
43
|
-
'properties' => {
|
44
|
-
'bar' => { 'type' => 'string' },
|
45
|
-
'foo' => { '$ref' => nil }
|
46
|
-
}
|
47
|
-
}
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Api with "path" versioning' do
|
4
|
-
let(:json_body) { JSON.parse(last_response.body) }
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
class ApiWithPathVersioning < Grape::API
|
8
|
-
format :json
|
9
|
-
version 'v1', using: :path
|
10
|
-
|
11
|
-
namespace :resources do
|
12
|
-
get
|
13
|
-
end
|
14
|
-
|
15
|
-
add_swagger_documentation api_version: 'v1'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def app
|
20
|
-
ApiWithPathVersioning
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'retrieves swagger-documentation on /swagger_doc that contains :resources api path' do
|
24
|
-
get '/v1/swagger_doc'
|
25
|
-
|
26
|
-
expect(json_body['apis']).to eq(
|
27
|
-
[
|
28
|
-
{ 'path' => '/resources.{format}', 'description' => 'Operations about resources' },
|
29
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
30
|
-
]
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'API with Prefix and Namespace' do
|
4
|
-
def app
|
5
|
-
Class.new(Grape::API) do
|
6
|
-
format :json
|
7
|
-
prefix 'api'
|
8
|
-
|
9
|
-
namespace :status do
|
10
|
-
desc 'Retrieve status.'
|
11
|
-
get do
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
add_swagger_documentation
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
subject do
|
20
|
-
get '/api/swagger_doc'
|
21
|
-
expect(last_response.status).to eq 200
|
22
|
-
body = JSON.parse last_response.body
|
23
|
-
body['apis']
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'gets array types' do
|
27
|
-
expect(subject).to eq([
|
28
|
-
{ 'path' => '/status.{format}', 'description' => 'Operations about statuses' },
|
29
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
30
|
-
])
|
31
|
-
end
|
32
|
-
end
|
@@ -1,215 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Standalone namespace API' do
|
4
|
-
let(:json_body) { JSON.parse(last_response.body) }
|
5
|
-
|
6
|
-
describe 'with "path" versioning' do
|
7
|
-
before do
|
8
|
-
class StandaloneApiWithPathVersioning < Grape::API
|
9
|
-
format :json
|
10
|
-
version 'v1', using: :path
|
11
|
-
|
12
|
-
namespace :store do
|
13
|
-
get
|
14
|
-
# will be assigned to standalone the namespace below
|
15
|
-
namespace :orders do
|
16
|
-
get :order_id
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
namespace 'store/orders', swagger: { nested: false } do
|
21
|
-
post :order_idx
|
22
|
-
namespace 'actions' do
|
23
|
-
get 'dummy'
|
24
|
-
end
|
25
|
-
namespace 'actions2', swagger: { nested: false } do
|
26
|
-
get 'dummy2'
|
27
|
-
namespace 'actions22' do
|
28
|
-
get 'dummy22'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
namespace 'store/:store_id/orders', swagger: { nested: false, name: 'specific-store-orders' } do
|
34
|
-
delete :order_id
|
35
|
-
end
|
36
|
-
|
37
|
-
add_swagger_documentation api_version: 'v1'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def app
|
42
|
-
StandaloneApiWithPathVersioning
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'retrieves swagger-documentation on /swagger_doc' do
|
46
|
-
before { get '/v1/swagger_doc' }
|
47
|
-
|
48
|
-
it 'that contains all api paths' do
|
49
|
-
expect(json_body['apis']).to eq(
|
50
|
-
[
|
51
|
-
{ 'path' => '/store.{format}', 'description' => 'Operations about stores' },
|
52
|
-
{ 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' },
|
53
|
-
{ 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' },
|
54
|
-
{ 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' },
|
55
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
56
|
-
]
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store' do
|
62
|
-
before { get '/v1/swagger_doc/store' }
|
63
|
-
it 'does not include standalone namespaces' do
|
64
|
-
apis = json_body['apis']
|
65
|
-
# shall include 1 route, GET on store
|
66
|
-
expect(apis.length).to eql(1)
|
67
|
-
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
72
|
-
before { get '/v1/swagger_doc/store_orders' }
|
73
|
-
it 'does not assign namespaces within standalone namespaces to the general resource' do
|
74
|
-
apis = json_body['apis']
|
75
|
-
# shall include 3 routes, get on store, get with order_id and get dummy on actions
|
76
|
-
expect(apis.length).to eql(3)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders_actions2' do
|
81
|
-
before { get '/v1/swagger_doc/store_orders_actions2' }
|
82
|
-
it 'does appear as standalone namespace within another standalone namespace' do
|
83
|
-
apis = json_body['apis']
|
84
|
-
# shall include 2 routes, get on dummy2 and get on dummy22
|
85
|
-
expect(apis.length).to eql(2)
|
86
|
-
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
87
|
-
expect(apis[1]['operations'][0]['method']).to eql('GET')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/specific-store-orders' do
|
92
|
-
before { get '/v1/swagger_doc/specific-store-orders' }
|
93
|
-
it 'does show the one route' do
|
94
|
-
apis = json_body['apis']
|
95
|
-
# shall include 1 routes, delete action
|
96
|
-
expect(apis.length).to eql(1)
|
97
|
-
expect(apis[0]['operations'][0]['method']).to eql('DELETE')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
102
|
-
before { get '/v1/swagger_doc/store_orders_actions2' }
|
103
|
-
it 'does work with standalone in standalone namespaces' do
|
104
|
-
apis = json_body['apis']
|
105
|
-
# shall include 2 routes, dummy2 and dummy22
|
106
|
-
expect(apis.length).to eql(2)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe 'with header versioning' do
|
112
|
-
before do
|
113
|
-
class StandaloneApiWithHeaderVersioning < Grape::API
|
114
|
-
format :json
|
115
|
-
version 'v1', using: :header, vendor: 'grape-swagger'
|
116
|
-
|
117
|
-
namespace :store do
|
118
|
-
get
|
119
|
-
# will be assigned to standalone the namespace below
|
120
|
-
namespace :orders do
|
121
|
-
get :order_id
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
namespace 'store/orders', swagger: { nested: false } do
|
126
|
-
post :order_idx
|
127
|
-
namespace 'actions' do
|
128
|
-
get 'dummy'
|
129
|
-
end
|
130
|
-
namespace 'actions2', swagger: { nested: false } do
|
131
|
-
get 'dummy2'
|
132
|
-
namespace 'actions22' do
|
133
|
-
get 'dummy22'
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
namespace 'store/:store_id/orders', swagger: { nested: false, name: 'specific-store-orders' } do
|
139
|
-
delete :order_id
|
140
|
-
end
|
141
|
-
|
142
|
-
add_swagger_documentation api_version: 'v1'
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def app
|
147
|
-
StandaloneApiWithHeaderVersioning
|
148
|
-
end
|
149
|
-
|
150
|
-
describe 'retrieves swagger-documentation on /swagger_doc' do
|
151
|
-
before { get 'swagger_doc' }
|
152
|
-
|
153
|
-
it 'that contains all api paths' do
|
154
|
-
expect(json_body['apis']).to eq(
|
155
|
-
[
|
156
|
-
{ 'path' => '/store.{format}', 'description' => 'Operations about stores' },
|
157
|
-
{ 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' },
|
158
|
-
{ 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' },
|
159
|
-
{ 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' },
|
160
|
-
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
161
|
-
]
|
162
|
-
)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store' do
|
167
|
-
before { get '/swagger_doc/store' }
|
168
|
-
it 'does not include standalone namespaces' do
|
169
|
-
apis = json_body['apis']
|
170
|
-
# shall include 1 route, GET on store
|
171
|
-
expect(apis.length).to eql(1)
|
172
|
-
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
177
|
-
before { get '/swagger_doc/store_orders' }
|
178
|
-
it 'does not assign namespaces within standalone namespaces to the general resource' do
|
179
|
-
apis = json_body['apis']
|
180
|
-
# shall include 3 routes, get on store, get with order_id and get dummy on actions
|
181
|
-
expect(apis.length).to eql(3)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders_actions2' do
|
186
|
-
before { get '/swagger_doc/store_orders_actions2' }
|
187
|
-
it 'does appear as standalone namespace within another standalone namespace' do
|
188
|
-
apis = json_body['apis']
|
189
|
-
# shall include 2 routes, get on dummy2 and get on dummy22
|
190
|
-
expect(apis.length).to eql(2)
|
191
|
-
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
192
|
-
expect(apis[1]['operations'][0]['method']).to eql('GET')
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/specific-store-orders' do
|
197
|
-
before { get '/swagger_doc/specific-store-orders' }
|
198
|
-
it 'does show the one route' do
|
199
|
-
apis = json_body['apis']
|
200
|
-
# shall include 1 routes, delete action
|
201
|
-
expect(apis.length).to eql(1)
|
202
|
-
expect(apis[0]['operations'][0]['method']).to eql('DELETE')
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
207
|
-
before { get '/swagger_doc/store_orders_actions2' }
|
208
|
-
it 'does work with standalone in standalone namespaces' do
|
209
|
-
apis = json_body['apis']
|
210
|
-
# shall include 2 routes, dummy2 and dummy22
|
211
|
-
expect(apis.length).to eql(2)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|