grape-swagger-entity 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72459a987fb7696ab9b9af64da1bcbcd6e1b2de3
4
- data.tar.gz: 9c401e5bcab37c4fb90af2b3faf4d5226953f5fa
3
+ metadata.gz: 25f852e7a159a5e8c626e7fcfdd63c7b9e566674
4
+ data.tar.gz: f060d4e451f67a8a69f53ee9a013f969f0990259
5
5
  SHA512:
6
- metadata.gz: 0df830bd1242402544528d473051715e12d5ee82650849582b1126de32048e2b0547478334394559ef584b7c38e7ebb11fa62e0435f6e2da7e6220e6ff36b0b2
7
- data.tar.gz: 0b2c212b1580bba2706ca2e116e7f32b1ef50acb083e92191f2ec77363c6839017ac26705b874f81271a4d2d98d721c8c446e8d670ac500490362500445e5fbd
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-02 15:42:44 +0100 using RuboCop version 0.47.1.
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: 1
9
+ # Offense count: 2
10
10
  Metrics/AbcSize:
11
- Max: 45
11
+ Max: 35
12
12
 
13
- # Offense count: 8
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- Metrics/BlockLength:
16
- Max: 27
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: 11
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: 2
28
+ # Offense count: 3
29
29
  # Configuration parameters: CountComments.
30
30
  Metrics/MethodLength:
31
- Max: 30
31
+ Max: 27
32
32
 
33
- # Offense count: 1
33
+ # Offense count: 2
34
34
  Metrics/PerceivedComplexity:
35
- Max: 16
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
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = '>= 2.2.6'
22
22
  s.add_runtime_dependency 'grape-swagger', '>= 0.20.4'
23
- s.add_runtime_dependency 'grape-entity'
23
+ s.add_runtime_dependency 'grape-entity', '>= 0.5.0'
24
24
  end
@@ -10,14 +10,8 @@ module GrapeSwagger
10
10
  end
11
11
 
12
12
  def call
13
- # TODO: this should only be a temporary hack ;)
14
- if ::GrapeEntity::VERSION =~ /0\.4\.\d/
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
- model = model_from(entity_options)
30
+ entity_model = model_from(entity_options)
37
31
 
38
- if model
39
- name = endpoint.nil? ? model.to_s.demodulize : endpoint.send(:expose_params_from_model, model)
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])
@@ -1,5 +1,5 @@
1
1
  module GrapeSwagger
2
2
  module Entity
3
- VERSION = '0.1.6'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  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.6
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-03 00:00:00.000000000 Z
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: '0'
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: '0'
40
+ version: 0.5.0
41
41
  description:
42
42
  email:
43
43
  - kirik910@gmail.com