grape-swagger-entity 0.1.6 → 0.2.0
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 +12 -12
- data/CHANGELOG.md +6 -0
- data/grape-swagger-entity.gemspec +1 -1
- data/lib/grape-swagger/entity/parser.rb +41 -12
- data/lib/grape-swagger/entity/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25f852e7a159a5e8c626e7fcfdd63c7b9e566674
|
4
|
+
data.tar.gz: f060d4e451f67a8a69f53ee9a013f969f0990259
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04652f20c5c6e885a787735d491260cab5343e2fb422907eea80da9463a866135a4435caf6a4c1b0f36365a150337dd7fdc6051de9439748b4bbeb0b0e28bf36
|
7
|
+
data.tar.gz: cd2f8375cbb8bb4d3200f22c8382384b8207e89ccca1324a207f9595f8f8b4bff7db7628f542e86e22ffe239f5aa50a4eb0439a002801db3ad62fdda9d7b397a
|
data/.rubocop_todo.yml
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-02-
|
3
|
+
# on 2017-02-26 22:17:25 +0200 using RuboCop version 0.47.1.
|
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: 2
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 35
|
12
12
|
|
13
|
-
# Offense count:
|
14
|
-
# Configuration parameters: CountComments
|
15
|
-
Metrics/
|
16
|
-
Max:
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 126
|
17
17
|
|
18
18
|
# Offense count: 1
|
19
19
|
Metrics/CyclomaticComplexity:
|
20
20
|
Max: 14
|
21
21
|
|
22
|
-
# Offense count:
|
22
|
+
# Offense count: 14
|
23
23
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
24
24
|
# URISchemes: http, https
|
25
25
|
Metrics/LineLength:
|
26
26
|
Max: 120
|
27
27
|
|
28
|
-
# Offense count:
|
28
|
+
# Offense count: 3
|
29
29
|
# Configuration parameters: CountComments.
|
30
30
|
Metrics/MethodLength:
|
31
|
-
Max:
|
31
|
+
Max: 27
|
32
32
|
|
33
|
-
# Offense count:
|
33
|
+
# Offense count: 2
|
34
34
|
Metrics/PerceivedComplexity:
|
35
|
-
Max:
|
35
|
+
Max: 15
|
36
36
|
|
37
37
|
# Offense count: 2
|
38
38
|
Style/Documentation:
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,12 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 0.2.0 (March 2, 2017)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#22](https://github.com/ruby-grape/grape-swagger-entity/pull/22): Nested exposures - [@Bugagazavr](https://github.com/Bugagazavr).
|
16
|
+
|
11
17
|
### 0.1.6 (February 3, 2017)
|
12
18
|
|
13
19
|
#### Features
|
@@ -10,14 +10,8 @@ module GrapeSwagger
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def call
|
13
|
-
|
14
|
-
|
15
|
-
warn 'usage of grape-entity <0.5.0 is deprecated'
|
16
|
-
parameters = model.exposures ? model.exposures : model.documentation
|
17
|
-
else
|
18
|
-
parameters = model.root_exposures.each_with_object({}) do |value, memo|
|
19
|
-
memo[value.attribute] = value.send(:options)
|
20
|
-
end
|
13
|
+
parameters = model.root_exposures.each_with_object({}) do |value, memo|
|
14
|
+
memo[value.attribute] = value.send(:options)
|
21
15
|
end
|
22
16
|
|
23
17
|
parse_grape_entity_params(parameters)
|
@@ -25,7 +19,7 @@ module GrapeSwagger
|
|
25
19
|
|
26
20
|
private
|
27
21
|
|
28
|
-
def parse_grape_entity_params(params)
|
22
|
+
def parse_grape_entity_params(params, parent_model = nil)
|
29
23
|
return unless params
|
30
24
|
|
31
25
|
params.each_with_object({}) do |(entity_name, entity_options), memo|
|
@@ -33,11 +27,13 @@ module GrapeSwagger
|
|
33
27
|
|
34
28
|
entity_name = entity_options[:as] if entity_options[:as]
|
35
29
|
documentation = entity_options[:documentation]
|
36
|
-
|
30
|
+
entity_model = model_from(entity_options)
|
37
31
|
|
38
|
-
if
|
39
|
-
name = endpoint.nil? ?
|
32
|
+
if entity_model
|
33
|
+
name = endpoint.nil? ? entity_model.to_s.demodulize : endpoint.send(:expose_params_from_model, entity_model)
|
40
34
|
memo[entity_name] = entity_model_type(name, entity_options)
|
35
|
+
elsif entity_options[:nesting]
|
36
|
+
memo[entity_name] = parse_nested(entity_name, entity_options, parent_model)
|
41
37
|
else
|
42
38
|
memo[entity_name] = data_type_from(entity_options)
|
43
39
|
next unless documentation
|
@@ -70,6 +66,39 @@ module GrapeSwagger
|
|
70
66
|
model
|
71
67
|
end
|
72
68
|
|
69
|
+
def parse_nested(entity_name, entity_options, parent_model = nil)
|
70
|
+
nested_entity = if parent_model.nil?
|
71
|
+
model.root_exposures.find_by(entity_name)
|
72
|
+
else
|
73
|
+
parent_model.nested_exposures.find_by(entity_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
params = nested_entity.nested_exposures.each_with_object({}) do |value, memo|
|
77
|
+
memo[value.attribute] = value.send(:options)
|
78
|
+
end
|
79
|
+
|
80
|
+
properties = parse_grape_entity_params(params, nested_entity)
|
81
|
+
is_a_collection = entity_options[:documentation].is_a?(Hash) &&
|
82
|
+
entity_options[:documentation][:type].to_s.casecmp('array').zero?
|
83
|
+
|
84
|
+
if is_a_collection
|
85
|
+
{
|
86
|
+
type: :array,
|
87
|
+
items: {
|
88
|
+
type: :object,
|
89
|
+
properties: properties
|
90
|
+
},
|
91
|
+
description: entity_options[:desc] || ''
|
92
|
+
}
|
93
|
+
else
|
94
|
+
{
|
95
|
+
type: :object,
|
96
|
+
properties: properties,
|
97
|
+
description: entity_options[:desc] || ''
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
73
102
|
def could_it_be_a_model?(value)
|
74
103
|
return false if value.nil?
|
75
104
|
direct_model_type?(value[:type]) || ambiguous_model_type?(value[:type])
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Zaitsev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-swagger
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.5.0
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- kirik910@gmail.com
|