grape-swagger-entity 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +7 -7
- data/CHANGELOG.md +15 -0
- data/lib/grape-swagger/entity/parser.rb +65 -25
- data/lib/grape-swagger/entity/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09004935e0da7b2d424d04a85feb7d0b7e4f5665
|
4
|
+
data.tar.gz: 13531135fa1fd80e04a9f0677bbf95cd9034e4aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e605ba8293b54f14ca786afe7c2c5f5e478042889c37aee3e2dd98e61f8149e4e5f3b1545a6d7d373542f679f4e8fbdbae48511de6b1a8465508b9c1c9ecfbec
|
7
|
+
data.tar.gz: 49da1141e3a3b413b893db0c0f4d1755e3a6dd516d05ffea0f367388f5cfba7130d103c8cfe349273c98f577a6302ef80e9b46b56cd76486c471184374a5ec94
|
data/.rubocop_todo.yml
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-
|
3
|
+
# on 2016-06-08 01:18:12 +0300 using RuboCop version 0.40.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 1
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 48
|
12
12
|
|
13
13
|
# Offense count: 1
|
14
14
|
Metrics/CyclomaticComplexity:
|
15
15
|
Max: 16
|
16
16
|
|
17
|
-
# Offense count:
|
17
|
+
# Offense count: 50
|
18
18
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
19
19
|
# URISchemes: http, https
|
20
20
|
Metrics/LineLength:
|
21
21
|
Max: 136
|
22
22
|
|
23
|
-
# Offense count:
|
23
|
+
# Offense count: 2
|
24
24
|
# Configuration parameters: CountComments.
|
25
25
|
Metrics/MethodLength:
|
26
|
-
Max:
|
26
|
+
Max: 42
|
27
27
|
|
28
28
|
# Offense count: 1
|
29
29
|
Metrics/PerceivedComplexity:
|
30
|
-
Max:
|
30
|
+
Max: 18
|
31
31
|
|
32
32
|
# Offense count: 2
|
33
33
|
Style/Documentation:
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
### Next
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* Your contribution here.
|
6
|
+
|
7
|
+
#### Fixes
|
8
|
+
|
9
|
+
* Your contribution here.
|
10
|
+
|
11
|
+
### 0.1.4 (June 7, 2016)
|
12
|
+
|
13
|
+
#### Fixes
|
14
|
+
|
15
|
+
* [#7](https://github.com/ruby-grape/grape-swagger-entity/pull/7) Fixed array support for primitive types - [@Bugagazavr](https://github.com/Bugagazavr).
|
@@ -25,49 +25,89 @@ module GrapeSwagger
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def parse_grape_entity_params(params)
|
28
|
-
return
|
28
|
+
return unless params
|
29
29
|
|
30
|
-
params.each_with_object({}) do |
|
31
|
-
next if
|
32
|
-
x[0] = x.last[:as] if x.last[:as]
|
30
|
+
params.each_with_object({}) do |(entity_name, entity_options), memo|
|
31
|
+
next if entity_options.fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
|
33
32
|
|
34
|
-
|
35
|
-
model
|
33
|
+
entity_name = entity_options[:as] if entity_options[:as]
|
34
|
+
model = entity_options[:using] if entity_options[:using].present?
|
35
|
+
|
36
|
+
if entity_options[:documentation] && could_it_be_a_model?(entity_options[:documentation])
|
37
|
+
model ||= entity_options[:documentation][:type]
|
38
|
+
end
|
36
39
|
|
37
40
|
if model
|
38
41
|
name = endpoint.send(:expose_params_from_model, model)
|
39
|
-
memo[
|
40
|
-
{ 'type' => 'array', 'items' => { '$ref' => "#/definitions/#{name}" } }
|
41
|
-
else
|
42
|
-
{ '$ref' => "#/definitions/#{name}" }
|
43
|
-
end
|
42
|
+
memo[entity_name] = entity_model_type(name, entity_options)
|
44
43
|
else
|
45
|
-
documented_type =
|
46
|
-
|
44
|
+
documented_type = entity_options[:type]
|
45
|
+
|
46
|
+
if entity_options[:documentation]
|
47
|
+
documented_type ||= entity_options[:documentation][:type]
|
48
|
+
end
|
49
|
+
|
47
50
|
data_type = GrapeSwagger::DocMethods::DataType.call(documented_type)
|
48
51
|
|
49
52
|
if GrapeSwagger::DocMethods::DataType.primitive?(data_type)
|
50
53
|
data = GrapeSwagger::DocMethods::DataType.mapping(data_type)
|
51
|
-
|
54
|
+
|
55
|
+
memo[entity_name] = {
|
56
|
+
type: data.first,
|
57
|
+
format: data.last
|
58
|
+
}
|
52
59
|
else
|
53
|
-
memo[
|
60
|
+
memo[entity_name] = {
|
61
|
+
type: data_type
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
if entity_options[:values] && entity_options[:values].is_a?(Array)
|
66
|
+
memo[entity_name][:enum] = entity_options[:values]
|
67
|
+
end
|
68
|
+
|
69
|
+
if entity_options[:documentation] && entity_options[:documentation][:is_array]
|
70
|
+
memo[entity_name] = {
|
71
|
+
type: :array,
|
72
|
+
items: memo.delete(entity_name)
|
73
|
+
}
|
54
74
|
end
|
75
|
+
end
|
55
76
|
|
56
|
-
|
77
|
+
if entity_options[:documentation] && entity_options[:documentation][:desc]
|
78
|
+
memo[entity_name][:description] = entity_options[:documentation][:desc]
|
57
79
|
end
|
58
|
-
memo[x.first][:description] = x.last[:documentation][:desc] if x.last[:documentation] && x.last[:documentation][:desc]
|
59
80
|
end
|
60
81
|
end
|
61
82
|
|
62
83
|
def could_it_be_a_model?(value)
|
63
|
-
(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
84
|
+
direct_model_type?(value[:type]) || ambiguous_model_type?(value[:type])
|
85
|
+
end
|
86
|
+
|
87
|
+
def direct_model_type?(type)
|
88
|
+
type.to_s.include?('Entity') || type.to_s.include?('Entities')
|
89
|
+
end
|
90
|
+
|
91
|
+
def ambiguous_model_type?(type)
|
92
|
+
type &&
|
93
|
+
type.is_a?(Class) &&
|
94
|
+
!GrapeSwagger::DocMethods::DataType.primitive?(type.name.downcase) &&
|
95
|
+
!type == Array
|
96
|
+
end
|
97
|
+
|
98
|
+
def entity_model_type(name, entity_options)
|
99
|
+
if entity_options[:documentation] && entity_options[:documentation][:is_array]
|
100
|
+
{
|
101
|
+
'type' => 'array',
|
102
|
+
'items' => {
|
103
|
+
'$ref' => "#/definitions/#{name}"
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else
|
107
|
+
{
|
108
|
+
'$ref' => "#/definitions/#{name}"
|
109
|
+
}
|
110
|
+
end
|
71
111
|
end
|
72
112
|
end
|
73
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger-entity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Zaitsev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-swagger
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- ".rubocop.yml"
|
191
191
|
- ".rubocop_todo.yml"
|
192
192
|
- ".travis.yml"
|
193
|
+
- CHANGELOG.md
|
193
194
|
- Gemfile
|
194
195
|
- LICENSE.txt
|
195
196
|
- README.md
|