grape-swagger-entity 0.1.3 → 0.1.4

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: 7e7aa5ac754173602ac184f45b9bdf26f75c0af9
4
- data.tar.gz: fbda957670775299a43bd8a99f582c909780ec05
3
+ metadata.gz: 09004935e0da7b2d424d04a85feb7d0b7e4f5665
4
+ data.tar.gz: 13531135fa1fd80e04a9f0677bbf95cd9034e4aa
5
5
  SHA512:
6
- metadata.gz: 9da5ddc8dec9962670fa707c7a19ef50e603ba3b71a941143df4db24274625e3245b8afeaea587125cdb7c1e386262f3e4454d9359fd16f5a70f5ffe1040b2f6
7
- data.tar.gz: 4fe7e4ddfed0651b2d6eff80734adfd1f6dfaa722b2d86fd00d5eeb0673f274eccbae5b059df76fd5252b6baea8f65fb85295af9010caac34ac042523a9aff4b
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-05-11 07:39:21 +0300 using RuboCop version 0.39.0.
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: 2
9
+ # Offense count: 1
10
10
  Metrics/AbcSize:
11
- Max: 69
11
+ Max: 48
12
12
 
13
13
  # Offense count: 1
14
14
  Metrics/CyclomaticComplexity:
15
15
  Max: 16
16
16
 
17
- # Offense count: 51
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: 1
23
+ # Offense count: 2
24
24
  # Configuration parameters: CountComments.
25
25
  Metrics/MethodLength:
26
- Max: 27
26
+ Max: 42
27
27
 
28
28
  # Offense count: 1
29
29
  Metrics/PerceivedComplexity:
30
- Max: 19
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 if params.nil?
28
+ return unless params
29
29
 
30
- params.each_with_object({}) do |x, memo|
31
- next if x[1].fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
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
- model = x.last[:using] if x.last[:using].present?
35
- model ||= x.last[:documentation][:type] if x.last[:documentation] && could_it_be_a_model?(x.last[:documentation])
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[x.first] = if x.last[:documentation] && x.last[:documentation][:is_array]
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 = x.last[:type]
46
- documented_type ||= x.last[:documentation][:type] if x.last[:documentation]
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
- memo[x.first] = { type: data.first, format: data.last }
54
+
55
+ memo[entity_name] = {
56
+ type: data.first,
57
+ format: data.last
58
+ }
52
59
  else
53
- memo[x.first] = { type: data_type }
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
- memo[x.first][:enum] = x.last[:values] if x.last[:values] && x.last[:values].is_a?(Array)
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
- value[:type].to_s.include?('Entity') || value[:type].to_s.include?('Entities')
65
- ) || (
66
- value[:type] &&
67
- value[:type].is_a?(Class) &&
68
- !GrapeSwagger::DocMethods::DataType.primitive?(value[:type].name.downcase) &&
69
- !value[:type] == Array
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
@@ -1,5 +1,5 @@
1
1
  module GrapeSwagger
2
2
  module Entity
3
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.1.4'.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.3
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-05-16 00:00:00.000000000 Z
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