grape-swagger 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +29 -32
- data/.travis.yml +2 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +253 -223
- data/UPGRADING.md +4 -0
- data/grape-swagger.gemspec +2 -2
- data/lib/grape-swagger.rb +10 -4
- data/lib/grape-swagger/doc_methods.rb +10 -5
- data/lib/grape-swagger/doc_methods/build_model_definition.rb +38 -0
- data/lib/grape-swagger/doc_methods/data_type.rb +6 -5
- data/lib/grape-swagger/doc_methods/move_params.rb +9 -1
- data/lib/grape-swagger/doc_methods/optional_object.rb +1 -1
- data/lib/grape-swagger/doc_methods/parse_params.rb +20 -19
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +9 -17
- data/lib/grape-swagger/endpoint.rb +26 -29
- data/lib/grape-swagger/model_parsers.rb +7 -0
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/427_entity_as_string_spec.rb +39 -0
- data/spec/issues/430_entity_definitions_spec.rb +48 -4
- data/spec/support/model_parsers/entity_parser.rb +10 -1
- data/spec/support/model_parsers/mock_parser.rb +4 -1
- data/spec/support/model_parsers/representable_parser.rb +13 -2
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +0 -2
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +56 -0
- data/spec/swagger_v2/api_swagger_v2_spec.rb +87 -61
- data/spec/swagger_v2/endpoint_versioned_path_spec.rb +24 -3
- data/spec/swagger_v2/guarded_endpoint_spec.rb +8 -3
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +2 -8
- data/spec/swagger_v2/namespace_tags_spec.rb +2 -8
- data/spec/swagger_v2/params_array_spec.rb +36 -0
- data/spec/swagger_v2/simple_mounted_api_spec.rb +2 -14
- metadata +12 -9
@@ -21,6 +21,10 @@ class SampleAuth < Grape::Middleware::Base
|
|
21
21
|
def access_token=(token)
|
22
22
|
@_access_token = token
|
23
23
|
end
|
24
|
+
|
25
|
+
def resource_owner
|
26
|
+
@resource_owner = true if access_token == '12345'
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def context
|
@@ -50,9 +54,9 @@ end
|
|
50
54
|
describe 'a guarded api endpoint' do
|
51
55
|
before :all do
|
52
56
|
class GuardedMountedApi < Grape::API
|
53
|
-
|
57
|
+
resource_owner_valid = proc { |token_owner = nil| token_owner.nil? }
|
54
58
|
|
55
|
-
desc 'Show endpoint if authenticated', hidden:
|
59
|
+
desc 'Show endpoint if authenticated', hidden: resource_owner_valid
|
56
60
|
get '/auth' do
|
57
61
|
{ foo: 'bar' }
|
58
62
|
end
|
@@ -62,7 +66,7 @@ describe 'a guarded api endpoint' do
|
|
62
66
|
mount GuardedMountedApi
|
63
67
|
add_swagger_documentation endpoint_auth_wrapper: SampleAuth,
|
64
68
|
swagger_endpoint_guard: 'sample_auth false',
|
65
|
-
|
69
|
+
token_owner: 'resource_owner'
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
@@ -82,6 +86,7 @@ describe 'a guarded api endpoint' do
|
|
82
86
|
'swagger' => '2.0',
|
83
87
|
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
84
88
|
'host' => 'example.org',
|
89
|
+
'tags' => [{ 'name' => 'auth', 'description' => 'Operations about auths' }],
|
85
90
|
'paths' => {
|
86
91
|
'/auth' => {
|
87
92
|
'get' => {
|
@@ -55,10 +55,7 @@ describe 'namespace tags check while using prefix and version' do
|
|
55
55
|
specify do
|
56
56
|
expect(subject['tags']).to eql(
|
57
57
|
[
|
58
|
-
{ 'name' => '
|
59
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
60
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
61
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' }
|
58
|
+
{ 'name' => 'colorado', 'description' => 'Operations about colorados' }
|
62
59
|
]
|
63
60
|
)
|
64
61
|
|
@@ -75,10 +72,7 @@ describe 'namespace tags check while using prefix and version' do
|
|
75
72
|
specify do
|
76
73
|
expect(subject['tags']).to eql(
|
77
74
|
[
|
78
|
-
{ 'name' => '
|
79
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
80
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
81
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' }
|
75
|
+
{ 'name' => 'thames', 'description' => 'Operations about thames' }
|
82
76
|
]
|
83
77
|
)
|
84
78
|
|
@@ -48,10 +48,7 @@ describe 'namespace tags check' do
|
|
48
48
|
specify do
|
49
49
|
expect(subject['tags']).to eql(
|
50
50
|
[
|
51
|
-
{ 'name' => '
|
52
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
53
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
54
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' }
|
51
|
+
{ 'name' => 'colorado', 'description' => 'Operations about colorados' }
|
55
52
|
]
|
56
53
|
)
|
57
54
|
|
@@ -68,10 +65,7 @@ describe 'namespace tags check' do
|
|
68
65
|
specify do
|
69
66
|
expect(subject['tags']).to eql(
|
70
67
|
[
|
71
|
-
{ 'name' => '
|
72
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
73
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
74
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' }
|
68
|
+
{ 'name' => 'thames', 'description' => 'Operations about thames' }
|
75
69
|
]
|
76
70
|
)
|
77
71
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Group Params as Array' do
|
4
|
+
include_context "#{MODEL_PARSER} swagger example"
|
5
|
+
|
4
6
|
def app
|
5
7
|
Class.new(Grape::API) do
|
6
8
|
format :json
|
@@ -57,6 +59,14 @@ describe 'Group Params as Array' do
|
|
57
59
|
{ 'declared_params' => declared(params) }
|
58
60
|
end
|
59
61
|
|
62
|
+
params do
|
63
|
+
requires :array_of_entities, type: Array[Entities::ApiError]
|
64
|
+
end
|
65
|
+
|
66
|
+
post '/array_of_entities' do
|
67
|
+
{ 'declared_params' => declared(params) }
|
68
|
+
end
|
69
|
+
|
60
70
|
add_swagger_documentation
|
61
71
|
end
|
62
72
|
end
|
@@ -156,4 +166,30 @@ describe 'Group Params as Array' do
|
|
156
166
|
)
|
157
167
|
end
|
158
168
|
end
|
169
|
+
|
170
|
+
describe 'documentation for entity array parameters' do
|
171
|
+
let(:parameters) do
|
172
|
+
[
|
173
|
+
{
|
174
|
+
'in' => 'formData',
|
175
|
+
'name' => 'array_of_entities',
|
176
|
+
'type' => 'array',
|
177
|
+
'items' => {
|
178
|
+
'$ref' => '#/definitions/ApiError'
|
179
|
+
},
|
180
|
+
'required' => true
|
181
|
+
}
|
182
|
+
]
|
183
|
+
end
|
184
|
+
|
185
|
+
subject do
|
186
|
+
get '/swagger_doc/array_of_entities'
|
187
|
+
JSON.parse(last_response.body)
|
188
|
+
end
|
189
|
+
|
190
|
+
specify do
|
191
|
+
expect(subject['definitions']['ApiError']).not_to be_blank
|
192
|
+
expect(subject['paths']['/array_of_entities']['post']['parameters']).to eql(parameters)
|
193
|
+
end
|
194
|
+
end
|
159
195
|
end
|
@@ -193,13 +193,7 @@ describe 'a simple mounted api' do
|
|
193
193
|
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
194
194
|
'host' => 'example.org',
|
195
195
|
'tags' => [
|
196
|
-
{ 'name' => 'simple', 'description' => 'Operations about simples' }
|
197
|
-
{ 'name' => 'simple-test', 'description' => 'Operations about simple-tests' },
|
198
|
-
{ 'name' => 'simple-head-test', 'description' => 'Operations about simple-head-tests' },
|
199
|
-
{ 'name' => 'simple-options-test', 'description' => 'Operations about simple-options-tests' },
|
200
|
-
{ 'name' => 'simple_with_headers', 'description' => 'Operations about simple_with_headers' },
|
201
|
-
{ 'name' => 'items', 'description' => 'Operations about items' },
|
202
|
-
{ 'name' => 'custom', 'description' => 'Operations about customs' }
|
196
|
+
{ 'name' => 'simple', 'description' => 'Operations about simples' }
|
203
197
|
],
|
204
198
|
'paths' => {
|
205
199
|
'/simple' => {
|
@@ -231,13 +225,7 @@ describe 'a simple mounted api' do
|
|
231
225
|
'produces' => ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
232
226
|
'host' => 'example.org',
|
233
227
|
'tags' => [
|
234
|
-
{ 'name' => 'simple', 'description' => 'Operations about
|
235
|
-
{ 'name' => 'simple-test', 'description' => 'Operations about simple-tests' },
|
236
|
-
{ 'name' => 'simple-head-test', 'description' => 'Operations about simple-head-tests' },
|
237
|
-
{ 'name' => 'simple-options-test', 'description' => 'Operations about simple-options-tests' },
|
238
|
-
{ 'name' => 'simple_with_headers', 'description' => 'Operations about simple_with_headers' },
|
239
|
-
{ 'name' => 'items', 'description' => 'Operations about items' },
|
240
|
-
{ 'name' => 'custom', 'description' => 'Operations about customs' }
|
228
|
+
{ 'name' => 'simple-test', 'description' => 'Operations about simple-tests' }
|
241
229
|
],
|
242
230
|
'paths' => {
|
243
231
|
'/simple-test' => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Vandecasteele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -126,16 +126,16 @@ dependencies:
|
|
126
126
|
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.40
|
131
|
+
version: '0.40'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.40
|
138
|
+
version: '0.40'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: kramdown
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -238,6 +238,7 @@ files:
|
|
238
238
|
- grape-swagger.gemspec
|
239
239
|
- lib/grape-swagger.rb
|
240
240
|
- lib/grape-swagger/doc_methods.rb
|
241
|
+
- lib/grape-swagger/doc_methods/build_model_definition.rb
|
241
242
|
- lib/grape-swagger/doc_methods/data_type.rb
|
242
243
|
- lib/grape-swagger/doc_methods/extensions.rb
|
243
244
|
- lib/grape-swagger/doc_methods/headers.rb
|
@@ -258,6 +259,7 @@ files:
|
|
258
259
|
- lib/grape-swagger/rake/oapi_tasks.rb
|
259
260
|
- lib/grape-swagger/version.rb
|
260
261
|
- spec/issues/403_versions_spec.rb
|
262
|
+
- spec/issues/427_entity_as_string_spec.rb
|
261
263
|
- spec/issues/430_entity_definitions_spec.rb
|
262
264
|
- spec/lib/data_type_spec.rb
|
263
265
|
- spec/lib/endpoint_spec.rb
|
@@ -346,13 +348,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
346
348
|
version: '0'
|
347
349
|
requirements: []
|
348
350
|
rubyforge_project:
|
349
|
-
rubygems_version: 2.6.
|
351
|
+
rubygems_version: 2.6.7
|
350
352
|
signing_key:
|
351
353
|
specification_version: 4
|
352
|
-
summary:
|
353
|
-
|
354
|
+
summary: Add auto generated documentation to your Grape API that can be displayed
|
355
|
+
with Swagger.
|
354
356
|
test_files:
|
355
357
|
- spec/issues/403_versions_spec.rb
|
358
|
+
- spec/issues/427_entity_as_string_spec.rb
|
356
359
|
- spec/issues/430_entity_definitions_spec.rb
|
357
360
|
- spec/lib/data_type_spec.rb
|
358
361
|
- spec/lib/endpoint_spec.rb
|