grape-swagger-entity 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d482687ea661169b18eb8f35ef06aa7601a57f4965c568b8f130c0451964465b
4
- data.tar.gz: 31e4b9aa0f9d132aabaefd2463a0fcecb3758eddc2316a13a5c77e443a653a55
3
+ metadata.gz: 3d55e877c4ed7f40cbc6331e38fdb62522c85e92dfcb5bbf239be8181cbcd456
4
+ data.tar.gz: c22441830ec45ee2ef82dff6066106bfecfd5a820050665090e4c4f9c110b16e
5
5
  SHA512:
6
- metadata.gz: 865221ba8a968d4f52d0572c30b3bcbff87797827f36056a34b9addb7e6cdc496354fbc87d8e89ed0b39e22691a32797b129219666a6c19f5dc2837983161344
7
- data.tar.gz: 2a87aa4e3b5219238d1c59e184c0e52acb2c8e9f077830117895fd7af554721631f64e3ce9be73b1f4573d9a4026a68a8805d2298c4717f2133b99cabe58aa2c
6
+ metadata.gz: bbf329848abcdcef57edd7cde491cef96160f29e266958f9ad5763f987210d506811858937c4e9cee59d85e2ff3ad200e85834a2cece230a172d22a6b0aaa2c9
7
+ data.tar.gz: efe0f9739a54925a044661d02ecd9ba232a5909a9c08556bd5a51c39aa6ea82ab413db5e77a350659ccba75462ceba704efb95f02ce2f774ea762f3491d8460c
@@ -15,7 +15,7 @@ jobs:
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
18
- ruby-version: 3.2
18
+ ruby-version: 3.0
19
19
  bundler-cache: true
20
20
  rubygems: latest
21
21
 
@@ -26,13 +26,70 @@ jobs:
26
26
  name: test (ruby=${{ matrix.ruby }}, grape=${{ matrix.grape }}, grape-swagger=${{ matrix.grape_swagger}}, grape_entity=${{ matrix.grape_entity }})
27
27
  strategy:
28
28
  matrix:
29
- grape: [ '~> 2.0.0', 'head' ]
30
- grape_swagger: [ '~> 2.0.3', 'head' ]
31
- grape_entity: [ '~> 1.0.1', 'head' ]
32
- ruby: [ '3.1', '3.4', 'head' ]
33
- # Exclude combinations that are not supported.
34
- exclude:
35
- - { grape_swagger: '~> 2.0.3', grape: 'head' }
29
+ include:
30
+ # Ruby 3.1 combinations
31
+ - ruby: '3.0'
32
+ grape: '~> 2.0.0'
33
+ grape_swagger: '~> 2.0.3'
34
+ grape_entity: '~> 1.0.1'
35
+ - ruby: '3.0'
36
+ grape: '~> 2.0.0'
37
+ grape_swagger: '~> 2.1.1'
38
+ grape_entity: 'head'
39
+
40
+ # Ruby 3.4 combinations
41
+ - ruby: '3.4'
42
+ grape: '~> 2.0.0'
43
+ grape_swagger: '~> 2.0.3'
44
+ grape_entity: '~> 1.0.1'
45
+ - ruby: '3.4'
46
+ grape: '~> 2.0.0'
47
+ grape_swagger: '~> 2.0.3'
48
+ grape_entity: 'head'
49
+ - ruby: '3.4'
50
+ grape: '~> 2.0.0'
51
+ grape_swagger: 'head'
52
+ grape_entity: '~> 1.0.1'
53
+ - ruby: '3.4'
54
+ grape: '~> 2.0.0'
55
+ grape_swagger: 'head'
56
+ grape_entity: 'head'
57
+ # - ruby: '3.4'
58
+ # grape: 'head'
59
+ # grape_swagger: 'head'
60
+ # grape_entity: '~> 1.0.1'
61
+ # - ruby: '3.4'
62
+ # grape: 'head'
63
+ # grape_swagger: 'head'
64
+ # grape_entity: 'head'
65
+
66
+ # Ruby head combinations
67
+ - ruby: 'head'
68
+ grape: '~> 2.0.0'
69
+ grape_swagger: '~> 2.0.3'
70
+ grape_entity: '~> 1.0.1'
71
+ - ruby: 'head'
72
+ grape: '~> 2.0.0'
73
+ grape_swagger: '~> 2.0.3'
74
+ grape_entity: 'head'
75
+ - ruby: 'head'
76
+ grape: '~> 2.0.0'
77
+ grape_swagger: 'head'
78
+ grape_entity: '~> 1.0.1'
79
+
80
+ # - ruby: 'head'
81
+ # grape: '~> 2.0.0'
82
+ # grape_swagger: 'head'
83
+ # grape_entity: 'head'
84
+ # - ruby: 'head'
85
+ # grape: 'head'
86
+ # grape_swagger: 'head'
87
+ # grape_entity: '~> 1.0.1'
88
+ # - ruby: 'head'
89
+ # grape: 'head'
90
+ # grape_swagger: 'head'
91
+ # grape_entity: 'head'
92
+
36
93
  runs-on: ubuntu-latest
