Skip to content

Commit e5a94a5

Browse files
authored
Merge pull request #82 from numbata/fix/recognize-grape-boolean-primitive
Fix: Recognize Grape::API::Boolean as a primitive type
1 parent df415ab commit e5a94a5

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* Your contribution here.
10+
* [#82](https://github.com/ruby-grape/grape-swagger-entity/pull/82): Fix: simplify primitive types recognition - [@numbata](https://github.com/numbata).
1011

1112
### 0.6.1 (2025/05/06)
1213

lib/grape-swagger/entity/attribute_parser.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ module Entity
55
class AttributeParser
66
attr_reader :endpoint
77

8-
# The list of that doesn't handled by `GrapeSwagger::DocMethods::DataType.primitive?` method
9-
ADDITIONAL_PRIMITIVE_TYPES = %w[string array].freeze
10-
118
def initialize(endpoint)
129
@endpoint = endpoint
1310
end
@@ -61,8 +58,7 @@ def ambiguous_model_type?(type)
6158

6259
def primitive_type?(type)
6360
data_type = GrapeSwagger::DocMethods::DataType.call(type)
64-
GrapeSwagger::DocMethods::DataType.primitive?(data_type) ||
65-
ADDITIONAL_PRIMITIVE_TYPES.include?(data_type)
61+
GrapeSwagger::DocMethods::DataType.request_primitive?(data_type)
6662
end
6763

6864
def data_type_from(entity_options)

spec/grape-swagger/entity/attribute_parser_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ def self.to_s
262262
it { is_expected.not_to include('$ref') }
263263
end
264264

265+
context 'when it is exposed as a Boolean class' do
266+
let(:entity_options) do
267+
{ documentation: { type: Grape::API::Boolean, example: example_value, default: example_value } }
268+
end
269+
270+
context 'when the example value is true' do
271+
let(:example_value) { true }
272+
273+
it { is_expected.to include(type: 'boolean', example: example_value, default: example_value) }
274+
end
275+
276+
context 'when the example value is false' do
277+
let(:example_value) { false }
278+
279+
it { is_expected.to include(type: 'boolean', example: example_value, default: example_value) }
280+
end
281+
end
282+
265283
context 'when it is exposed as a boolean' do
266284
let(:entity_options) { { documentation: { type: 'boolean', example: example_value, default: example_value } } }
267285

@@ -277,6 +295,22 @@ def self.to_s
277295
it { is_expected.to include(type: 'boolean', example: example_value, default: example_value) }
278296
end
279297
end
298+
299+
context 'when it is exposed as a hash' do
300+
let(:entity_options) { { documentation: { type: Hash, example: example_value, default: example_value } } }
301+
302+
context 'when the example value is true' do
303+
let(:example_value) { true }
304+
305+
it { is_expected.to include(type: 'object', example: example_value, default: example_value) }
306+
end
307+
308+
context 'when the example value is false' do
309+
let(:example_value) { false }
310+
311+
it { is_expected.to include(type: 'object', example: example_value, default: example_value) }
312+
end
313+
end
280314
end
281315
end
282316
end

0 commit comments

Comments
 (0)