grape-swagger-entity 0.5.5 → 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 +72 -8
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +88 -45
- data/CHANGELOG.md +30 -0
- data/Gemfile +25 -3
- data/README.md +1 -1
- data/UPGRADING.md +54 -0
- data/grape-swagger-entity.gemspec +2 -2
- data/lib/grape-swagger/entity/attribute_parser.rb +9 -6
- data/lib/grape-swagger/entity/parser.rb +9 -3
- data/lib/grape-swagger/entity/version.rb +1 -1
- metadata +4 -7
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
|
|
|
@@ -23,21 +23,85 @@ jobs:
|
|
|
23
23
|
run: bundle exec rubocop
|
|
24
24
|
|
|
25
25
|
test:
|
|
26
|
-
|
|
27
|
-
GRAPE_ENTITY: 1.0.0
|
|
28
|
-
|
|
29
|
-
runs-on: ubuntu-latest
|
|
26
|
+
name: test (ruby=${{ matrix.ruby }}, grape=${{ matrix.grape }}, grape-swagger=${{ matrix.grape_swagger}}, grape_entity=${{ matrix.grape_entity }})
|
|
30
27
|
strategy:
|
|
31
|
-
fail-fast: false
|
|
32
28
|
matrix:
|
|
33
|
-
|
|
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
|
+
|
|
93
|
+
runs-on: ubuntu-latest
|
|
94
|
+
env:
|
|
95
|
+
GRAPE_VERSION: ${{ matrix.grape }}
|
|
96
|
+
GRAPE_SWAGGER_VERSION: ${{ matrix.grape_swagger }}
|
|
97
|
+
GRAPE_ENTITY_VERSION: ${{ matrix.grape_entity }}
|
|
34
98
|
|
|
35
99
|
steps:
|
|
36
100
|
- uses: actions/checkout@v4
|
|
37
101
|
- name: Set up Ruby
|
|
38
102
|
uses: ruby/setup-ruby@v1
|
|
39
103
|
with:
|
|
40
|
-
ruby-version: ${{ matrix.ruby
|
|
104
|
+
ruby-version: ${{ matrix.ruby }}
|
|
41
105
|
bundler-cache: true
|
|
42
106
|
- name: Run tests
|
|
43
107
|
run: bundle exec rake spec
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
|
-
# `rubocop --auto-gen-config
|
|
3
|
-
# on
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
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
|
|
@@ -28,7 +21,7 @@ Lint/EmptyBlock:
|
|
|
28
21
|
Exclude:
|
|
29
22
|
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
|
|
30
23
|
|
|
31
|
-
# Offense count:
|
|
24
|
+
# Offense count: 2
|
|
32
25
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
33
26
|
# Configuration parameters: AllowedMethods.
|
|
34
27
|
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
|
|
@@ -37,59 +30,109 @@ Lint/RedundantSafeNavigation:
|
|
|
37
30
|
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
38
31
|
|
|
39
32
|
# Offense count: 4
|
|
40
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns,
|
|
33
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
|
41
34
|
Metrics/AbcSize:
|
|
42
|
-
|
|
43
|
-
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
44
|
-
- 'lib/grape-swagger/entity/parser.rb'
|
|
35
|
+
Max: 34
|
|
45
36
|
|
|
46
|
-
# Offense count:
|
|
47
|
-
# Configuration parameters: CountComments,
|
|
48
|
-
# AllowedMethods: refine
|
|
49
|
-
Metrics/BlockLength:
|
|
50
|
-
Exclude:
|
|
51
|
-
- '**/*.gemspec'
|
|
52
|
-
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
53
|
-
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
|
|
54
|
-
- 'spec/grape-swagger/entity/parser_spec.rb'
|
|
55
|
-
- 'spec/support/shared_contexts/this_api.rb'
|
|
56
|
-
|
|
57
|
-
# Offense count: 1
|
|
58
|
-
# Configuration parameters: CountComments, Max, CountAsOne.
|
|
37
|
+
# Offense count: 2
|
|
38
|
+
# Configuration parameters: CountComments, CountAsOne.
|
|
59
39
|
Metrics/ClassLength:
|
|
60
|
-
|
|
61
|
-
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
62
|
-
- 'lib/grape-swagger/entity/parser.rb'
|
|
40
|
+
Max: 117
|
|
63
41
|
|
|
64
42
|
# Offense count: 2
|
|
65
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns
|
|
43
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
|
66
44
|
Metrics/CyclomaticComplexity:
|
|
67
|
-
|
|
68
|
-
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
69
|
-
- 'lib/grape-swagger/entity/parser.rb'
|
|
45
|
+
Max: 11
|
|
70
46
|
|
|
71
|
-
# Offense count:
|
|
72
|
-
# Configuration parameters: CountComments,
|
|
47
|
+
# Offense count: 7
|
|
48
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
73
49
|
Metrics/MethodLength:
|
|
74
|
-
|
|
75
|
-
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
76
|
-
- 'lib/grape-swagger/entity/parser.rb'
|
|
50
|
+
Max: 28
|
|
77
51
|
|
|
78
52
|
# Offense count: 2
|
|
79
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns
|
|
53
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
|
80
54
|
Metrics/PerceivedComplexity:
|
|
81
|
-
|
|
82
|
-
- 'lib/grape-swagger/entity/attribute_parser.rb'
|
|
83
|
-
- 'lib/grape-swagger/entity/parser.rb'
|
|
55
|
+
Max: 13
|
|
84
56
|
|
|
85
|
-
# Offense count:
|
|
57
|
+
# Offense count: 5
|
|
86
58
|
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
|
87
59
|
# SupportedStyles: snake_case, normalcase, non_integer
|
|
88
|
-
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
|
|
60
|
+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
|
89
61
|
Naming/VariableNumber:
|
|
90
62
|
Exclude:
|
|
91
63
|
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
92
64
|
|
|
65
|
+
# Offense count: 1
|
|
66
|
+
RSpec/BeforeAfterAll:
|
|
67
|
+
Exclude:
|
|
68
|
+
- '**/spec/spec_helper.rb'
|
|
69
|
+
- '**/spec/rails_helper.rb'
|
|
70
|
+
- '**/spec/support/**/*.rb'
|
|
71
|
+
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
72
|
+
|
|
73
|
+
# Offense count: 4
|
|
74
|
+
# Configuration parameters: Prefixes, AllowedPatterns.
|
|
75
|
+
# Prefixes: when, with, without
|
|
76
|
+
RSpec/ContextWording:
|
|
77
|
+
Exclude:
|
|
78
|
+
- 'spec/grape-swagger/entity/parser_spec.rb'
|
|
79
|
+
- 'spec/support/shared_contexts/inheritance_api.rb'
|
|
80
|
+
- 'spec/support/shared_contexts/this_api.rb'
|
|
81
|
+
|
|
82
|
+
# Offense count: 2
|
|
83
|
+
# Configuration parameters: IgnoredMetadata.
|
|
84
|
+
RSpec/DescribeClass:
|
|
85
|
+
Exclude:
|
|
86
|
+
- '**/spec/features/**/*'
|
|
87
|
+
- '**/spec/requests/**/*'
|
|
88
|
+
- '**/spec/routing/**/*'
|
|
89
|
+
- '**/spec/system/**/*'
|
|
90
|
+
- '**/spec/views/**/*'
|
|
91
|
+
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
92
|
+
|
|
93
|
+
# Offense count: 4
|
|
94
|
+
# Configuration parameters: CountAsOne.
|
|
95
|
+
RSpec/ExampleLength:
|
|
96
|
+
Max: 213
|
|
97
|
+
|
|
98
|
+
# Offense count: 26
|
|
99
|
+
RSpec/LeakyConstantDeclaration:
|
|
100
|
+
Exclude:
|
|
101
|
+
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
102
|
+
- 'spec/support/shared_contexts/inheritance_api.rb'
|
|
103
|
+
- 'spec/support/shared_contexts/this_api.rb'
|
|
104
|
+
|
|
105
|
+
# Offense count: 1
|
|
106
|
+
RSpec/MultipleDescribes:
|
|
107
|
+
Exclude:
|
|
108
|
+
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
109
|
+
|
|
110
|
+
# Offense count: 5
|
|
111
|
+
RSpec/MultipleExpectations:
|
|
112
|
+
Max: 11
|
|
113
|
+
|
|
114
|
+
# Offense count: 21
|
|
115
|
+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
|
116
|
+
# SupportedStyles: always, named_only
|
|
117
|
+
RSpec/NamedSubject:
|
|
118
|
+
Exclude:
|
|
119
|
+
- 'spec/grape-swagger/entities/response_model_spec.rb'
|
|
120
|
+
|
|
121
|
+
# Offense count: 46
|
|
122
|
+
# Configuration parameters: AllowedGroups.
|
|
123
|
+
RSpec/NestedGroups:
|
|
124
|
+
Max: 5
|
|
125
|
+
|
|
126
|
+
# Offense count: 3
|
|
127
|
+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
|
128
|
+
# Include: **/*_spec.rb
|
|
129
|
+
RSpec/SpecFilePathFormat:
|
|
130
|
+
Exclude:
|
|
131
|
+
- '**/spec/routing/**/*'
|
|
132
|
+
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
|
|
133
|
+
- 'spec/grape-swagger/entity/parser_spec.rb'
|
|
134
|
+
- 'spec/grape-swagger/entity_spec.rb'
|
|
135
|
+
|
|
93
136
|
# Offense count: 4
|
|
94
137
|
# Configuration parameters: AllowedConstants.
|
|
95
138
|
Style/Documentation:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
### 0.7.0 (2025/08/02)
|
|
2
|
+
|
|
3
|
+
#### Features
|
|
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)
|
|
9
|
+
|
|
10
|
+
#### Fixes
|
|
11
|
+
|
|
12
|
+
* [#82](https://github.com/ruby-grape/grape-swagger-entity/pull/82): Fix: simplify primitive types recognition - [@numbata](https://github.com/numbata).
|
|
13
|
+
|
|
14
|
+
### 0.6.1 (2025/05/06)
|
|
15
|
+
|
|
16
|
+
#### Fixes
|
|
17
|
+
|
|
18
|
+
* [#79](https://github.com/ruby-grape/grape-swagger-entity/pull/79): Fix correctly handle class types like time in documentation - [@krororo](https://github.com/krororo).
|
|
19
|
+
|
|
20
|
+
### 0.6.0 (2025/04/26)
|
|
21
|
+
|
|
22
|
+
#### Features
|
|
23
|
+
|
|
24
|
+
* [#76](https://github.com/ruby-grape/grape-swagger-entity/pull/76): Update ci matrix and gemfile for multi-version grape testing - [@numbata](https://github.com/numbata).
|
|
25
|
+
* [#77](https://github.com/ruby-grape/grape-swagger-entity/pull/77): Allow proc for enum values in documentation - [@krororo](https://github.com/krororo).
|
|
26
|
+
|
|
27
|
+
#### Fixes
|
|
28
|
+
|
|
29
|
+
* [#75](https://github.com/ruby-grape/grape-swagger-entity/pull/75): Fix handling of entity with class names without "entity" or "entities" - [@numbata](https://github.com/numbata).
|
|
30
|
+
|
|
1
31
|
### 0.5.5 (2024/09/09)
|
|
2
32
|
|
|
3
33
|
#### Fixes
|
data/Gemfile
CHANGED
|
@@ -5,6 +5,25 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# Specify your gem's dependencies in grape-swagger-entity.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
+
grape_version = ENV.fetch('GRAPE_VERSION', '< 3.0')
|
|
9
|
+
grape_swagger_version = ENV.fetch('GRAPE_SWAGGER_VERSION', '< 3.0')
|
|
10
|
+
grape_entity_version = ENV.fetch('GRAPE_ENTITY_VERSION', '< 2.0')
|
|
11
|
+
|
|
12
|
+
grape_spec = grape_version.casecmp('HEAD').zero? ? { git: 'https://github.com/ruby-grape/grape' } : grape_version
|
|
13
|
+
grape_swagger_spec = if grape_swagger_version.casecmp('HEAD').zero?
|
|
14
|
+
{ git: 'https://github.com/ruby-grape/grape-swagger.git' }
|
|
15
|
+
else
|
|
16
|
+
grape_swagger_version
|
|
17
|
+
end
|
|
18
|
+
grape_entity_spec = if grape_entity_version.casecmp('HEAD').zero?
|
|
19
|
+
{ git: 'https://github.com/ruby-grape/grape-entity.git' }
|
|
20
|
+
else
|
|
21
|
+
grape_entity_version
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
gem 'grape', grape_spec
|
|
25
|
+
gem 'grape-swagger', grape_swagger_spec
|
|
26
|
+
|
|
8
27
|
group :development, :test do
|
|
9
28
|
gem 'bundler'
|
|
10
29
|
gem 'pry', platforms: [:mri]
|
|
@@ -15,13 +34,16 @@ group :development, :test do
|
|
|
15
34
|
gem 'rake'
|
|
16
35
|
gem 'rdoc'
|
|
17
36
|
gem 'rspec'
|
|
18
|
-
gem 'rubocop'
|
|
19
37
|
end
|
|
20
38
|
|
|
21
|
-
|
|
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
|
|
43
|
+
end
|
|
22
44
|
|
|
23
45
|
group :test do
|
|
24
|
-
gem 'grape-entity',
|
|
46
|
+
gem 'grape-entity', grape_entity_spec
|
|
25
47
|
gem 'ruby-grape-danger', '~> 0.2.1', require: false
|
|
26
48
|
gem 'simplecov', require: false
|
|
27
49
|
end
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# GrapeSwagger::Entity
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/grape-swagger-entity)
|
|
4
|
-
[](https://github.com/ruby-grape/grape-swagger-entity/actions/workflows/test.yml)
|
|
5
5
|
|
|
6
6
|
## Table of Contents
|
|
7
7
|
|
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
|
+
````
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
s.require_paths = ['lib']
|
|
21
21
|
|
|
22
22
|
s.required_ruby_version = '>= 3.0'
|
|
23
|
-
s.
|
|
24
|
-
s.
|
|
23
|
+
s.add_dependency 'grape-entity', '~> 1'
|
|
24
|
+
s.add_dependency 'grape-swagger', '~> 2'
|
|
25
25
|
s.metadata['rubygems_mfa_required'] = 'true'
|
|
26
26
|
end
|
|
@@ -53,9 +53,12 @@ module GrapeSwagger
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def ambiguous_model_type?(type)
|
|
56
|
-
type&.is_a?(Class) &&
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
type&.is_a?(Class) && !primitive_type?(type)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def primitive_type?(type)
|
|
60
|
+
data_type = GrapeSwagger::DocMethods::DataType.call(type)
|
|
61
|
+
GrapeSwagger::DocMethods::DataType.request_primitive?(data_type)
|
|
59
62
|
end
|
|
60
63
|
|
|
61
64
|
def data_type_from(entity_options)
|
|
@@ -86,9 +89,9 @@ module GrapeSwagger
|
|
|
86
89
|
|
|
87
90
|
type[:format] = documentation[:format] if documentation.key?(:format)
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
values = documentation[:values]
|
|
93
|
+
values = values.call if values.is_a?(Proc)
|
|
94
|
+
type[:enum] = values if values.is_a?(Array)
|
|
92
95
|
|
|
93
96
|
type
|
|
94
97
|
end
|
|
@@ -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,14 +1,13 @@
|
|
|
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
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: grape-entity
|
|
@@ -38,7 +37,6 @@ dependencies:
|
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '2'
|
|
41
|
-
description:
|
|
42
40
|
email:
|
|
43
41
|
- kirik910@gmail.com
|
|
44
42
|
executables: []
|
|
@@ -58,6 +56,7 @@ files:
|
|
|
58
56
|
- README.md
|
|
59
57
|
- RELEASING.md
|
|
60
58
|
- Rakefile
|
|
59
|
+
- UPGRADING.md
|
|
61
60
|
- bin/pry
|
|
62
61
|
- bin/setup
|
|
63
62
|
- grape-swagger-entity.gemspec
|
|
@@ -72,7 +71,6 @@ licenses:
|
|
|
72
71
|
- MIT
|
|
73
72
|
metadata:
|
|
74
73
|
rubygems_mfa_required: 'true'
|
|
75
|
-
post_install_message:
|
|
76
74
|
rdoc_options: []
|
|
77
75
|
require_paths:
|
|
78
76
|
- lib
|
|
@@ -87,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
85
|
- !ruby/object:Gem::Version
|
|
88
86
|
version: '0'
|
|
89
87
|
requirements: []
|
|
90
|
-
rubygems_version: 3.
|
|
91
|
-
signing_key:
|
|
88
|
+
rubygems_version: 3.6.8
|
|
92
89
|
specification_version: 4
|
|
93
90
|
summary: Grape swagger adapter to support grape-entity object parsing
|
|
94
91
|
test_files: []
|