grape-swagger 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/.travis.yml +9 -9
- data/CHANGELOG.md +19 -4
- data/Dangerfile +1 -0
- data/Gemfile +3 -1
- data/README.md +7 -9
- data/UPGRADING.md +16 -0
- data/lib/grape-swagger/doc_methods/data_type.rb +1 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +34 -36
- data/lib/grape-swagger/doc_methods/operation_id.rb +9 -3
- data/lib/grape-swagger/endpoint.rb +13 -6
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/403_versions_spec.rb +41 -92
- data/spec/lib/data_type_spec.rb +6 -0
- data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +44 -0
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +46 -0
- data/spec/swagger_v2/nicknamed_api_spec.rb +23 -0
- data/spec/swagger_v2/params_array_spec.rb +4 -2
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9531be292e7a5a8d3ee086291e248f42f13457
|
4
|
+
data.tar.gz: 8f7cea40f42d1bb5a474f3468000c837eb540699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 133c28324c1637b9117e06e33e4585df7b3c072dba7432784550b1c309b24b1635abd18f97a06ce43b9c9650176a7df7bccb0a4d7ddb4cc80d61ac7ddbd067a1
|
7
|
+
data.tar.gz: 238698df89fbb172922f2224652eddff2fc26d89c593fb90f787bab4293def4d32bcdfd929200c7ef1770b6c33a486feb7435763bae9eb8708e83992c927cd2f
|
data/.rubocop_todo.yml
CHANGED
data/.travis.yml
CHANGED
@@ -4,32 +4,32 @@ sudo: false
|
|
4
4
|
|
5
5
|
matrix:
|
6
6
|
include:
|
7
|
+
- rvm: 2.3.1
|
8
|
+
script:
|
9
|
+
- bundle exec danger
|
7
10
|
- rvm: 2.3.1
|
8
11
|
env: MODEL_PARSER=grape-swagger-entity
|
9
12
|
- rvm: 2.3.1
|
10
13
|
env: MODEL_PARSER=grape-swagger-representable
|
11
|
-
- rvm: 2.3.1
|
12
|
-
env: GRAPE_VERSION=0.12.0
|
13
|
-
- rvm: 2.3.1
|
14
|
-
env: GRAPE_VERSION=0.13.0
|
15
14
|
- rvm: 2.3.1
|
16
15
|
env: GRAPE_VERSION=0.14.0
|
17
16
|
- rvm: 2.3.1
|
18
17
|
env: GRAPE_VERSION=0.15.0
|
19
18
|
- rvm: 2.3.1
|
20
19
|
env: GRAPE_VERSION=0.16.2
|
20
|
+
- rvm: 2.3.1
|
21
|
+
env: GRAPE_VERSION=0.17.0
|
21
22
|
- rvm: 2.3.1
|
22
23
|
env: GRAPE_VERSION=HEAD
|
23
24
|
- rvm: 2.3.0
|
24
25
|
- rvm: 2.2
|
25
26
|
- rvm: 2.1
|
26
27
|
- rvm: ruby-head
|
27
|
-
- rvm:
|
28
|
-
- rvm: jruby-9.0.5.0
|
29
|
-
- rvm: jruby-19mode
|
28
|
+
- rvm: jruby-9.1.2.0
|
30
29
|
- rvm: jruby-head
|
30
|
+
- rvm: rbx-2
|
31
31
|
allow_failures:
|
32
32
|
- rvm: ruby-head
|
33
|
-
- rvm:
|
34
|
-
- rvm: jruby-19mode
|
33
|
+
- rvm: jruby-9.1.2.0
|
35
34
|
- rvm: jruby-head
|
35
|
+
- rvm: rbx-2
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,21 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 0.23.0 (August 5, 2016)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#491](https://github.com/ruby-grape/grape/pull/491): Add `ignore_defaults` option - [@pezholio](https://github.com/pezholio).
|
16
|
+
* [#486](https://github.com/ruby-grape/grape/pull/486): Use an automated PR linter, [danger.systems](http://danger.systems) - [@dblock](https://github.com/dblock).
|
17
|
+
|
18
|
+
#### Fixes
|
19
|
+
|
20
|
+
* [#489](https://github.com/ruby-grape/grape-swagger/pull/489): Makes version settings/usage more clear; updates `UPGRADE.md`, `README.md` - [@LeFnord](https://github.com/LeFnord).
|
21
|
+
* [#476](https://github.com/ruby-grape/grape-swagger/pull/476): Fixes for handling the parameter type when body parameters are defined inside desc block - [@anakinj](https://github.com/anakinj).
|
22
|
+
* [#478](https://github.com/ruby-grape/grape-swagger/pull/478): Refactors building of properties, corrects documentation of array items - [@LeFnord](https://github.com/LeFnord).
|
23
|
+
* [#479](https://github.com/ruby-grape/grape-swagger/pull/479): Fix regex for Array and Multi Type in doc_methods. Parsing of "[APoint]" should return "APoint" - [@frodrigo](https://github.com/frodrigo).
|
24
|
+
* [#483](https://github.com/ruby-grape/grape-swagger/pull/483): Added support for nicknamed routes - [@pbendersky](https://github.com/pbendersky).
|
25
|
+
|
11
26
|
### 0.22.0 (July 12, 2016)
|
12
27
|
|
13
28
|
#### Features
|
@@ -27,10 +42,10 @@
|
|
27
42
|
* [#455](https://github.com/ruby-grape/grape-swagger/pull/455): Setting `type:` option as `Array[Class]` creates `array` type in JSON - [@tyspring](https://github.com/tyspring).
|
28
43
|
* [#450](https://github.com/ruby-grape/grape-swagger/pull/438): Do not add :description to definitions if :description is missing on path - [@texpert](https://github.com/texpert).
|
29
44
|
* [#447](https://github.com/ruby-grape/grape-swagger/pull/447): Version part of the url is now ignored when generating tags for endpoint - [@anakinj](https://github.com/anakinj).
|
30
|
-
* [#444](https://github.com/ruby-grape/grape-swagger
|
31
|
-
* [#443](https://github.com/ruby-grape/grape-swagger/issues/443): Type provided in the documentation hash, override the grape type [@scauglog](https://github.com/scauglog).
|
45
|
+
* [#444](https://github.com/ruby-grape/grape-swagger/pull/444): Default value provided in the documentation hash, override the grape default - [@scauglog](https://github.com/scauglog).
|
46
|
+
* [#443](https://github.com/ruby-grape/grape-swagger/issues/443): Type provided in the documentation hash, override the grape type - [@scauglog](https://github.com/scauglog).
|
32
47
|
* [#454](https://github.com/ruby-grape/grape-swagger/pull/454): Include documented Hashes in documentation output - [@aschuster3](https://github.com/aschuster3).
|
33
|
-
* [#457](https://github.com/ruby-grape/grape-swagger/issues/457): Using camel case on namespace throws exception on add_swagger_documentation method - [@rayko](https://github.com/rayko
|
48
|
+
* [#457](https://github.com/ruby-grape/grape-swagger/issues/457): Using camel case on namespace throws exception on add_swagger_documentation method - [@rayko](https://github.com/rayko).
|
34
49
|
|
35
50
|
### 0.21.0 (June 1, 2016)
|
36
51
|
|
@@ -167,7 +182,7 @@
|
|
167
182
|
* [#136](https://github.com/ruby-grape/grape-swagger/pull/136), [#94](https://github.com/ruby-grape/grape-swagger/pull/94): Recurse combination of namespaces when using mounted apps - [@renier](https://github.com/renier).
|
168
183
|
* [#100](https://github.com/ruby-grape/grape-swagger/pull/100): Added ability to specify a nickname for an endpoint - [@lhorne](https://github.com/lhorne).
|
169
184
|
* [#94](https://github.com/ruby-grape/grape-swagger/pull/94): Added support for namespace descriptions - [@renier](https://github.com/renier).
|
170
|
-
* [#110](https://github.com/ruby-grape/grape-swagger/pull/110), [#111](https://github.com/ruby-grape/grape-swagger/pull/111)
|
185
|
+
* [#110](https://github.com/ruby-grape/grape-swagger/pull/110), [#111](https://github.com/ruby-grape/grape-swagger/pull/111): Added `responseModel` support - [@bagilevi](https://github.com/bagilevi).
|
171
186
|
* [#114](https://github.com/ruby-grape/grape-swagger/pull/114): Added support for generating nested models from composed Grape Entities - [@dspaeth-faber](https://github.com/dspaeth-faber).
|
172
187
|
* [#124](https://github.com/ruby-grape/grape-swagger/pull/124): Added ability to change the description and parameters of the API endpoints generated by grape-swagger - [@dblock](https://github.com/dblock).
|
173
188
|
* [#128](https://github.com/ruby-grape/grape-swagger/pull/128): Combine global models and endpoint entities - [@dspaeth-faber](https://github.com/dspaeth-faber).
|
data/Dangerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# inherits from https://github.com/ruby-grape/danger
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
case version = ENV['GRAPE_VERSION'] || '~> 0.
|
5
|
+
case version = ENV['GRAPE_VERSION'] || '~> 0.17.0'
|
6
6
|
when 'HEAD'
|
7
7
|
gem 'grape', github: 'ruby-grape/grape'
|
8
8
|
else
|
@@ -15,3 +15,5 @@ if RUBY_VERSION < '2.2.2'
|
|
15
15
|
gem 'rack', '<2.0.0'
|
16
16
|
gem 'activesupport', '<5.0.0'
|
17
17
|
end
|
18
|
+
|
19
|
+
gem 'danger', '~> 2.1', require: false
|
data/README.md
CHANGED
@@ -199,8 +199,7 @@ end
|
|
199
199
|
|
200
200
|
|
201
201
|
You can pass a hash with optional configuration settings to ```add_swagger_documentation```.
|
202
|
-
|
203
|
-
*not all configuration options supported yet*, but is WIP
|
202
|
+
The examples shows the default value.
|
204
203
|
|
205
204
|
|
206
205
|
The `host` and `base_path` options also accept a `proc` or `lambda` to evaluate, which is passed a [request](http://www.rubydoc.info/github/rack/rack/Rack/Request) object:
|
@@ -223,7 +222,7 @@ add_swagger_documentation \
|
|
223
222
|
Base path of the API that's being exposed, default would be taken from `request`.
|
224
223
|
```ruby
|
225
224
|
add_swagger_documentation \
|
226
|
-
base_path:
|
225
|
+
base_path: nil
|
227
226
|
```
|
228
227
|
|
229
228
|
`host` and `base_path` are also accepting a `proc` or `lambda`
|
@@ -233,14 +232,14 @@ add_swagger_documentation \
|
|
233
232
|
The path where the API documentation is loaded, default is: `/swagger_doc`.
|
234
233
|
```ruby
|
235
234
|
add_swagger_documentation \
|
236
|
-
mount_path: '/
|
235
|
+
mount_path: '/swagger_doc'
|
237
236
|
```
|
238
237
|
|
239
238
|
#### add_base_path:
|
240
239
|
Add `basePath` key to the documented path keys, default is: `false`.
|
241
240
|
```ruby
|
242
241
|
add_swagger_documentation \
|
243
|
-
add_base_path: true
|
242
|
+
add_base_path: true # only if base_path given
|
244
243
|
```
|
245
244
|
|
246
245
|
#### add_version:
|
@@ -249,7 +248,7 @@ here the version is the API version, specified by `grape` in [`path`](https://gi
|
|
249
248
|
|
250
249
|
```ruby
|
251
250
|
add_swagger_documentation \
|
252
|
-
add_version:
|
251
|
+
add_version: true
|
253
252
|
```
|
254
253
|
|
255
254
|
<a name="doc_version" />
|
@@ -289,9 +288,6 @@ add_swagger_documentation \
|
|
289
288
|
}
|
290
289
|
```
|
291
290
|
|
292
|
-
#### *authorizations*:
|
293
|
-
This value is added to the `authorizations` key in the JSON documentation.
|
294
|
-
|
295
291
|
<a name="models" />
|
296
292
|
#### models:
|
297
293
|
A list of entities to document. Combine with the [grape-entity](https://github.com/ruby-grape/grape-entity) gem.
|
@@ -333,6 +329,8 @@ add_swagger_documentation \
|
|
333
329
|
|
334
330
|
A hash merged into the `info` key of the JSON documentation.
|
335
331
|
|
332
|
+
<!-- #### *authorizations*:
|
333
|
+
This value is added to the `authorizations` key in the JSON documentation. -->
|
336
334
|
|
337
335
|
<!-- #### *api_documentation*:
|
338
336
|
Customize the Swagger API documentation route, typically contains a `desc` field. The default description is "Swagger compatible API description".
|
data/UPGRADING.md
CHANGED
@@ -10,6 +10,22 @@ gem 'grape-swagger'
|
|
10
10
|
gem 'grape-swagger-entity'
|
11
11
|
```
|
12
12
|
|
13
|
+
`add_swagger_documentation` has changed from
|
14
|
+
``` ruby
|
15
|
+
add_swagger_documentation \
|
16
|
+
api_version: '0.0.1'
|
17
|
+
```
|
18
|
+
to
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
add_swagger_documentation \
|
22
|
+
doc_version: '0.0.1'
|
23
|
+
```
|
24
|
+
|
25
|
+
The API version self, would be set by grape, see -> [spec for #403](https://github.com/ruby-grape/grape-swagger/blob/master/spec/issues/403_versions_spec.rb).
|
26
|
+
|
27
|
+
|
28
|
+
|
13
29
|
### Upgrading to >= 0.10.2
|
14
30
|
|
15
31
|
With grape >= 0.12.0, support for `notes` is replaced by passing a block `detail` option specified. For future compatibility, update your code:
|
@@ -32,7 +32,7 @@ module GrapeSwagger
|
|
32
32
|
def parse_multi_type(raw_data_type)
|
33
33
|
case raw_data_type
|
34
34
|
when /\A\[.*\]\z/
|
35
|
-
raw_data_type.gsub(/[
|
35
|
+
raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
|
36
36
|
when Array
|
37
37
|
raw_data_type.first
|
38
38
|
else
|
@@ -33,7 +33,7 @@ module GrapeSwagger
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def move_params_to_new(definition, params)
|
36
|
-
params, nested_params = params.partition { |x| !x[:name].include?('[') }
|
36
|
+
params, nested_params = params.partition { |x| !x[:name].to_s.include?('[') }
|
37
37
|
|
38
38
|
unless params.blank?
|
39
39
|
properties, required = build_properties(params)
|
@@ -44,6 +44,39 @@ module GrapeSwagger
|
|
44
44
|
add_properties_to_definition(definition, nested_properties, []) unless nested_params.blank?
|
45
45
|
end
|
46
46
|
|
47
|
+
def build_properties(params)
|
48
|
+
properties = {}
|
49
|
+
required = []
|
50
|
+
|
51
|
+
prepare_nested_types(params) if should_expose_as_array?(params)
|
52
|
+
|
53
|
+
params.each do |param|
|
54
|
+
name = param[:name].to_sym
|
55
|
+
|
56
|
+
properties[name] = if should_expose_as_array?([param])
|
57
|
+
document_as_array(param)
|
58
|
+
else
|
59
|
+
document_as_property(param)
|
60
|
+
end
|
61
|
+
|
62
|
+
required << name if deletable?(param) && param[:required]
|
63
|
+
end
|
64
|
+
|
65
|
+
[properties, required]
|
66
|
+
end
|
67
|
+
|
68
|
+
def document_as_array(param)
|
69
|
+
{}.tap do |property|
|
70
|
+
property[:type] = 'array'
|
71
|
+
property[:description] = param.delete(:description) unless param[:description].nil?
|
72
|
+
property[:items] = document_as_property(param)[:items]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def document_as_property(param)
|
77
|
+
property_keys.each_with_object({}) { |x, memo| memo[x] = param[x] if param[x].present? }
|
78
|
+
end
|
79
|
+
|
47
80
|
def build_nested_properties(params, properties = {})
|
48
81
|
property = params.bsearch { |x| x[:name].include?('[') }[:name].split('[').first
|
49
82
|
|
@@ -94,41 +127,6 @@ module GrapeSwagger
|
|
94
127
|
definition[:required].push(*value)
|
95
128
|
end
|
96
129
|
|
97
|
-
def build_properties(params)
|
98
|
-
properties = {}
|
99
|
-
required = []
|
100
|
-
|
101
|
-
prepare_nested_types(params) if should_expose_as_array?(params)
|
102
|
-
|
103
|
-
params.each do |param|
|
104
|
-
name = param[:name].to_sym
|
105
|
-
properties[name] = {}
|
106
|
-
|
107
|
-
if should_expose_as_array?([param])
|
108
|
-
prepare_nested_types([param])
|
109
|
-
|
110
|
-
properties[name][:type] = 'array'
|
111
|
-
properties[name][:items] = {}
|
112
|
-
properties[name][:items].tap do |x|
|
113
|
-
property_keys.each do |attribute|
|
114
|
-
x[attribute] = param[attribute] unless param[attribute].nil?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
else
|
118
|
-
|
119
|
-
properties[name].tap do |x|
|
120
|
-
property_keys.each do |attribute|
|
121
|
-
x[attribute] = param[attribute] unless param[attribute].nil?
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
required << name if deletable?(param) && param[:required]
|
127
|
-
end
|
128
|
-
|
129
|
-
[properties, required]
|
130
|
-
end
|
131
|
-
|
132
130
|
def build_body_parameter(reference, name)
|
133
131
|
{}.tap do |x|
|
134
132
|
x[:name] = name
|
@@ -3,11 +3,17 @@ module GrapeSwagger
|
|
3
3
|
class OperationId
|
4
4
|
class << self
|
5
5
|
def build(route, path = nil)
|
6
|
-
|
6
|
+
if route.options[:nickname]
|
7
|
+
operation_id = route.options[:nickname]
|
8
|
+
else
|
9
|
+
verb = route.request_method.to_s.downcase
|
7
10
|
|
8
|
-
|
11
|
+
operation = manipulate(path) unless path.nil?
|
9
12
|
|
10
|
-
|
13
|
+
operation_id = "#{verb}#{operation}"
|
14
|
+
end
|
15
|
+
|
16
|
+
operation_id
|
11
17
|
end
|
12
18
|
|
13
19
|
def manipulate(path)
|
@@ -168,11 +168,9 @@ module Grape
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def response_object(route, markdown)
|
171
|
-
|
172
|
-
|
173
|
-
default_code[:message] = route.description || default_code[:message].sub('{item}', @item)
|
171
|
+
codes = (route.http_codes || route.options[:failure] || [])
|
172
|
+
codes = apply_defaults(route, codes) if route.options[:ignore_defaults].nil?
|
174
173
|
|
175
|
-
codes = [default_code] + (route.http_codes || route.options[:failure] || [])
|
176
174
|
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2] } : x }
|
177
175
|
|
178
176
|
codes.each_with_object({}) do |value, memo|
|
@@ -200,6 +198,13 @@ module Grape
|
|
200
198
|
end
|
201
199
|
end
|
202
200
|
|
201
|
+
def apply_defaults(route, codes)
|
202
|
+
default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
|
203
|
+
default_code[:model] = @entity if @entity
|
204
|
+
default_code[:message] = route.description || default_code[:message].sub('{item}', @item)
|
205
|
+
[default_code] + codes
|
206
|
+
end
|
207
|
+
|
203
208
|
def tag_object(route)
|
204
209
|
Array(route.path.split('{')[0].split('/').reject(&:empty?).delete_if { |i| ((i == route.prefix.to_s) || (i == route.version)) }.first)
|
205
210
|
end
|
@@ -231,9 +236,11 @@ module Grape
|
|
231
236
|
array_key = nil
|
232
237
|
params.select { |param| public_parameter?(param) }.each_with_object({}) do |param, memo|
|
233
238
|
name, options = *param
|
234
|
-
|
239
|
+
param_type = options[:type]
|
240
|
+
param_type = param_type.to_s unless param_type.nil?
|
241
|
+
array_key = name.to_s if param_type_is_array?(param_type)
|
235
242
|
options[:is_array] = true if array_key && name.start_with?(array_key)
|
236
|
-
memo[
|
243
|
+
memo[name] = options unless %w(Hash Array).include?(param_type) && !options.key?(:documentation)
|
237
244
|
end
|
238
245
|
end
|
239
246
|
|
@@ -16,31 +16,12 @@ describe 'describing versions' do
|
|
16
16
|
|
17
17
|
subject do
|
18
18
|
get '/swagger_doc'
|
19
|
-
JSON.parse(last_response.body
|
19
|
+
JSON.parse(last_response.body)
|
20
20
|
end
|
21
21
|
|
22
22
|
specify do
|
23
|
-
expect(subject).to eql
|
24
|
-
|
25
|
-
swagger: '2.0',
|
26
|
-
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
27
|
-
host: 'example.org',
|
28
|
-
tags: [{ name: 'nothings', description: 'Operations about nothings' }],
|
29
|
-
paths: {
|
30
|
-
:'/nothings' => {
|
31
|
-
get: {
|
32
|
-
summary: 'no versions given',
|
33
|
-
description: 'no versions given',
|
34
|
-
produces: ['application/json'],
|
35
|
-
responses: {
|
36
|
-
:'200' => { description: 'no versions given' }
|
37
|
-
},
|
38
|
-
tags: ['nothings'],
|
39
|
-
operationId: 'getNothings'
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
)
|
23
|
+
expect(subject['info']['version']).to eql '0.0.1'
|
24
|
+
expect(subject['paths'].keys.first).to eql '/nothings'
|
44
25
|
end
|
45
26
|
end
|
46
27
|
|
@@ -59,31 +40,12 @@ describe 'describing versions' do
|
|
59
40
|
|
60
41
|
subject do
|
61
42
|
get '/v2/swagger_doc'
|
62
|
-
JSON.parse(last_response.body
|
43
|
+
JSON.parse(last_response.body)
|
63
44
|
end
|
64
45
|
|
65
46
|
specify do
|
66
|
-
expect(subject).to eql
|
67
|
-
|
68
|
-
swagger: '2.0',
|
69
|
-
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
70
|
-
host: 'example.org',
|
71
|
-
tags: [{ name: 'api_version', description: 'Operations about api_versions' }],
|
72
|
-
paths: {
|
73
|
-
:'/v2/api_version' => {
|
74
|
-
get: {
|
75
|
-
summary: 'api versions given',
|
76
|
-
description: 'api versions given',
|
77
|
-
produces: ['application/json'],
|
78
|
-
responses: {
|
79
|
-
:'200' => { description: 'api versions given' }
|
80
|
-
},
|
81
|
-
tags: ['api_version'],
|
82
|
-
operationId: 'getV2ApiVersion'
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
)
|
47
|
+
expect(subject['info']['version']).to eql '0.0.1'
|
48
|
+
expect(subject['paths'].keys.first).to eql '/v2/api_version'
|
87
49
|
end
|
88
50
|
end
|
89
51
|
|
@@ -95,80 +57,67 @@ describe 'describing versions' do
|
|
95
57
|
{ message: 'hello world …' }
|
96
58
|
end
|
97
59
|
|
98
|
-
add_swagger_documentation doc_version: '0.
|
60
|
+
add_swagger_documentation doc_version: '0.1'
|
99
61
|
end
|
100
62
|
end
|
101
63
|
|
102
64
|
subject do
|
103
65
|
get '/swagger_doc'
|
104
|
-
JSON.parse(last_response.body
|
66
|
+
JSON.parse(last_response.body)
|
105
67
|
end
|
106
68
|
|
107
69
|
specify do
|
108
|
-
expect(subject).to eql
|
109
|
-
|
110
|
-
swagger: '2.0',
|
111
|
-
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
112
|
-
host: 'example.org',
|
113
|
-
tags: [{ name: 'doc_version', description: 'Operations about doc_versions' }],
|
114
|
-
paths: {
|
115
|
-
:'/doc_version' => {
|
116
|
-
get: {
|
117
|
-
summary: 'doc versions given',
|
118
|
-
description: 'doc versions given',
|
119
|
-
produces: ['application/json'],
|
120
|
-
responses: {
|
121
|
-
:'200' => { description: 'doc versions given' }
|
122
|
-
},
|
123
|
-
tags: ['doc_version'],
|
124
|
-
operationId: 'getDocVersion'
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
)
|
70
|
+
expect(subject['info']['version']).to eql '0.1'
|
71
|
+
expect(subject['paths'].keys.first).to eql '/doc_version'
|
129
72
|
end
|
130
73
|
end
|
131
74
|
|
132
75
|
describe 'both versions given' do
|
133
76
|
def app
|
134
77
|
Class.new(Grape::API) do
|
135
|
-
version :
|
78
|
+
version :v3, using: :path
|
136
79
|
desc 'both versions given'
|
137
80
|
get '/both_versions' do
|
138
81
|
{ message: 'hello world …' }
|
139
82
|
end
|
140
83
|
|
141
|
-
add_swagger_documentation doc_version: '0.
|
84
|
+
add_swagger_documentation doc_version: '0.2'
|
142
85
|
end
|
143
86
|
end
|
144
87
|
|
145
88
|
subject do
|
146
|
-
get '/
|
147
|
-
JSON.parse(last_response.body
|
89
|
+
get '/v3/swagger_doc'
|
90
|
+
JSON.parse(last_response.body)
|
91
|
+
end
|
92
|
+
|
93
|
+
specify do
|
94
|
+
expect(subject['info']['version']).to eql '0.2'
|
95
|
+
expect(subject['paths'].keys.first).to eql '/v3/both_versions'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'try to override grape given version' do
|
100
|
+
def app
|
101
|
+
Class.new(Grape::API) do
|
102
|
+
version :v4, using: :path
|
103
|
+
desc 'overriding grape given version?'
|
104
|
+
get '/grape_version' do
|
105
|
+
{ message: 'hello world …' }
|
106
|
+
end
|
107
|
+
|
108
|
+
add_swagger_documentation doc_version: '0.0.3',
|
109
|
+
version: 'v5'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
subject do
|
114
|
+
get '/v4/swagger_doc'
|
115
|
+
JSON.parse(last_response.body)
|
148
116
|
end
|
149
117
|
|
150
118
|
specify do
|
151
|
-
expect(subject).to eql
|
152
|
-
|
153
|
-
swagger: '2.0',
|
154
|
-
produces: ['application/xml', 'application/json', 'application/octet-stream', 'text/plain'],
|
155
|
-
host: 'example.org',
|
156
|
-
tags: [{ name: 'both_versions', description: 'Operations about both_versions' }],
|
157
|
-
paths: {
|
158
|
-
:'/v2/both_versions' => {
|
159
|
-
get: {
|
160
|
-
summary: 'both versions given',
|
161
|
-
description: 'both versions given',
|
162
|
-
produces: ['application/json'],
|
163
|
-
responses: {
|
164
|
-
:'200' => { description: 'both versions given' }
|
165
|
-
},
|
166
|
-
tags: ['both_versions'],
|
167
|
-
operationId: 'getV2BothVersions'
|
168
|
-
}
|
169
|
-
}
|
170
|
-
}
|
171
|
-
)
|
119
|
+
expect(subject['info']['version']).to eql '0.0.3'
|
120
|
+
expect(subject['paths'].keys.first).to eql '/v4/grape_version'
|
172
121
|
end
|
173
122
|
end
|
174
123
|
end
|
data/spec/lib/data_type_spec.rb
CHANGED
@@ -24,6 +24,12 @@ describe GrapeSwagger::DocMethods::DataType do
|
|
24
24
|
it { expect(subject).to eql 'string' }
|
25
25
|
end
|
26
26
|
|
27
|
+
describe 'Multi types in a string stating with A' do
|
28
|
+
let(:value) { { type: '[Apple, Orange]' } }
|
29
|
+
|
30
|
+
it { expect(subject).to eql 'Apple' }
|
31
|
+
end
|
32
|
+
|
27
33
|
describe 'Multi types in array' do
|
28
34
|
let(:value) { { type: [String, Integer] } }
|
29
35
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'body parameter definitions' do
|
4
|
+
before :all do
|
5
|
+
module TheBodyApi
|
6
|
+
class Endpoint < Grape::API
|
7
|
+
resource :endpoint do
|
8
|
+
desc 'The endpoint' do
|
9
|
+
headers XAuthToken: {
|
10
|
+
description: 'Valdates your identity',
|
11
|
+
required: true
|
12
|
+
}
|
13
|
+
params body_param: { type: 'String', desc: 'param', documentation: { in: 'body' } },
|
14
|
+
body_type_as_const_param: { type: String, desc: 'string_param', documentation: { in: 'body' } }
|
15
|
+
end
|
16
|
+
|
17
|
+
post do
|
18
|
+
{ 'declared_params' => declared(params) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
add_swagger_documentation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def app
|
28
|
+
TheBodyApi::Endpoint
|
29
|
+
end
|
30
|
+
|
31
|
+
subject do
|
32
|
+
get '/swagger_doc'
|
33
|
+
JSON.parse(last_response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'a definition is generated for the endpoints parameters defined within the desc block' do
|
37
|
+
specify do
|
38
|
+
expect(subject['definitions']['postEndpoint']['properties']).to eql(
|
39
|
+
'body_param' => { 'type' => 'string', 'description' => 'param' },
|
40
|
+
'body_type_as_const_param' => { 'type' => 'string', 'description' => 'string_param' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'swagger spec v2.0' do
|
4
|
+
include_context "#{MODEL_PARSER} swagger example"
|
5
|
+
|
6
|
+
def app
|
7
|
+
Class.new(Grape::API) do
|
8
|
+
format :json
|
9
|
+
|
10
|
+
desc 'This creates Thing after a delay',
|
11
|
+
success: Entities::Something
|
12
|
+
params do
|
13
|
+
requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
|
14
|
+
requires :links, type: Array, documentation: { type: 'link', is_array: true }
|
15
|
+
end
|
16
|
+
post '/delay_thing', http_codes: [{ code: 202, message: 'OK' }], ignore_defaults: true do
|
17
|
+
status 202
|
18
|
+
end
|
19
|
+
|
20
|
+
version 'v3', using: :path
|
21
|
+
add_swagger_documentation api_version: 'v1',
|
22
|
+
base_path: '/api',
|
23
|
+
info: {
|
24
|
+
title: 'The API title to be displayed on the API homepage.',
|
25
|
+
description: 'A description of the API.',
|
26
|
+
contact_name: 'Contact name',
|
27
|
+
contact_email: 'Contact@email.com',
|
28
|
+
contact_url: 'Contact URL',
|
29
|
+
license: 'The name of the license.',
|
30
|
+
license_url: 'www.The-URL-of-the-license.org',
|
31
|
+
terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
before do
|
37
|
+
get '/v3/swagger_doc'
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:json) { JSON.parse(last_response.body) }
|
41
|
+
|
42
|
+
it 'only returns one response if ignore_defaults is specified' do
|
43
|
+
expect(json['paths']['/delay_thing']['post']['responses']).to eq('202' => { 'description' => 'OK' })
|
44
|
+
expect(json['paths']['/delay_thing']['post']['responses'].keys).not_to include '201'
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'a nicknamed mounted api' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
desc 'Show this endpoint', nickname: 'simple'
|
7
|
+
get '/simple' do
|
8
|
+
{ foo: 'bar' }
|
9
|
+
end
|
10
|
+
|
11
|
+
add_swagger_documentation format: :json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
subject do
|
16
|
+
get '/swagger_doc.json'
|
17
|
+
JSON.parse(last_response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'uses the nickname as the operationId' do
|
21
|
+
expect(subject['paths']['/simple']['get']['operationId']).to eql('simple')
|
22
|
+
end
|
23
|
+
end
|
@@ -128,8 +128,10 @@ describe 'Group Params as Array' do
|
|
128
128
|
expect(subject['definitions']['postObjectAndArray']['type']).to eql 'object'
|
129
129
|
expect(subject['definitions']['postObjectAndArray']['properties']).to eql(
|
130
130
|
'array_of_string' => {
|
131
|
-
'type' => 'array',
|
132
|
-
|
131
|
+
'type' => 'array',
|
132
|
+
'description' => 'array of strings',
|
133
|
+
'items' => {
|
134
|
+
'type' => 'string'
|
133
135
|
}
|
134
136
|
},
|
135
137
|
'integer_value' => {
|
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.23.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-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -222,6 +222,7 @@ files:
|
|
222
222
|
- ".travis.yml"
|
223
223
|
- CHANGELOG.md
|
224
224
|
- CONTRIBUTING.md
|
225
|
+
- Dangerfile
|
225
226
|
- Gemfile
|
226
227
|
- LICENSE.txt
|
227
228
|
- README.md
|
@@ -276,6 +277,7 @@ files:
|
|
276
277
|
- spec/support/model_parsers/representable_parser.rb
|
277
278
|
- spec/support/namespace_tags.rb
|
278
279
|
- spec/support/the_paths_definitions.rb
|
280
|
+
- spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
|
279
281
|
- spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
|
280
282
|
- spec/swagger_v2/api_swagger_v2_detail_spec.rb
|
281
283
|
- spec/swagger_v2/api_swagger_v2_extensions_spec.rb
|
@@ -285,6 +287,7 @@ files:
|
|
285
287
|
- spec/swagger_v2/api_swagger_v2_headers_spec.rb
|
286
288
|
- spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb
|
287
289
|
- spec/swagger_v2/api_swagger_v2_hide_param_spec.rb
|
290
|
+
- spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb
|
288
291
|
- spec/swagger_v2/api_swagger_v2_mounted_spec.rb
|
289
292
|
- spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb
|
290
293
|
- spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb
|
@@ -307,6 +310,7 @@ files:
|
|
307
310
|
- spec/swagger_v2/namespace_tags_prefix_spec.rb
|
308
311
|
- spec/swagger_v2/namespace_tags_spec.rb
|
309
312
|
- spec/swagger_v2/namespaced_api_spec.rb
|
313
|
+
- spec/swagger_v2/nicknamed_api_spec.rb
|
310
314
|
- spec/swagger_v2/param_multi_type_spec.rb
|
311
315
|
- spec/swagger_v2/param_type_spec.rb
|
312
316
|
- spec/swagger_v2/param_values_spec.rb
|
@@ -363,6 +367,7 @@ test_files:
|
|
363
367
|
- spec/support/model_parsers/representable_parser.rb
|
364
368
|
- spec/support/namespace_tags.rb
|
365
369
|
- spec/support/the_paths_definitions.rb
|
370
|
+
- spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
|
366
371
|
- spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
|
367
372
|
- spec/swagger_v2/api_swagger_v2_detail_spec.rb
|
368
373
|
- spec/swagger_v2/api_swagger_v2_extensions_spec.rb
|
@@ -372,6 +377,7 @@ test_files:
|
|
372
377
|
- spec/swagger_v2/api_swagger_v2_headers_spec.rb
|
373
378
|
- spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb
|
374
379
|
- spec/swagger_v2/api_swagger_v2_hide_param_spec.rb
|
380
|
+
- spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb
|
375
381
|
- spec/swagger_v2/api_swagger_v2_mounted_spec.rb
|
376
382
|
- spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb
|
377
383
|
- spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb
|
@@ -394,6 +400,7 @@ test_files:
|
|
394
400
|
- spec/swagger_v2/namespace_tags_prefix_spec.rb
|
395
401
|
- spec/swagger_v2/namespace_tags_spec.rb
|
396
402
|
- spec/swagger_v2/namespaced_api_spec.rb
|
403
|
+
- spec/swagger_v2/nicknamed_api_spec.rb
|
397
404
|
- spec/swagger_v2/param_multi_type_spec.rb
|
398
405
|
- spec/swagger_v2/param_type_spec.rb
|
399
406
|
- spec/swagger_v2/param_values_spec.rb
|