Skip to content

Commit cac04bc

Browse files
authored
Merge pull request #79 from krororo/fix-type-class
Fix Correctly handle class types like Time in documentation
2 parents 4bdb457 + 653bcbe commit cac04bc

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-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+
* [#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).
1011

1112
### 0.6.0 (2025/04/26)
1213

lib/grape-swagger/entity/attribute_parser.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ def ambiguous_model_type?(type)
6060
end
6161

6262
def primitive_type?(type)
63-
type_name = type.name&.downcase
64-
return false if type_name.nil?
65-
66-
GrapeSwagger::DocMethods::DataType.primitive?(type_name) ||
67-
ADDITIONAL_PRIMITIVE_TYPES.include?(type_name)
63+
data_type = GrapeSwagger::DocMethods::DataType.call(type)
64+
GrapeSwagger::DocMethods::DataType.primitive?(data_type) ||
65+
ADDITIONAL_PRIMITIVE_TYPES.include?(data_type)
6866
end
6967

7068
def data_type_from(entity_options)

spec/grape-swagger/entities/response_model_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def app
5454
'properties' =>
5555
{ 'text' => { 'type' => 'string', 'description' => 'Content of something.' },
5656
'colors' => { 'type' => 'array', 'items' => { 'type' => 'string' }, 'description' => 'Colors' },
57+
'created_at' => { 'type' => 'string', 'format' => 'date-time', 'description' => 'Created at the time.' },
5758
'kind' => { '$ref' => '#/definitions/ThisApi_Entities_Kind',
5859
'description' => 'The kind of this something.' },
5960
'kind2' => { '$ref' => '#/definitions/ThisApi_Entities_Kind', 'description' => 'Secondary kind.' },

spec/support/shared_contexts/this_api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Something < Grape::Entity
3131
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
3232
expose :colors, documentation: { type: 'string', desc: 'Colors', is_array: true }
3333
expose :hidden_attr, documentation: { type: 'string', desc: 'Hidden', hidden: true }
34+
expose :created_at, documentation: { type: Time, desc: 'Created at the time.' }
3435
expose :kind, using: Kind, documentation: { type: 'ThisApi::Kind', desc: 'The kind of this something.' }
3536
expose :kind2, using: Kind, documentation: { desc: 'Secondary kind.' }
3637
expose :kind3, using: ThisApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' }

0 commit comments

Comments
 (0)