37
94
  env:
38
95
  GRAPE_VERSION: ${{ matrix.grape }}
data/.rubocop.yml CHANGED
@@ -3,11 +3,11 @@ AllCops:
3
3
  Exclude:
4
4
  - vendor/**/*
5
5
  TargetRubyVersion:
6
- 2.7
6
+ 3.0
7
7
 
8
8
  inherit_from: .rubocop_todo.yml
9
9
 
10
- require:
10
+ plugins:
11
11
  - rubocop-rake
12
12
  - rubocop-rspec
13
13
 
data/.rubocop_todo.yml CHANGED
@@ -1,18 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2024-09-09 22:35:29 UTC using RuboCop version 1.66.1.
3
+ # on 2025-05-28 16:52:10 UTC using RuboCop version 1.75.8.
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
10
- # Configuration parameters: Severity, Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
13
- Exclude:
14
- - 'grape-swagger-entity.gemspec'
15
-
16
9
  # Offense count: 3
17
10
  # Configuration parameters: AllowedMethods.
18
11
  # AllowedMethods: enums
@@ -44,7 +37,7 @@ Metrics/AbcSize:
44
37
  # Offense count: 2
45
38
  # Configuration parameters: CountComments, CountAsOne.
46
39
  Metrics/ClassLength:
47
- Max: 112
40
+ Max: 117
48
41
 
49
42
  # Offense count: 2
50
43
  # Configuration parameters: AllowedMethods, AllowedPatterns.
@@ -64,7 +57,7 @@ Metrics/PerceivedComplexity:
64
57
  # Offense count: 5
65
58
  # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
66
59
  # SupportedStyles: snake_case, normalcase, non_integer
67
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
60
+ # AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
68
61
  Naming/VariableNumber:
69
62
  Exclude:
70
63
  - 'spec/grape-swagger/entities/response_model_spec.rb'
@@ -100,9 +93,9 @@ RSpec/DescribeClass:
100
93
  # Offense count: 4
101
94
  # Configuration parameters: CountAsOne.
102
95
  RSpec/ExampleLength:
103
- Max: 187
96
+ Max: 213
104
97
 
105
- # Offense count: 24
98
+ # Offense count: 26
106
99
  RSpec/LeakyConstantDeclaration:
107
100
  Exclude:
108
101
  - 'spec/grape-swagger/entities/response_model_spec.rb'
@@ -118,14 +111,14 @@ RSpec/MultipleDescribes:
118
111
  RSpec/MultipleExpectations:
119
112
  Max: 11
120
113
 
121
- # Offense count: 20
114
+ # Offense count: 21
122
115
  # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
123
116
  # SupportedStyles: always, named_only
124
117
  RSpec/NamedSubject:
125
118
  Exclude:
126
119
  - 'spec/grape-swagger/entities/response_model_spec.rb'
127
120
 
128
- # Offense count: 39
121
+ # Offense count: 46
129
122
  # Configuration parameters: AllowedGroups.
130
123
  RSpec/NestedGroups:
131
124
  Max: 5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
- ### 0.6.2 (2025/05/10)
1
+ ### 0.7.0 (2025/08/02)
2
+
3
+ #### Features
2
4
 
