grape-swagger 0.25.2 → 0.25.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +2 -2
- data/.travis.yml +13 -13
- data/CHANGELOG.md +14 -2
- data/Gemfile +24 -11
- data/UPGRADING.md +24 -2
- data/grape-swagger.gemspec +0 -14
- data/lib/grape-swagger/doc_methods.rb +0 -1
- data/lib/grape-swagger/doc_methods/data_type.rb +10 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +4 -3
- data/lib/grape-swagger/doc_methods/operation_id.rb +1 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +7 -7
- data/lib/grape-swagger/doc_methods/path_string.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +21 -7
- data/lib/grape-swagger/markdown/redcarpet_adapter.rb +5 -2
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/427_entity_as_string_spec.rb +0 -2
- data/spec/issues/430_entity_definitions_spec.rb +0 -2
- data/spec/issues/539_array_post_body_spec.rb +0 -2
- data/spec/issues/542_array_of_type_in_post_body_spec.rb +0 -2
- data/spec/issues/553_align_array_put_post_params_spec.rb +142 -0
- data/spec/lib/data_type_spec.rb +15 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/swagger_v2/operation_id_api_spec.rb +25 -0
- metadata +6 -184
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ff792817a48d392666a4e84933495fa6e68b66e
|
4
|
+
data.tar.gz: 9368606ffd2008f4491145cf3e3803579abde016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84b8254773002e828481160615dc3176121d3f440de4937949ca086d53129aae064d72ad4ef5810c23789e3918228ccc083f6794eddb918ccebdc576224a8a30
|
7
|
+
data.tar.gz: 5960d2a66afffdb1f37a625d553e974aa782be32b7166b3199ac89e7b6dd347d8c6f97e431d81faf328482763a47ce39da5528f503b9f1c1de090eac9b96a246
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -18,7 +18,7 @@ Metrics/BlockLength:
|
|
18
18
|
# Offense count: 3
|
19
19
|
# Configuration parameters: CountComments.
|
20
20
|
Metrics/ClassLength:
|
21
|
-
Max:
|
21
|
+
Max: 265
|
22
22
|
|
23
23
|
# Offense count: 10
|
24
24
|
Metrics/CyclomaticComplexity:
|
@@ -28,7 +28,7 @@ Metrics/CyclomaticComplexity:
|
|
28
28
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
29
29
|
# URISchemes: http, https
|
30
30
|
Metrics/LineLength:
|
31
|
-
Max:
|
31
|
+
Max: 120
|
32
32
|
|
33
33
|
# Offense count: 34
|
34
34
|
# Configuration parameters: CountComments.
|
data/.travis.yml
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
sudo: false
|
4
|
+
before_install:
|
5
|
+
- gem install bundler
|
4
6
|
|
5
7
|
matrix:
|
6
8
|
include:
|
7
|
-
- rvm: 2.3.
|
9
|
+
- rvm: 2.3.3
|
8
10
|
script:
|
9
11
|
- bundle exec danger
|
10
|
-
- rvm: 2.3.
|
12
|
+
- rvm: 2.3.3
|
11
13
|
env: MODEL_PARSER=grape-swagger-entity
|
12
|
-
- rvm: 2.3.
|
14
|
+
- rvm: 2.3.3
|
13
15
|
env: MODEL_PARSER=grape-swagger-representable
|
14
|
-
- rvm: 2.3.
|
16
|
+
- rvm: 2.3.3
|
15
17
|
env: GRAPE_VERSION=0.14.0
|
16
|
-
- rvm: 2.3.
|
18
|
+
- rvm: 2.3.3
|
17
19
|
env: GRAPE_VERSION=0.15.0
|
18
|
-
- rvm: 2.3.
|
20
|
+
- rvm: 2.3.3
|
19
21
|
env: GRAPE_VERSION=0.16.2
|
20
|
-
- rvm: 2.3.
|
22
|
+
- rvm: 2.3.3
|
21
23
|
env: GRAPE_VERSION=0.17.0
|
22
|
-
- rvm: 2.3.
|
24
|
+
- rvm: 2.3.3
|
23
25
|
env: GRAPE_VERSION=0.18.0
|
24
|
-
- rvm: 2.3.
|
26
|
+
- rvm: 2.3.3
|
25
27
|
env: GRAPE_VERSION=HEAD
|
26
|
-
- rvm: 2.3.0
|
27
28
|
- rvm: 2.2
|
28
|
-
- rvm: 2.1
|
29
29
|
- rvm: ruby-head
|
30
|
-
- rvm: jruby-9.1.
|
30
|
+
- rvm: jruby-9.1.6.0
|
31
31
|
- rvm: jruby-head
|
32
32
|
- rvm: rbx-2
|
33
33
|
allow_failures:
|
34
34
|
- rvm: ruby-head
|
35
|
-
- rvm: jruby-9.1.
|
35
|
+
- rvm: jruby-9.1.6.0
|
36
36
|
- rvm: jruby-head
|
37
37
|
- rvm: rbx-2
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,18 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 0.25.3 (December 18, 2016)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#554](https://github.com/ruby-grape/grape-swagger/pull/554): Updates travis.yml to align with grape - [@LeFnord](https://github.com/LeFnord).
|
16
|
+
|
17
|
+
#### Fixes
|
18
|
+
|
19
|
+
* [#546](https://github.com/ruby-grape/grape-swagger/pull/546): Move development dependencies to Gemfile - [@olleolleolle](https://github.com/olleolleolle).
|
20
|
+
* [#547](https://github.com/ruby-grape/grape-swagger/pull/547): Use entity_name event if type come from a string - [@frodrigo](https://github.com/frodrigo).
|
21
|
+
* [#548](https://github.com/ruby-grape/grape-swagger/pull/548): Remove dots from operation id - [@frodrigo](https://github.com/frodrigo).
|
22
|
+
* [#553](https://github.com/ruby-grape/grape-swagger/pull/553): Align array params for post, put request - addition to [#540](https://github.com/ruby-grape/grape-swagger/pull/540) - [@LeFnord](https://github.com/LeFnord).
|
11
23
|
|
12
24
|
### 0.25.2 (November 30, 2016)
|
13
25
|
|
@@ -34,7 +46,7 @@
|
|
34
46
|
* [#524](https://github.com/ruby-grape/grape-swagger/pull/524): Use route tags for global tag set - [@LeFnord](https://github.com/LeFnord).
|
35
47
|
* [#523](https://github.com/ruby-grape/grape-swagger/pull/523): Allow specifying custom tags at the route level - [@jordanfbrown](https://github.com/jordanfbrown).
|
36
48
|
* [#520](https://github.com/ruby-grape/grape-swagger/pull/520): Response model can have required attributes - [@WojciechKo](https://github.com/WojciechKo).
|
37
|
-
* [#510](https://github.com/ruby-grape/grape-swagger/pull/510): Use 'token_owner' instead of 'oauth_token' on Swagger UI endpoint authorization
|
49
|
+
* [#510](https://github.com/ruby-grape/grape-swagger/pull/510): Use 'token_owner' instead of 'oauth_token' on Swagger UI endpoint authorization - [@texpert](https://github.com/texpert).
|
38
50
|
|
39
51
|
#### Fixes
|
40
52
|
|
@@ -50,7 +62,7 @@
|
|
50
62
|
* [#502](https://github.com/ruby-grape/grape-swagger/pull/502): Adds specs for rake tasks - [@LeFnord](https://github.com/LeFnord).
|
51
63
|
* [#501](https://github.com/ruby-grape/grape-swagger/pull/501): Adds getting of a specified resource for Rake Tasks - [@LeFnord](https://github.com/LeFnord).
|
52
64
|
* [#500](https://github.com/ruby-grape/grape-swagger/pull/500): Adds Rake tasks to get and validate OAPI/Swagger documentation - [@LeFnord](https://github.com/LeFnord).
|
53
|
-
* [#493](https://github.com/ruby-grape/grape-swagger/pull/493): Swagger UI endpoint authorization
|
65
|
+
* [#493](https://github.com/ruby-grape/grape-swagger/pull/493): Swagger UI endpoint authorization - [@texpert](https://github.com/texpert).
|
54
66
|
* [#492](https://github.com/ruby-grape/grape/pull/492): Define security requirements on endpoint methods - [@tomregelink](https://github.com/tomregelink).
|
55
67
|
* [#497](https://github.com/ruby-grape/grape-swagger/pull/497): Use ruby-grape-danger in Dangerfile - [@dblock](https://github.com/dblock).
|
56
68
|
|
data/Gemfile
CHANGED
@@ -1,23 +1,36 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
+
ruby RUBY_VERSION
|
4
|
+
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
case version = ENV['GRAPE_VERSION'] || '~> 0.18'
|
6
|
-
when 'HEAD'
|
7
|
-
|
8
|
-
else
|
9
|
-
|
10
|
-
end
|
7
|
+
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.18'
|
8
|
+
when 'HEAD'
|
9
|
+
{ github: 'ruby-grape/grape' }
|
10
|
+
else
|
11
|
+
version
|
12
|
+
end
|
11
13
|
|
12
14
|
gem ENV['MODEL_PARSER'] if ENV.key?('MODEL_PARSER')
|
13
15
|
|
14
|
-
|
15
|
-
gem '
|
16
|
-
gem '
|
16
|
+
group :development, :test do
|
17
|
+
gem 'bundler'
|
18
|
+
gem 'kramdown'
|
19
|
+
gem 'pry', platforms: [:mri]
|
20
|
+
gem 'pry-byebug', platforms: [:mri]
|
21
|
+
gem 'rack'
|
22
|
+
gem 'rack-cors'
|
23
|
+
gem 'rack-test'
|
24
|
+
gem 'rake'
|
25
|
+
gem 'rdoc'
|
26
|
+
gem 'redcarpet', platforms: [:mri]
|
27
|
+
gem 'rouge', platforms: [:mri]
|
28
|
+
gem 'rspec', '~> 3.0'
|
29
|
+
gem 'rubocop', '~> 0.40'
|
30
|
+
gem 'shoulda'
|
17
31
|
end
|
18
|
-
|
19
32
|
group :test do
|
20
|
-
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
21
33
|
gem 'grape-entity'
|
22
34
|
gem 'grape-swagger-entity'
|
35
|
+
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
23
36
|
end
|
data/UPGRADING.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
Upgrading Grape-swagger
|
2
|
-
|
1
|
+
## Upgrading Grape-swagger
|
2
|
+
|
3
|
+
### Upgrading to >= 0.25.2
|
4
|
+
|
5
|
+
Avoids ambiguous documentation of array parameters,
|
6
|
+
by enforcing correct usage of both possibilities:
|
7
|
+
|
8
|
+
1. Array of primitive types
|
9
|
+
```ruby
|
10
|
+
params do
|
11
|
+
requires :foo, type: Array[String]
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
2. Array of objects
|
16
|
+
```ruby
|
17
|
+
params do
|
18
|
+
requires :put_params, type: Array do
|
19
|
+
requires :op, type: String
|
20
|
+
requires :path, type: String
|
21
|
+
requires :value, type: String
|
22
|
+
end
|
23
|
+
end
|
24
|
+
```
|
3
25
|
|
4
26
|
### Upgrading to >= 0.25.0
|
5
27
|
|
data/grape-swagger.gemspec
CHANGED
@@ -13,20 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.add_runtime_dependency 'grape', '>= 0.12.0'
|
15
15
|
|
16
|
-
s.add_development_dependency 'rake'
|
17
|
-
s.add_development_dependency 'shoulda'
|
18
|
-
s.add_development_dependency 'rdoc'
|
19
|
-
s.add_development_dependency 'rspec', '~> 3.0'
|
20
|
-
s.add_development_dependency 'bundler'
|
21
|
-
s.add_development_dependency 'rack-test'
|
22
|
-
s.add_development_dependency 'rack-cors'
|
23
|
-
s.add_development_dependency 'rubocop', '~> 0.40'
|
24
|
-
s.add_development_dependency 'kramdown'
|
25
|
-
s.add_development_dependency 'redcarpet' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
|
26
|
-
s.add_development_dependency 'rouge' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
|
27
|
-
s.add_development_dependency 'pry' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
|
28
|
-
s.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
|
29
|
-
|
30
16
|
s.files = `git ls-files`.split("\n")
|
31
17
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
32
18
|
s.require_paths = ['lib']
|
@@ -32,7 +32,12 @@ 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(/[\[\s+\]]/, '').split(',').first
|
35
|
+
type_as_string = raw_data_type.gsub(/[\[\s+\]]/, '').split(',').first
|
36
|
+
begin
|
37
|
+
Object.const_get(type_as_string)
|
38
|
+
rescue NameError
|
39
|
+
type_as_string
|
40
|
+
end
|
36
41
|
when Array
|
37
42
|
raw_data_type.first
|
38
43
|
else
|
@@ -71,6 +76,10 @@ module GrapeSwagger
|
|
71
76
|
def mapping(value)
|
72
77
|
PRIMITIVE_MAPPINGS[value] || 'string'
|
73
78
|
end
|
79
|
+
|
80
|
+
def collections
|
81
|
+
%w(csv ssv tsv pipes multi)
|
82
|
+
end
|
74
83
|
end
|
75
84
|
|
76
85
|
PRIMITIVE_MAPPINGS = {
|
@@ -12,9 +12,10 @@ module GrapeSwagger
|
|
12
12
|
@definitions = definitions
|
13
13
|
unify!(params)
|
14
14
|
|
15
|
-
return correct_array_param(params) if should_correct_array?(params)
|
16
|
-
|
17
15
|
params_to_move = movable_params(params)
|
16
|
+
|
17
|
+
return (params + correct_array_param(params_to_move)) if should_correct_array?(params_to_move)
|
18
|
+
|
18
19
|
params << parent_definition_of_params(params_to_move, route)
|
19
20
|
|
20
21
|
params
|
@@ -33,7 +34,7 @@ module GrapeSwagger
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def parent_definition_of_params(params, route)
|
36
|
-
definition_name =
|
37
|
+
definition_name = OperationId.manipulate(parse_model(route.path))
|
37
38
|
referenced_definition = build_definition(definition_name, params, route.request_method.downcase)
|
38
39
|
definition = @definitions[referenced_definition]
|
39
40
|
|
@@ -20,6 +20,7 @@ module GrapeSwagger
|
|
20
20
|
operation = path.split('/').map(&:capitalize).join
|
21
21
|
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
|
22
22
|
operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
|
23
|
+
operation.gsub!(/\.(\w)/, &:upcase).delete!('.') if operation.include?('.')
|
23
24
|
if path.include?('{')
|
24
25
|
operation.gsub!(/\{(\w)/, &:upcase)
|
25
26
|
operation.delete!('{').delete!('}')
|
@@ -8,7 +8,7 @@ module GrapeSwagger
|
|
8
8
|
|
9
9
|
additional_documentation = settings.fetch(:documentation, {})
|
10
10
|
settings.merge!(additional_documentation)
|
11
|
-
data_type =
|
11
|
+
data_type = DataType.call(settings)
|
12
12
|
|
13
13
|
value_type = settings.merge(data_type: data_type, path: path, param_name: param, method: method)
|
14
14
|
|
@@ -52,8 +52,8 @@ module GrapeSwagger
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def document_type_and_format(data_type)
|
55
|
-
if
|
56
|
-
data =
|
55
|
+
if DataType.primitive?(data_type)
|
56
|
+
data = DataType.mapping(data_type)
|
57
57
|
@parsed_param[:type], @parsed_param[:format] = data
|
58
58
|
else
|
59
59
|
@parsed_param[:type] = data_type
|
@@ -64,7 +64,7 @@ module GrapeSwagger
|
|
64
64
|
if value_type[:documentation].present?
|
65
65
|
param_type = value_type[:documentation][:param_type]
|
66
66
|
doc_type = value_type[:documentation][:type]
|
67
|
-
type =
|
67
|
+
type = DataType.mapping(doc_type) if doc_type && !DataType.request_primitive?(doc_type)
|
68
68
|
collection_format = value_type[:documentation][:collectionFormat]
|
69
69
|
end
|
70
70
|
|
@@ -74,14 +74,14 @@ module GrapeSwagger
|
|
74
74
|
if definitions[value_type[:data_type]]
|
75
75
|
array_items['$ref'] = "#/definitions/#{@parsed_param[:type]}"
|
76
76
|
else
|
77
|
-
array_items[:type] = type || @parsed_param[:type]
|
77
|
+
array_items[:type] = type || @parsed_param[:type] == 'array' ? 'string' : @parsed_param[:type]
|
78
78
|
end
|
79
79
|
array_items[:format] = @parsed_param.delete(:format) if @parsed_param[:format]
|
80
80
|
|
81
81
|
@parsed_param[:in] = param_type || 'formData'
|
82
82
|
@parsed_param[:items] = array_items
|
83
83
|
@parsed_param[:type] = 'array'
|
84
|
-
@parsed_param[:collectionFormat] = collection_format if
|
84
|
+
@parsed_param[:collectionFormat] = collection_format if DataType.collections.include?(collection_format)
|
85
85
|
end
|
86
86
|
|
87
87
|
def param_type(value_type)
|
@@ -91,7 +91,7 @@ module GrapeSwagger
|
|
91
91
|
elsif param_type
|
92
92
|
param_type
|
93
93
|
elsif %w(POST PUT PATCH).include?(value_type[:method])
|
94
|
-
|
94
|
+
DataType.request_primitive?(value_type[:data_type]) ? 'formData' : 'body'
|
95
95
|
else
|
96
96
|
'query'
|
97
97
|
end
|
@@ -20,7 +20,7 @@ module GrapeSwagger
|
|
20
20
|
path.sub!('/{version}', '')
|
21
21
|
end
|
22
22
|
|
23
|
-
path = "#{
|
23
|
+
path = "#{OptionalObject.build(:base_path, options)}#{path}" if options[:add_base_path]
|
24
24
|
|
25
25
|
[item, path.start_with?('/') ? path : "/#{path}"]
|
26
26
|
end
|
@@ -9,7 +9,9 @@ module Grape
|
|
9
9
|
if content_types.empty?
|
10
10
|
formats = [target_class.format, target_class.default_format].compact.uniq
|
11
11
|
formats = Grape::Formatter::Base.formatters({}).keys if formats.empty?
|
12
|
-
content_types = Grape::ContentTypes::CONTENT_TYPES.select
|
12
|
+
content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type|
|
13
|
+
formats.include? content_type
|
14
|
+
end.values
|
13
15
|
end
|
14
16
|
|
15
17
|
content_types.uniq
|
@@ -151,7 +153,9 @@ module Grape
|
|
151
153
|
|
152
154
|
def consumes_object(route, format)
|
153
155
|
method = route.request_method.downcase.to_sym
|
154
|
-
|
156
|
+
if route.settings[:description] && route.settings[:description][:consumes]
|
157
|
+
format = route.settings[:description][:consumes]
|
158
|
+
end
|
155
159
|
mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format) if [:post, :put].include?(method)
|
156
160
|
|
157
161
|
mime_types
|
@@ -199,10 +203,11 @@ module Grape
|
|
199
203
|
|
200
204
|
@definitions[response_model][:description] = description_object(route, markdown)
|
201
205
|
# TODO: proof that the definition exist, if model isn't specified
|
206
|
+
reference = { '$ref' => "#/definitions/#{response_model}" }
|
202
207
|
memo[value[:code]][:schema] = if route.options[:is_array]
|
203
|
-
{ 'type' => 'array', 'items' =>
|
208
|
+
{ 'type' => 'array', 'items' => reference }
|
204
209
|
else
|
205
|
-
|
210
|
+
reference
|
206
211
|
end
|
207
212
|
end
|
208
213
|
end
|
@@ -223,7 +228,11 @@ module Grape
|
|
223
228
|
end
|
224
229
|
|
225
230
|
def tag_object(route)
|
226
|
-
Array(
|
231
|
+
Array(
|
232
|
+
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
|
233
|
+
i == route.prefix.to_s || i == route.version
|
234
|
+
end.first
|
235
|
+
)
|
227
236
|
end
|
228
237
|
|
229
238
|
private
|
@@ -240,7 +249,9 @@ module Grape
|
|
240
249
|
parse_request_params(required)
|
241
250
|
end || {}
|
242
251
|
|
243
|
-
|
252
|
+
if route.params.present? && !route.settings[:declared_params].present?
|
253
|
+
request_params = route.params.merge(request_params)
|
254
|
+
end
|
244
255
|
|
245
256
|
request_params
|
246
257
|
end
|
@@ -295,7 +306,10 @@ module Grape
|
|
295
306
|
raise GrapeSwagger::Errors::UnregisteredParser, "No parser registered for #{model_name}." unless parser
|
296
307
|
|
297
308
|
properties = parser.new(model, self).call
|
298
|
-
|
309
|
+
unless properties && properties.any?
|
310
|
+
raise GrapeSwagger::Errors::SwaggerSpec,
|
311
|
+
"Empty model #{model_name}, swagger 2.0 doesn't support empty definitions."
|
312
|
+
end
|
299
313
|
|
300
314
|
@definitions[model_name] = GrapeSwagger::DocMethods::BuildModelDefinition.build(model, properties)
|
301
315
|
|
@@ -6,7 +6,9 @@ module GrapeSwagger
|
|
6
6
|
|
7
7
|
def block_code(code, language)
|
8
8
|
language ||= 'text'
|
9
|
-
"<div class=\"code_highlight\"
|
9
|
+
"<div class=\"code_highlight\">
|
10
|
+
<pre><code class=\"highlight #{language}\">#{CGI.escapeHTML(code)}</code></pre>
|
11
|
+
</div>"
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -31,7 +33,8 @@ module GrapeSwagger
|
|
31
33
|
# when you want to have rouge as syntax highlighter add rouge to the gemfile or run:
|
32
34
|
# $ (sudo) gem install rouge
|
33
35
|
#
|
34
|
-
# GrapeSwagger::Markdown::RedcarpetAdapter.new({highlighter: :none},{no_links: true})
|
36
|
+
# GrapeSwagger::Markdown::RedcarpetAdapter.new({highlighter: :none},{no_links: true})
|
37
|
+
# will use no syntax highlighter and won't render links.
|
35
38
|
###
|
36
39
|
def initialize(options = {})
|
37
40
|
require 'redcarpet'
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#553 array of type in post/put params' do
|
4
|
+
let(:app) do
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
namespace :in_form_data do
|
7
|
+
desc 'create foo'
|
8
|
+
params do
|
9
|
+
requires :guid, type: Array[String]
|
10
|
+
end
|
11
|
+
post do
|
12
|
+
# your code goes here
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'put specific foo'
|
16
|
+
params do
|
17
|
+
requires :id
|
18
|
+
requires :guid, type: Array[String]
|
19
|
+
end
|
20
|
+
put ':id' do
|
21
|
+
# your code goes here
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace :in_body do
|
26
|
+
desc 'create foo'
|
27
|
+
params do
|
28
|
+
requires :guid, type: Array[String], documentation: { param_type: 'body' }
|
29
|
+
end
|
30
|
+
post do
|
31
|
+
# your code goes here
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'put specific foo'
|
35
|
+
params do
|
36
|
+
requires :id
|
37
|
+
requires :guid, type: Array[String], documentation: { param_type: 'body' }
|
38
|
+
end
|
39
|
+
put ':id' do
|
40
|
+
# your code goes here
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
add_swagger_documentation format: :json
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
subject do
|
49
|
+
get '/swagger_doc'
|
50
|
+
JSON.parse(last_response.body)
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'type for Array specified' do
|
54
|
+
describe 'in formData' do
|
55
|
+
describe 'post request' do
|
56
|
+
let(:params) { subject['paths']['/in_form_data']['post']['parameters'] }
|
57
|
+
|
58
|
+
specify do
|
59
|
+
expect(params).to eql([{
|
60
|
+
'in' => 'formData',
|
61
|
+
'name' => 'guid',
|
62
|
+
'type' => 'array',
|
63
|
+
'items' => { 'type' => 'string' },
|
64
|
+
'required' => true
|
65
|
+
}])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'put request' do
|
70
|
+
let(:params) { subject['paths']['/in_form_data/{id}']['put']['parameters'] }
|
71
|
+
|
72
|
+
specify do
|
73
|
+
expect(params).to eql(
|
74
|
+
[
|
75
|
+
{
|
76
|
+
'in' => 'path',
|
77
|
+
'name' => 'id',
|
78
|
+
'type' => 'string',
|
79
|
+
'required' => true
|
80
|
+
},
|
81
|
+
{
|
82
|
+
'in' => 'formData',
|
83
|
+
'name' => 'guid',
|
84
|
+
'type' => 'array',
|
85
|
+
'items' => { 'type' => 'string' },
|
86
|
+
'required' => true
|
87
|
+
}
|
88
|
+
]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'in body' do
|
95
|
+
describe 'post request' do
|
96
|
+
let(:params) { subject['paths']['/in_body']['post']['parameters'] }
|
97
|
+
|
98
|
+
specify do
|
99
|
+
expect(params).to eql(
|
100
|
+
[
|
101
|
+
{
|
102
|
+
'in' => 'body',
|
103
|
+
'name' => 'guid',
|
104
|
+
'required' => true,
|
105
|
+
'schema' => {
|
106
|
+
'type' => 'array',
|
107
|
+
'items' => { 'type' => 'string' }
|
108
|
+
}
|
109
|
+
}
|
110
|
+
]
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'put request' do
|
116
|
+
let(:params) { subject['paths']['/in_body/{id}']['put']['parameters'] }
|
117
|
+
|
118
|
+
specify do
|
119
|
+
expect(params).to eql(
|
120
|
+
[
|
121
|
+
{
|
122
|
+
'in' => 'path',
|
123
|
+
'name' => 'id',
|
124
|
+
'type' => 'string',
|
125
|
+
'required' => true
|
126
|
+
},
|
127
|
+
{
|
128
|
+
'in' => 'body',
|
129
|
+
'name' => 'guid',
|
130
|
+
'required' => true,
|
131
|
+
'schema' => {
|
132
|
+
'type' => 'array',
|
133
|
+
'items' => { 'type' => 'string' }
|
134
|
+
}
|
135
|
+
}
|
136
|
+
]
|
137
|
+
)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/spec/lib/data_type_spec.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GrapeSwagger::DocMethods::DataType do
|
4
|
+
before do
|
5
|
+
stub_const 'MyEntity', Class.new
|
6
|
+
MyEntity.class_eval do
|
7
|
+
def self.entity_name
|
8
|
+
'MyInteger'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
subject { described_class.call(value) }
|
5
14
|
|
6
15
|
describe 'standards' do
|
@@ -36,6 +45,12 @@ describe GrapeSwagger::DocMethods::DataType do
|
|
36
45
|
it { expect(subject).to eql 'string' }
|
37
46
|
end
|
38
47
|
|
48
|
+
describe 'Types in array with entity_name' do
|
49
|
+
let(:value) { { type: '[MyEntity]' } }
|
50
|
+
|
51
|
+
it { expect(subject).to eql 'MyInteger' }
|
52
|
+
end
|
53
|
+
|
39
54
|
describe 'Rack::Multipart::UploadedFile' do
|
40
55
|
let(:value) { { type: Rack::Multipart::UploadedFile } }
|
41
56
|
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,9 @@ Dir[File.join(Dir.getwd, 'spec/support/*.rb')].each { |f| require f }
|
|
8
8
|
require "grape-swagger/#{MODEL_PARSER}" if MODEL_PARSER != 'mock'
|
9
9
|
require File.join(Dir.getwd, "spec/support/model_parsers/#{MODEL_PARSER}_parser.rb")
|
10
10
|
|
11
|
+
require 'grape-entity'
|
12
|
+
require 'grape-swagger-entity'
|
13
|
+
|
11
14
|
Bundler.setup :default, :test
|
12
15
|
|
13
16
|
require 'rack'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'an operation id api' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
version '0.1'
|
7
|
+
|
8
|
+
desc 'Show this endpoint'
|
9
|
+
get '/simple_opp' do
|
10
|
+
{ foo: 'bar' }
|
11
|
+
end
|
12
|
+
|
13
|
+
add_swagger_documentation format: :json
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject do
|
18
|
+
get '/0.1/swagger_doc.json'
|
19
|
+
JSON.parse(last_response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'uses build name as operationId' do
|
23
|
+
expect(subject['paths']['/0.1/simple_opp']['get']['operationId']).to eql('get01SimpleOpp')
|
24
|
+
end
|
25
|
+
end
|
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.25.
|
4
|
+
version: 0.25.3
|
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-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -24,188 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.12.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: shoulda
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rdoc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: bundler
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rack-test
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rack-cors
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.40'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.40'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: kramdown
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: redcarpet
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: rouge
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: pry
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: pry-byebug
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
27
|
description:
|
210
28
|
email:
|
211
29
|
- tim.vandecasteele@gmail.com
|
@@ -264,6 +82,7 @@ files:
|
|
264
82
|
- spec/issues/533_specify_status_code_spec.rb
|
265
83
|
- spec/issues/539_array_post_body_spec.rb
|
266
84
|
- spec/issues/542_array_of_type_in_post_body_spec.rb
|
85
|
+
- spec/issues/553_align_array_put_post_params_spec.rb
|
267
86
|
- spec/lib/data_type_spec.rb
|
268
87
|
- spec/lib/endpoint_spec.rb
|
269
88
|
- spec/lib/extensions_spec.rb
|
@@ -320,6 +139,7 @@ files:
|
|
320
139
|
- spec/swagger_v2/namespace_tags_spec.rb
|
321
140
|
- spec/swagger_v2/namespaced_api_spec.rb
|
322
141
|
- spec/swagger_v2/nicknamed_api_spec.rb
|
142
|
+
- spec/swagger_v2/operation_id_api_spec.rb
|
323
143
|
- spec/swagger_v2/param_multi_type_spec.rb
|
324
144
|
- spec/swagger_v2/param_type_spec.rb
|
325
145
|
- spec/swagger_v2/param_values_spec.rb
|
@@ -364,6 +184,7 @@ test_files:
|
|
364
184
|
- spec/issues/533_specify_status_code_spec.rb
|
365
185
|
- spec/issues/539_array_post_body_spec.rb
|
366
186
|
- spec/issues/542_array_of_type_in_post_body_spec.rb
|
187
|
+
- spec/issues/553_align_array_put_post_params_spec.rb
|
367
188
|
- spec/lib/data_type_spec.rb
|
368
189
|
- spec/lib/endpoint_spec.rb
|
369
190
|
- spec/lib/extensions_spec.rb
|
@@ -420,6 +241,7 @@ test_files:
|
|
420
241
|
- spec/swagger_v2/namespace_tags_spec.rb
|
421
242
|
- spec/swagger_v2/namespaced_api_spec.rb
|
422
243
|
- spec/swagger_v2/nicknamed_api_spec.rb
|
244
|
+
- spec/swagger_v2/operation_id_api_spec.rb
|
423
245
|
- spec/swagger_v2/param_multi_type_spec.rb
|
424
246
|
- spec/swagger_v2/param_type_spec.rb
|
425
247
|
- spec/swagger_v2/param_values_spec.rb
|