grape-swagger-entity 0.5.5 → 0.6.1

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: 2acdf9214576f2fd49186e8bf6163382daa19b6842dc08033567d2427aaa5bcc
4
- data.tar.gz: 50fa87da0ef94dff6128cea9b5178d3455c831b87457768ea8140bd14f8fc001
3
+ metadata.gz: 42830a4af16bc176defa31e496aeebfc5601a503e649169788b4465bdc265aa9
4
+ data.tar.gz: fbf28a2d59009b68385d8f32e0ff3bbc17cf801c5899274e3886284580393175
5
5
  SHA512:
6
- metadata.gz: 6f7f9ef5026e54fd99035d38e84c358cc8446a117aadeb486f900775ff15a83bc3b5aaa7c0f3c27afbde6a870ec77a3e8e6baf9fcc1c13df024826f1164aecf8
7
- data.tar.gz: 89b9bcb8ef9693861bf2042f70147f611b9500c0dda4db5cac5b08af03a156281be02ec14afd71722d23fa498fec28308f1d638997bae066f3db4c07c7d98397
6
+ metadata.gz: 39ba0110395a1e3424958ecde9fe48d144af50a7500cc78a19a7a7191e27dc2ac893ce5b1760477fd5c3ae56149506c8ae4466003c2d97d73559e7f9db3afd78
7
+ data.tar.gz: a3c91cf3cc0d9ad620adb3b3b40a4940430c88b863271fe58b98ee718180a1596ff4a3789ff67bfe12562f29b7acec3fd56635ab214d85499d4c968672742aab
@@ -23,21 +23,28 @@ jobs:
23
23
  run: bundle exec rubocop
24
24
 
25
25
  test:
26
- env:
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
- ruby-version: ['3.0', '3.1', '3.2', '3.3']
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' }
36
+ runs-on: ubuntu-latest
37
+ env:
38
+ GRAPE_VERSION: ${{ matrix.grape }}
39
+ GRAPE_SWAGGER_VERSION: ${{ matrix.grape_swagger }}
40
+ GRAPE_ENTITY_VERSION: ${{ matrix.grape_entity }}
34
41
 
35
42
  steps:
36
43
  - uses: actions/checkout@v4
37
44
  - name: Set up Ruby
38
45
  uses: ruby/setup-ruby@v1
39
46
  with:
40
- ruby-version: ${{ matrix.ruby-version }}
47
+ ruby-version: ${{ matrix.ruby }}
41
48
  bundler-cache: true
42
49
  - name: Run tests
43
50
  run: bundle exec rake spec
data/.rubocop.yml CHANGED
@@ -7,6 +7,10 @@ AllCops:
7
7
 
8
8
  inherit_from: .rubocop_todo.yml
9
9
 
10
+ require:
11
+ - rubocop-rake
12
+ - rubocop-rspec
13
+
10
14
  Naming/FileName:
11
15
  Enabled: false
