grape-swagger-entity 0.2.2 → 0.2.3

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: 4765712e8fa51a31cb4cde4e6cb6c67e2863f3cb
4
- data.tar.gz: 2012ba6b40ad94a02afc087e8ddcfe9a2fb341f1
3
+ metadata.gz: dc998b981e77b49cc07ee0c8556ae90cd9039e7f
4
+ data.tar.gz: b41b339f7804f2b95234a72da9db8d8545a54e78
5
5
  SHA512:
6
- metadata.gz: bc1f438ae665e682e20603cd9c1693dce8fc41c243b49706aa4939d0c75034f251e6516329a66ac2dbdb09962ab214dc4411ede6e3d72b05b9cc7aec58c92328
7
- data.tar.gz: 467778758de82752d19f383bd9be651d06cd6116850ec8d71a21f79e337b822531b49bafbc8d4718940ed3d3b900eaa411cb3c7bb65058c993b65be4c404b3ac
6
+ metadata.gz: 040cebbf6a2a1a884d2a767655c61c4255d298a5e78212131a8fd70e576f332480cb5e4417660162e8cfabebf63abad6e265f166a330a1b2e7228ce33113abbf
7
+ data.tar.gz: 304e5f306ab9e0cfd43fb293c0604d88db110790ab6aa262d50ce27dafa9e320695bcb9a55083d5b734578b2f7e9273f28375bd0195ae91ca6bc957fe2764aa8
@@ -1,3 +1,7 @@
1
+ language: ruby
2
+
3
+ sudo: false
4
+
1
5
  before_install:
2
6
  - gem update --system
3
7
  - gem install bundler
@@ -6,9 +10,8 @@ after_success:
6
10
  - bundle exec danger
7
11
 
8
12
  rvm:
9
- - 2.4.0
10
- - 2.3.3
11
- - 2.2.6
13
+ - 2.4.2
14
+ - 2.3.5
12
15
 
13
16
  env:
14
17
  - GRAPE_ENTITY=0.5.2
@@ -18,6 +21,8 @@ matrix:
18
21
  fast_finish: true
19
22
 
20
23
  include:
24
+ - rvm: 2.2.8
25
+ env:
21
26
  - rvm: ruby-head
22
27
  env:
23
28
  - rvm: jruby-head
@@ -26,6 +31,7 @@ matrix:
26
31
  env:
27
32
 
28
33
  allow_failures:
34
+ - rvm: 2.2.8
29
35
  - rvm: ruby-head
30
36
  - rvm: jruby-head
31
37
  - rvm: rbx-2
@@ -8,6 +8,13 @@
8
8
 
9
9
  * Your contribution here.
10
10
 
11
+ ### 0.2.3 (November 19, 2017)
12
+
13
+ #### Fixes
14
+
15
+ * [#30](https://github.com/ruby-grape/grape-swagger-entity/pull/30): Fix nested exposures with an alias - [@Kukunin](https://github.com/Kukunin).
16
+ * [#31](https://github.com/ruby-grape/grape-swagger-entity/pull/31): Respect `required: true` for nested attributes as well - [@Kukunin](https://github.com/Kukunin).
17
+
11
18
  ### 0.2.2 (November 3, 2017)
12
19
 
13
20
  #### Features
@@ -27,19 +27,20 @@ module GrapeSwagger
27
27
  params.each_with_object({}) do |(entity_name, entity_options), memo|
28
28
  next if entity_options.fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
29
29
 
30
- entity_name = entity_options[:as] if entity_options[:as]
30
+ final_entity_name = entity_options.fetch(:as, entity_name)
31
31
  documentation = entity_options[:documentation]
32
32
 
33
- memo[entity_name] = if entity_options[:nesting]
34
- parse_nested(entity_name, entity_options, parent_model)
35
- else
36
- attribute_parser.call(entity_options)
37
- end
33
+ memo[final_entity_name] = if entity_options[:nesting]
34
+ parse_nested(entity_name, entity_options, parent_model)
35
+ else
36
+ attribute_parser.call(entity_options)
37
+ end
38
38
 
39
- if documentation
40
- memo[entity_name][:read_only] = documentation[:read_only].to_s == 'true' if documentation[:read_only]
41
- memo[entity_name][:description] = documentation[:desc] if documentation[:desc]
39
+ next unless documentation
40
+ if documentation[:read_only]
41
+ memo[final_entity_name][:read_only] = documentation[:read_only].to_s == 'true'
42
42
  end
43
+ memo[final_entity_name][:description] = documentation[:desc] if documentation[:desc]
43
44
  end
44
45
  end
45
46
 
@@ -54,6 +55,8 @@ module GrapeSwagger
54
55
  memo[value.attribute] = value.send(:options)
55
56
  end
56
57
 
58
+ required = required_params(params)
59
+
57
60
  properties = parse_grape_entity_params(params, nested_entity)
58
61
  is_a_collection = entity_options[:documentation].is_a?(Hash) &&
59
62
  entity_options[:documentation][:type].to_s.casecmp('array').zero?
@@ -61,20 +64,30 @@ module GrapeSwagger
61
64
  if is_a_collection
62
65
  {
63
66
  type: :array,
64
- items: {
67
+ items: with_required({
65
68
  type: :object,
66
69
  properties: properties
67
- },
68
- description: entity_options[:desc] || ''
70
+ }, required)
69
71
  }
70
72
  else
71
- {
73
+ with_required({
72
74
  type: :object,
73
- properties: properties,
74
- description: entity_options[:desc] || ''
75
- }
75
+ properties: properties
76
+ }, required)
76
77
  end
77
78
  end
79
+
80
+ def required_params(params)
81
+ params.select { |_, options| options.fetch(:documentation, {}).fetch(:required, false) }
82
+ .map { |(key, options)| [options.fetch(:as, key), options] }
83
+ .map(&:first)
84
+ end
85
+
86
+ def with_required(hash, required)
87
+ return hash if required.empty?
88
+ hash[:required] = required
89
+ hash
90
+ end
78
91
  end
79
92
  end
80
93
  end
@@ -1,5 +1,5 @@
1
1
  module GrapeSwagger
2
2
  module Entity
3
- VERSION = '0.2.2'.freeze
3
+ VERSION = '0.2.3'.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.2.2
4
+ version: 0.2.3
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-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-entity