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 +4 -4
- data/.github/workflows/test.yml +65 -8
- data/.rubocop.yml +2 -2
- data/.rubocop_todo.yml +7 -14
- data/CHANGELOG.md +7 -1
- data/Gemfile +6 -3
- data/UPGRADING.md +54 -0
- data/lib/grape-swagger/entity/parser.rb +9 -3
- data/lib/grape-swagger/entity/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d55e877c4ed7f40cbc6331e38fdb62522c85e92dfcb5bbf239be8181cbcd456
|
4
|
+
data.tar.gz: c22441830ec45ee2ef82dff6066106bfecfd5a820050665090e4c4f9c110b16e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf329848abcdcef57edd7cde491cef96160f29e266958f9ad5763f987210d506811858937c4e9cee59d85e2ff3ad200e85834a2cece230a172d22a6b0aaa2c9
|
7
|
+
data.tar.gz: efe0f9739a54925a044661d02ecd9ba232a5909a9c08556bd5a51c39aa6ea82ab413db5e77a350659ccba75462ceba704efb95f02ce2f774ea762f3491d8460c
|
data/.github/workflows/test.yml
CHANGED
@@ -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.
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
-
|
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
data/.rubocop_todo.yml
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
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:
|
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:
|
96
|
+
Max: 213
|
104
97
|
|
105
|
-
# Offense count:
|
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:
|
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:
|
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.
|
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
|
-
|
38
|
-
|
39
|
-
|
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.
|
139
|
-
|
140
|
-
|
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)
|
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.
|
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
|