5
+ * [#81](https://github.com/ruby-grape/grape-swagger-entity/pull/81): Make entity fields required by default - [@olivier-thatch](https://github.com/olivier-thatch).
6
+ * [#85](https://github.com/ruby-grape/grape-swagger-entity/pull/85): Use rubocop plugins, use ruby 3.0 as minimum version everywhere - [@olivier-thatch](https://github.com/olivier-thatch).
7
+
8
+ ### 0.6.2 (2025/05/10)
3
9
 
4
10
  #### Fixes
5
11
 
data/Gemfile CHANGED
@@ -34,9 +34,12 @@ group :development, :test do
34
34
  gem 'rake'
35
35
  gem 'rdoc'
36
36
  gem 'rspec'
37
- gem 'rubocop'
38
- gem 'rubocop-rake'
39
- gem 'rubocop-rspec'
37
+ end
38
+
39
+ group :development do
40
+ gem 'rubocop', '>= 1.72', require: false
41
+ gem 'rubocop-rake', '>= 0.7', require: false
42
+ gem 'rubocop-rspec', '>= 3.5.0', require: false
40
43
  end
41
44
 
42
45
  group :test do
data/UPGRADING.md ADDED
@@ -0,0 +1,54 @@
1
+ ## Upgrading grape-swagger-entity
2
+
3
+ ### Upgrading to >= 0.7.0
4
+
5
+ #### Entity Fields Required by Default
6
+
7
+ This release changes how `grape-swagger-entity` determines if an entity field is
8
+ **required** in the generated Swagger documentation. This is a **breaking change**
9
+ and may require updates to your API documentation and any tools or tests that rely
10
+ on the previous behavior.
11
+
12
+ **Previous Behavior:**
13
+ Fields were considered optional by default unless explicitly marked as `required: true`
14
+ in their `documentation` options.
15
+
16
+ **New Behavior:**
17
+ Fields are now considered **required by default** unless one of the following
18
+ conditions is met:
19
+
20
+ 1. **`documentation: { required: false }` is explicitly set:** If you want a field to
21
+ be optional, you must now explicitly set `required: false` within its
22
+ `documentation` hash.
23
+ ```ruby
24
+ expose :field_name,
25
+ documentation: { type: String, required: false, desc: 'An optional field' }
26
+ ```
27
+ 2. **`if` or `unless` options are present:** If a field uses `if` or `unless` for
28
+ conditional exposure, it will be considered optional.
29
+ ```ruby
30
+ expose :conditional_field,
31
+ if: -> { some_condition? },
32
+ documentation: { type: String, desc: 'Exposed only if condition is met' }
33
+ ```
34
+ 3. **`expose_nil: false` is set:** If `expose_nil` is set to `false`, the field will
35
+ be considered optional.
36
+ ```ruby
37
+ expose :non_nil_field,
38
+ expose_nil: false,
39
+ documentation: { type: String, desc: 'Not exposed if nil' }
40
+ ```
41
+
42
+ This change aligns `grape-swagger-entity`'s behavior with `grape-entity`'s rendering
43
+ logic, where fields are always exposed unless `if` or `unless` is provided.
44
+
45
+ **Action Required:**
46
+ Review your existing Grape entities. If you have fields that were implicitly
47
+ considered optional but did not explicitly set `required: false`, `if`, `unless`, or
48
+ `expose_nil: false`, they will now be marked as required in your Swagger
49
+ documentation.Adjust your `documentation` options accordingly to maintain the desired
50
+ optionality for these fields.
51
+
52
+ For more details, refer to GitHub Pull Request
53
+ [#81](https://github.com/ruby-grape/grape-swagger-entity/pull/81).
54
+ ````
@@ -135,9 +135,15 @@ module GrapeSwagger
135
135
  end
136
136
 
137
137
  def required_params(params)
138
- params.select { |_, options| options.fetch(:documentation, {}).fetch(:required, false) }
139
- .map { |(key, options)| [options.fetch(:as, key), options] }
140
- .map(&:first)
138
+ params.each_with_object(Set.new) do |(key, options), accum|
139
+ required = if options.fetch(:documentation, {}).key?(:required)
140
+ options.dig(:documentation, :required)
141
+ else
142
+ !options.key?(:if) && !options.key?(:unless) && options[:expose_nil] != false
143
+ end
144
+
145
+ accum.add(options.fetch(:as, key)) if required
146
+ end.to_a
141
147
  end
142
148
 
143
149
  def with_required(hash, required)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GrapeSwagger
4
4
  module Entity
5
- VERSION = '0.6.2'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger-entity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Zaitsev
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - RELEASING.md
58
58
  - Rakefile
59
+ - UPGRADING.md
59
60
  - bin/pry
60
61
  - bin/setup
61
62
  - grape-swagger-entity.gemspec