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,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Float Params' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
format :json
|
9
|
-
|
10
|
-
params do
|
11
|
-
requires :a_float, type: Float
|
12
|
-
end
|
13
|
-
post :splines do
|
14
|
-
{ message: 'hi' }
|
15
|
-
end
|
16
|
-
|
17
|
-
add_swagger_documentation
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
subject do
|
22
|
-
get '/swagger_doc/splines'
|
23
|
-
expect(last_response.status).to eq 200
|
24
|
-
body = JSON.parse last_response.body
|
25
|
-
body['paths']['/splines']['post']['parameters']
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'converts float types' do
|
29
|
-
expect(subject).to eq [
|
30
|
-
{ 'in' => 'formData', 'name' => 'a_float', 'type' => 'number', 'required' => true, 'format' => 'float' }
|
31
|
-
]
|
32
|
-
end
|
33
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Form Params' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
format :json
|
9
|
-
|
10
|
-
params do
|
11
|
-
requires :name, type: String, desc: 'name of item'
|
12
|
-
end
|
13
|
-
post '/items' do
|
14
|
-
{}
|
15
|
-
end
|
16
|
-
|
17
|
-
params do
|
18
|
-
requires :id, type: Integer, desc: 'id of item'
|
19
|
-
requires :name, type: String, desc: 'name of item'
|
20
|
-
requires :conditions, type: Integer, desc: 'conditions of item', values: [1, 2, 3]
|
21
|
-
end
|
22
|
-
put '/items/:id' do
|
23
|
-
{}
|
24
|
-
end
|
25
|
-
|
26
|
-
params do
|
27
|
-
requires :id, type: Integer, desc: 'id of item'
|
28
|
-
requires :name, type: String, desc: 'name of item'
|
29
|
-
optional :conditions, type: String, desc: 'conditions of item', values: proc { %w[1 2] }
|
30
|
-
end
|
31
|
-
patch '/items/:id' do
|
32
|
-
{}
|
33
|
-
end
|
34
|
-
|
35
|
-
params do
|
36
|
-
requires :id, type: Integer, desc: 'id of item'
|
37
|
-
requires :name, type: String, desc: 'name of item'
|
38
|
-
optional :conditions, type: Symbol, desc: 'conditions of item', values: %i[one two]
|
39
|
-
end
|
40
|
-
post '/items/:id' do
|
41
|
-
{}
|
42
|
-
end
|
43
|
-
|
44
|
-
add_swagger_documentation
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
subject do
|
49
|
-
get '/swagger_doc/items'
|
50
|
-
JSON.parse(last_response.body)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'retrieves the documentation form params' do
|
54
|
-
expect(subject['paths'].length).to eq 2
|
55
|
-
expect(subject['paths'].keys).to include('/items', '/items/{id}')
|
56
|
-
expect(subject['paths']['/items'].keys).to include 'post'
|
57
|
-
expect(subject['paths']['/items/{id}'].keys).to include('post', 'patch', 'put')
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'treats Symbol parameter as form param' do
|
61
|
-
expect(subject['paths']['/items/{id}']['post']['parameters']).to eq [
|
62
|
-
{ 'in' => 'path', 'name' => 'id', 'description' => 'id of item', 'type' => 'integer', 'required' => true, 'format' => 'int32' },
|
63
|
-
{ 'in' => 'formData', 'name' => 'name', 'description' => 'name of item', 'type' => 'string', 'required' => true },
|
64
|
-
{ 'in' => 'formData', 'name' => 'conditions', 'description' => 'conditions of item', 'type' => 'string', 'required' => false, 'enum' => %w[one two] }
|
65
|
-
]
|
66
|
-
end
|
67
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeInstance do
|
6
|
-
it 'added combined-routes' do
|
7
|
-
expect(described_class).to respond_to :combined_routes
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'added add_swagger_documentation' do
|
11
|
-
expect(described_class).to respond_to :add_swagger_documentation
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'added combined-namespaces' do
|
15
|
-
expect(described_class).to respond_to :combined_namespaces
|
16
|
-
end
|
17
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
class SampleAuth < Grape::Middleware::Base
|
6
|
-
module AuthMethods
|
7
|
-
attr_accessor :access_token
|
8
|
-
|
9
|
-
def protected_endpoint=(protected)
|
10
|
-
@protected_endpoint = protected
|
11
|
-
end
|
12
|
-
|
13
|
-
def protected_endpoint?
|
14
|
-
@protected_endpoint || false
|
15
|
-
end
|
16
|
-
|
17
|
-
def resource_owner
|
18
|
-
@resource_owner = true if access_token == '12345'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def context
|
23
|
-
env['api.endpoint']
|
24
|
-
end
|
25
|
-
|
26
|
-
def before
|
27
|
-
context.extend(SampleAuth::AuthMethods)
|
28
|
-
context.protected_endpoint = context.options[:route_options][:auth].present?
|
29
|
-
|
30
|
-
return unless context.protected_endpoint?
|
31
|
-
|
32
|
-
scopes = context.options[:route_options][:auth][:scopes]
|
33
|
-
authorize!(*scopes) unless scopes.include? false
|
34
|
-
context.access_token = env['HTTP_AUTHORIZATION']
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module Extension
|
39
|
-
def sample_auth(*scopes)
|
40
|
-
description = route_setting(:description) || route_setting(:description, {})
|
41
|
-
description[:auth] = { scopes: scopes }
|
42
|
-
end
|
43
|
-
|
44
|
-
GrapeInstance.extend self
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'a guarded api endpoint' do
|
48
|
-
before :all do
|
49
|
-
class GuardedMountedApi < Grape::API
|
50
|
-
resource_owner_valid = proc { |token_owner = nil| token_owner.nil? }
|
51
|
-
|
52
|
-
desc 'Show endpoint if authenticated'
|
53
|
-
route_setting :swagger, hidden: resource_owner_valid
|
54
|
-
get '/auth' do
|
55
|
-
{ foo: 'bar' }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class GuardedApi < Grape::API
|
60
|
-
mount GuardedMountedApi
|
61
|
-
add_swagger_documentation endpoint_auth_wrapper: SampleAuth,
|
62
|
-
swagger_endpoint_guard: 'sample_auth false',
|
63
|
-
token_owner: 'resource_owner'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def app
|
68
|
-
GuardedApi
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:endpoint) { '/swagger_doc.json' }
|
72
|
-
let(:auth_token) { nil }
|
73
|
-
|
74
|
-
subject do
|
75
|
-
get endpoint, {}, 'HTTP_AUTHORIZATION' => auth_token
|
76
|
-
JSON.parse(last_response.body)
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'accessing the main doc endpoint' do
|
80
|
-
let(:endpoint) { '/swagger_doc.json' }
|
81
|
-
|
82
|
-
context 'when a correct token is passed with the request' do
|
83
|
-
let(:auth_token) { '12345' }
|
84
|
-
|
85
|
-
it 'retrieves swagger-documentation for the endpoint' do
|
86
|
-
expect(subject).to eq(
|
87
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
88
|
-
'swagger' => '2.0',
|
89
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
90
|
-
'host' => 'example.org',
|
91
|
-
'tags' => [{ 'name' => 'auth', 'description' => 'Operations about auths' }],
|
92
|
-
'paths' => {
|
93
|
-
'/auth' => {
|
94
|
-
'get' => {
|
95
|
-
'description' => 'Show endpoint if authenticated',
|
96
|
-
'produces' => ['application/json'],
|
97
|
-
'tags' => ['auth'],
|
98
|
-
'operationId' => 'getAuth',
|
99
|
-
'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when a bad token is passed with the request' do
|
108
|
-
let(:auth_token) { '123456' }
|
109
|
-
|
110
|
-
it 'does not retrieve swagger-documentation for the endpoint - only the info_object' do
|
111
|
-
expect(subject).to eq(
|
112
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
113
|
-
'swagger' => '2.0',
|
114
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
115
|
-
'host' => 'example.org'
|
116
|
-
)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'accessing the tag specific endpoint' do
|
122
|
-
let(:endpoint) { '/swagger_doc/auth.json' }
|
123
|
-
|
124
|
-
context 'when a correct token is passed with the request' do
|
125
|
-
let(:auth_token) { '12345' }
|
126
|
-
|
127
|
-
it 'retrieves swagger-documentation for the endpoint' do
|
128
|
-
expect(subject).to eq(
|
129
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
130
|
-
'swagger' => '2.0',
|
131
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
132
|
-
'host' => 'example.org',
|
133
|
-
'tags' => [{ 'name' => 'auth', 'description' => 'Operations about auths' }],
|
134
|
-
'paths' => {
|
135
|
-
'/auth' => {
|
136
|
-
'get' => {
|
137
|
-
'description' => 'Show endpoint if authenticated',
|
138
|
-
'produces' => ['application/json'],
|
139
|
-
'tags' => ['auth'],
|
140
|
-
'operationId' => 'getAuth',
|
141
|
-
'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when a bad token is passed with the request' do
|
150
|
-
let(:auth_token) { '123456' }
|
151
|
-
|
152
|
-
it 'does not retrieve swagger-documentation for the endpoint - only the info_object' do
|
153
|
-
expect(subject).to eq(
|
154
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
155
|
-
'swagger' => '2.0',
|
156
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
157
|
-
'host' => 'example.org'
|
158
|
-
)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'a hide mounted api' do
|
6
|
-
before :all do
|
7
|
-
class HideMountedApi < Grape::API
|
8
|
-
desc 'Show this endpoint'
|
9
|
-
get '/simple' do
|
10
|
-
{ foo: 'bar' }
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Hide this endpoint', hidden: true
|
14
|
-
get '/hide' do
|
15
|
-
{ foo: 'bar' }
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'Hide this endpoint using route setting'
|
19
|
-
route_setting :swagger, hidden: true
|
20
|
-
get '/hide_as_well' do
|
21
|
-
{ foo: 'bar' }
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Lazily show endpoint', hidden: -> { false }
|
25
|
-
get '/lazy' do
|
26
|
-
{ foo: 'bar' }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class HideApi < Grape::API
|
31
|
-
mount HideMountedApi
|
32
|
-
add_swagger_documentation
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def app
|
37
|
-
HideApi
|
38
|
-
end
|
39
|
-
|
40
|
-
subject do
|
41
|
-
get '/swagger_doc.json'
|
42
|
-
JSON.parse(last_response.body)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "retrieves swagger-documentation that doesn't include hidden endpoints" do
|
46
|
-
expect(subject).to eq(
|
47
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
48
|
-
'swagger' => '2.0',
|
49
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
50
|
-
'host' => 'example.org',
|
51
|
-
'tags' => [{ 'name' => 'simple', 'description' => 'Operations about simples' }, { 'name' => 'lazy', 'description' => 'Operations about lazies' }],
|
52
|
-
'paths' => {
|
53
|
-
'/simple' => {
|
54
|
-
'get' => {
|
55
|
-
'description' => 'Show this endpoint',
|
56
|
-
'produces' => ['application/json'],
|
57
|
-
'tags' => ['simple'],
|
58
|
-
'operationId' => 'getSimple',
|
59
|
-
'responses' => { '200' => { 'description' => 'Show this endpoint' } }
|
60
|
-
}
|
61
|
-
},
|
62
|
-
'/lazy' => {
|
63
|
-
'get' => {
|
64
|
-
'description' => 'Lazily show endpoint',
|
65
|
-
'produces' => ['application/json'],
|
66
|
-
'tags' => ['lazy'],
|
67
|
-
'operationId' => 'getLazy',
|
68
|
-
'responses' => { '200' => { 'description' => 'Lazily show endpoint' } }
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'a hide mounted api with same namespace' do
|
77
|
-
before :all do
|
78
|
-
class HideNamespaceMountedApi < Grape::API
|
79
|
-
desc 'Show this endpoint'
|
80
|
-
get '/simple/show' do
|
81
|
-
{ foo: 'bar' }
|
82
|
-
end
|
83
|
-
|
84
|
-
desc 'Hide this endpoint', hidden: true
|
85
|
-
get '/simple/hide' do
|
86
|
-
{ foo: 'bar' }
|
87
|
-
end
|
88
|
-
|
89
|
-
desc 'Lazily hide endpoint', hidden: -> { true }
|
90
|
-
get '/simple/lazy' do
|
91
|
-
{ foo: 'bar' }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class HideNamespaceApi < Grape::API
|
96
|
-
mount HideNamespaceMountedApi
|
97
|
-
add_swagger_documentation
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def app
|
102
|
-
HideNamespaceApi
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'retrieves swagger-documentation on /swagger_doc' do
|
106
|
-
get '/swagger_doc.json'
|
107
|
-
expect(JSON.parse(last_response.body)).to eq(
|
108
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
109
|
-
'swagger' => '2.0',
|
110
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
111
|
-
'host' => 'example.org',
|
112
|
-
'tags' => [{ 'name' => 'simple', 'description' => 'Operations about simples' }],
|
113
|
-
'paths' => {
|
114
|
-
'/simple/show' => {
|
115
|
-
'get' => {
|
116
|
-
'description' => 'Show this endpoint',
|
117
|
-
'produces' => ['application/json'],
|
118
|
-
'operationId' => 'getSimpleShow',
|
119
|
-
'tags' => ['simple'], 'responses' => { '200' => { 'description' => 'Show this endpoint' } }
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "retrieves the documentation for mounted-api that doesn't include hidden endpoints" do
|
127
|
-
get '/swagger_doc/simple.json'
|
128
|
-
expect(JSON.parse(last_response.body)).to eq(
|
129
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
130
|
-
'swagger' => '2.0',
|
131
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
132
|
-
'host' => 'example.org',
|
133
|
-
'tags' => [{ 'name' => 'simple', 'description' => 'Operations about simples' }],
|
134
|
-
'paths' => {
|
135
|
-
'/simple/show' => {
|
136
|
-
'get' => {
|
137
|
-
'description' => 'Show this endpoint',
|
138
|
-
'produces' => ['application/json'],
|
139
|
-
'tags' => ['simple'],
|
140
|
-
'operationId' => 'getSimpleShow',
|
141
|
-
'responses' => { '200' => { 'description' => 'Show this endpoint' } }
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
)
|
146
|
-
end
|
147
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'host in the swagger_doc' do
|
6
|
-
before :all do
|
7
|
-
module TheApi
|
8
|
-
class EmptyApi < Grape::API
|
9
|
-
format :json
|
10
|
-
|
11
|
-
add_swagger_documentation
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def app
|
17
|
-
TheApi::EmptyApi
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'host should include port' do
|
21
|
-
subject do
|
22
|
-
get 'http://example.com:8080/swagger_doc'
|
23
|
-
JSON.parse(last_response.body)
|
24
|
-
end
|
25
|
-
|
26
|
-
specify do
|
27
|
-
expect(subject['host']).to eq 'example.com:8080'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'respect X-Forwarded-Host over Host header' do
|
32
|
-
subject do
|
33
|
-
header 'Host', 'dummy.example.com'
|
34
|
-
header 'X-Forwarded-Host', 'real.example.com'
|
35
|
-
get '/swagger_doc'
|
36
|
-
JSON.parse(last_response.body)
|
37
|
-
end
|
38
|
-
|
39
|
-
specify do
|
40
|
-
expect(subject['host']).to eq 'real.example.com'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Inheritance and Discriminator' do
|
6
|
-
before :all do
|
7
|
-
module InheritanceTest
|
8
|
-
module Entities
|
9
|
-
# example from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-polymorphism-supports
|
10
|
-
class Pet < Grape::Entity
|
11
|
-
expose :type, documentation: {
|
12
|
-
type: 'string',
|
13
|
-
is_discriminator: true,
|
14
|
-
required: true
|
15
|
-
}
|
16
|
-
expose :name, documentation: {
|
17
|
-
type: 'string',
|
18
|
-
required: true
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
class Cat < Pet
|
23
|
-
expose :huntingSkill, documentation: {
|
24
|
-
type: 'string',
|
25
|
-
description: 'The measured skill for hunting',
|
26
|
-
default: 'lazy',
|
27
|
-
values: %w[
|
28
|
-
clueless
|
29
|
-
lazy
|
30
|
-
adventurous
|
31
|
-
aggressive
|
32
|
-
]
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class NameApi < Grape::API
|
38
|
-
add_swagger_documentation models: [Entities::Pet, Entities::Cat]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'Parent model' do
|
44
|
-
let(:app) { InheritanceTest::NameApi }
|
45
|
-
|
46
|
-
subject do
|
47
|
-
get '/swagger_doc'
|
48
|
-
JSON.parse(last_response.body)['definitions']
|
49
|
-
end
|
50
|
-
|
51
|
-
specify do
|
52
|
-
subject['InheritanceTest_Entities_Pet'].key?('discriminator')
|
53
|
-
subject['InheritanceTest_Entities_Pet']['discriminator'] = 'type'
|
54
|
-
subject['InheritanceTest_Entities_Cat'].key?('allOf')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'mount override api' do
|
6
|
-
def app
|
7
|
-
old_api = Class.new(Grape::API) do
|
8
|
-
desc 'old endpoint', success: { code: 200, message: 'old message' }
|
9
|
-
params do
|
10
|
-
optional :param, type: Integer, desc: 'old param'
|
11
|
-
end
|
12
|
-
get do
|
13
|
-
'old'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
new_api = Class.new(Grape::API) do
|
18
|
-
desc 'new endpoint', success: { code: 200, message: 'new message' }
|
19
|
-
params do
|
20
|
-
optional :param, type: String, desc: 'new param'
|
21
|
-
end
|
22
|
-
get do
|
23
|
-
'new'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
Class.new(Grape::API) do
|
28
|
-
mount new_api
|
29
|
-
mount old_api
|
30
|
-
|
31
|
-
add_swagger_documentation format: :json
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'actual api request' do
|
36
|
-
subject do
|
37
|
-
get '/'
|
38
|
-
last_response.body
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns data from new endpoint' do
|
42
|
-
is_expected.to eq 'new'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'api documentation' do
|
47
|
-
subject do
|
48
|
-
get '/swagger_doc'
|
49
|
-
JSON.parse(last_response.body)['paths']['/']['get']
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'shows documentation from new endpoint' do
|
53
|
-
expect(subject['parameters'][0]['description']).to eql('new param')
|
54
|
-
expect(subject['parameters'][0]['type']).to eql('string')
|
55
|
-
expect(subject['responses']['200']['description']).to eql('new message')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
xdescribe 'docs mounted separately from api' do
|
6
|
-
before :all do
|
7
|
-
class ActualApi < Grape::API
|
8
|
-
desc 'Document root'
|
9
|
-
|
10
|
-
desc 'This gets something.',
|
11
|
-
notes: '_test_'
|
12
|
-
get '/simple' do
|
13
|
-
{ bla: 'something' }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class MountedDocs < Grape::API
|
18
|
-
add_swagger_documentation(target_class: ActualApi)
|
19
|
-
end
|
20
|
-
|
21
|
-
class WholeApp < Grape::API
|
22
|
-
mount ActualApi
|
23
|
-
mount MountedDocs
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def app
|
28
|
-
WholeApp
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'retrieves docs for actual api class' do
|
32
|
-
get '/swagger_doc.json'
|
33
|
-
expect(JSON.parse(last_response.body)).to eq(
|
34
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
35
|
-
'swagger' => '2.0',
|
36
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
37
|
-
'host' => 'example.org',
|
38
|
-
'tags' => [{ 'name' => 'simple', 'description' => 'Operations about simples' }],
|
39
|
-
'paths' => {
|
40
|
-
'/simple' => {
|
41
|
-
'get' => {
|
42
|
-
'description' => 'This gets something.',
|
43
|
-
'produces' => ['application/json'],
|
44
|
-
'responses' => { '200' => { 'description' => 'This gets something.' } },
|
45
|
-
'tags' => ['simple'],
|
46
|
-
'operationId' => 'getSimple'
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'retrieves docs for endpoint in actual api class' do
|
54
|
-
get '/swagger_doc/simple.json'
|
55
|
-
expect(JSON.parse(last_response.body)).to eq(
|
56
|
-
'info' => { 'title' => 'API title', 'version' => '0.0.1' },
|
57
|
-
'swagger' => '2.0',
|
58
|
-
'tags' => [{ 'name' => 'simple', 'description' => 'Operations about simples' }],
|
59
|
-
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
60
|
-
'host' => 'example.org',
|
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
|