12
16
 
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000`
3
- # on 2023-07-06 20:16:40 UTC using RuboCop version 1.42.0.
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-09-09 22:35:29 UTC using RuboCop version 1.66.1.
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
@@ -28,7 +28,7 @@ Lint/EmptyBlock:
28
28
  Exclude:
29
29
  - 'spec/grape-swagger/entity/attribute_parser_spec.rb'
30
30
 
31
- # Offense count: 1
31
+ # Offense count: 2
32
32
  # This cop supports unsafe autocorrection (--autocorrect-all).
33
33
  # Configuration parameters: AllowedMethods.
34
34
  # AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
@@ -37,59 +37,109 @@ Lint/RedundantSafeNavigation:
37
37
  - 'lib/grape-swagger/entity/attribute_parser.rb'
38
38
 
39
39
  # Offense count: 4
40
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes, Max.
40
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
41
41
  Metrics/AbcSize:
42
- Exclude:
43
- - 'lib/grape-swagger/entity/attribute_parser.rb'
44
- - 'lib/grape-swagger/entity/parser.rb'
45
-
46
- # Offense count: 13
47
- # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
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'
42
+ Max: 34
56
43
 
57
- # Offense count: 1
58
- # Configuration parameters: CountComments, Max, CountAsOne.
44
+ # Offense count: 2
45
+ # Configuration parameters: CountComments, CountAsOne.
59
46
  Metrics/ClassLength:
60
- Exclude:
61
- - 'lib/grape-swagger/entity/attribute_parser.rb'
62
- - 'lib/grape-swagger/entity/parser.rb'
47
+ Max: 112
63
48
 
64
49
  # Offense count: 2
65
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
50
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
66
51
  Metrics/CyclomaticComplexity:
67
- Exclude:
68
- - 'lib/grape-swagger/entity/attribute_parser.rb'
69
- - 'lib/grape-swagger/entity/parser.rb'
52
+ Max: 11
70
53
 
71
- # Offense count: 5
72
- # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
54
+ # Offense count: 7
55
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
73
56
  Metrics/MethodLength:
74
- Exclude:
75
- - 'lib/grape-swagger/entity/attribute_parser.rb'
76
- - 'lib/grape-swagger/entity/parser.rb'
57
+ Max: 28
77
58
 
78
59
  # Offense count: 2
79
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
60
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
80
61
  Metrics/PerceivedComplexity:
81
- Exclude:
82
- - 'lib/grape-swagger/entity/attribute_parser.rb'
83
- - 'lib/grape-swagger/entity/parser.rb'
62
+ Max: 13
84
63
 
85
- # Offense count: 2
64
+ # Offense count: 5
86
65
  # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
87
66
  # SupportedStyles: snake_case, normalcase, non_integer
88
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
67
+ # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
89
68
  Naming/VariableNumber:
90
69
  Exclude:
91
70
  - 'spec/grape-swagger/entities/response_model_spec.rb'
92
71
 
72
+ # Offense count: 1
73
+ RSpec/BeforeAfterAll:
74
+ Exclude:
75
+ - '**/spec/spec_helper.rb'
76
+ - '**/spec/rails_helper.rb'
77
+ - '**/spec/support/**/*.rb'
78
+ - 'spec/grape-swagger/entities/response_model_spec.rb'
79
+
80
+ # Offense count: 4
81
+ # Configuration parameters: Prefixes, AllowedPatterns.
82
+ # Prefixes: when, with, without
83
+ RSpec/ContextWording:
84
+ Exclude:
85
+ - 'spec/grape-swagger/entity/parser_spec.rb'
86
+ - 'spec/support/shared_contexts/inheritance_api.rb'
87
+ - 'spec/support/shared_contexts/this_api.rb'
88
+
89
+ # Offense count: 2
90
+ # Configuration parameters: IgnoredMetadata.
91
+ RSpec/DescribeClass:
92
+ Exclude:
93
+ - '**/spec/features/**/*'
94
+ - '**/spec/requests/**/*'
95
+ - '**/spec/routing/**/*'
96
+ - '**/spec/system/**/*'
97
+ - '**/spec/views/**/*'
98
+ - 'spec/grape-swagger/entities/response_model_spec.rb'
99
+
100
+ # Offense count: 4
101
+ # Configuration parameters: CountAsOne.
102
+ RSpec/ExampleLength:
103
+ Max: 187
104
+
105
+ # Offense count: 24
106
+ RSpec/LeakyConstantDeclaration:
107
+ Exclude:
108
+ - 'spec/grape-swagger/entities/response_model_spec.rb'
109
+ - 'spec/support/shared_contexts/inheritance_api.rb'
110
+ - 'spec/support/shared_contexts/this_api.rb'
111
+
112
+ # Offense count: 1
113
+ RSpec/MultipleDescribes:
114
+ Exclude:
115
+ - 'spec/grape-swagger/entities/response_model_spec.rb'
116
+
117
+ # Offense count: 5
118
+ RSpec/MultipleExpectations:
119
+ Max: 11
120
+
121
+ # Offense count: 20
122
+ # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
123
+ # SupportedStyles: always, named_only
124
+ RSpec/NamedSubject:
125
+ Exclude:
126
+ - 'spec/grape-swagger/entities/response_model_spec.rb'
127
+
128
+ # Offense count: 39
129
+ # Configuration parameters: AllowedGroups.
130
+ RSpec/NestedGroups:
131
+ Max: 5
132
+
133
+ # Offense count: 3
134
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
135
+ # Include: **/*_spec.rb
136
+ RSpec/SpecFilePathFormat:
137
+ Exclude:
138
+ - '**/spec/routing/**/*'
139
+ - 'spec/grape-swagger/entity/attribute_parser_spec.rb'
140
+ - 'spec/grape-swagger/entity/parser_spec.rb'
141
+ - 'spec/grape-swagger/entity_spec.rb'
142
+
93
143
  # Offense count: 4
94
144
  # Configuration parameters: AllowedConstants.
95
145
  Style/Documentation:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 0.6.1 (2025/05/06)
2
+
3
+ #### Fixes
4
+
5
+ * [#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).
6
+
7
+ ### 0.6.0 (2025/04/26)
8
+
9
+ #### Features
10
+
11
+ * [#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).
12
+ * [#77](https://github.com/ruby-grape/grape-swagger-entity/pull/77): Allow proc for enum values in documentation - [@krororo](https://github.com/krororo).
13
+
14
+ #### Fixes
15
+
16
+ * [#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).
17
+
1
18
  ### 0.5.5 (2024/09/09)
2
19
 
3
20
  #### 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]
@@ -16,12 +35,12 @@ group :development, :test do
16
35
  gem 'rdoc'
17
36
  gem 'rspec'
18
37
  gem 'rubocop'
38
+ gem 'rubocop-rake'
39
+ gem 'rubocop-rspec'
19
40
  end
20
41
 
21
- gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'
22
-
23
42
  group :test do
24
- gem 'grape-entity', ENV.fetch('GRAPE_ENTITY', '1.0.0')
43
+ gem 'grape-entity', grape_entity_spec
25
44
  gem 'ruby-grape-danger', '~> 0.2.1', require: false
26
45
  gem 'simplecov', require: false
27
46
  end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # GrapeSwagger::Entity
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/grape-swagger-entity.svg)](https://badge.fury.io/rb/grape-swagger-entity)
4
- [![Build Status](https://github.com/ruby-grape/grape-swagger-entity/workflows/test/badge.svg?branch=master)](https://github.com/ruby-grape/grape-swagger-entity/actions)
4
+ [![Build Status](https://github.com/ruby-grape/grape-swagger-entity/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-grape/grape-swagger-entity/actions/workflows/test.yml)
5
5
 
6
6
  ## Table of Contents
7
7
 
@@ -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.add_runtime_dependency 'grape-entity', '~> 1'
24
- s.add_runtime_dependency 'grape-swagger', '~> 2'
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
@@ -5,6 +5,9 @@ module GrapeSwagger
5
5
  class AttributeParser
6
6
  attr_reader :endpoint
7
7
 
8
+ # The list of that doesn't handled by `GrapeSwagger::DocMethods::DataType.primitive?` method
9
+ ADDITIONAL_PRIMITIVE_TYPES = %w[string array].freeze
10
+
8
11
  def initialize(endpoint)
9
12
  @endpoint = endpoint
10
13
  end
@@ -53,9 +56,13 @@ module GrapeSwagger
53
56
  end
54
57
 
55
58
  def ambiguous_model_type?(type)
56
- type&.is_a?(Class) &&
57
- !GrapeSwagger::DocMethods::DataType.primitive?(type.name.downcase) &&
58
- !type == Array
59
+ type&.is_a?(Class) && !primitive_type?(type)
60
+ end
61
+
62
+ def primitive_type?(type)
63
+ data_type = GrapeSwagger::DocMethods::DataType.call(type)
64
+ GrapeSwagger::DocMethods::DataType.primitive?(data_type) ||
65
+ ADDITIONAL_PRIMITIVE_TYPES.include?(data_type)
59
66
  end
60
67
 
61
68
  def data_type_from(entity_options)
@@ -86,9 +93,9 @@ module GrapeSwagger
86
93
 
87
94
  type[:format] = documentation[:format] if documentation.key?(:format)
88
95
 
89
- if (values = documentation[:values]) && values.is_a?(Array)
90
- type[:enum] = values
91
- end
96
+ values = documentation[:values]
97
+ values = values.call if values.is_a?(Proc)
98
+ type[:enum] = values if values.is_a?(Array)
92
99
 
93
100
  type
94
101
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GrapeSwagger
4
4
  module Entity
5
- VERSION = '0.5.5'
5
+ VERSION = '0.6.1'
6
6
  end
7
7
  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.5.5
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Zaitsev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-09 00:00:00.000000000 Z
11
+ date: 2025-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-entity
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.3.7
90
+ rubygems_version: 3.5.22
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Grape swagger adapter to support grape-entity object parsing