Skip to content

Commit faf99ec

Browse files
committed
Allow the use of Classes for type declarations inside documentation
1 parent 19001f3 commit faf99ec

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/grape-swagger.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def is_primitive?(type)
426426
end
427427

428428
def generate_typeref(type)
429+
type = type.to_s.sub(/^[A-Z]/) {|f| f.downcase } if type.kind_of?(Class)
429430
if is_primitive? type
430431
{ 'type' => type }
431432
else

spec/api_global_models_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ module Entities
77
module Some
88
class Thing < Grape::Entity
99
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
10+
expose :name, documentation: { type: String, desc: 'Name of something.' }
1011
end
1112

1213
class CombinedThing < Grape::Entity
1314
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
15+
expose :created_at, documentation: { type: DateTime, desc: 'Creation of something.' }
1416
end
1517
end
1618
end
@@ -47,7 +49,8 @@ def app
4749
'Some::Thing' => {
4850
'id' => 'Some::Thing',
4951
'properties' => {
50-
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
52+
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
53+
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
5154
}
5255
})
5356
end
@@ -60,15 +63,17 @@ def app
6063
'Some::Thing' => {
6164
'id' => 'Some::Thing',
6265
'properties' => {
63-
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
66+
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
67+
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
6468
}
6569
})
6670

6771
expect(json['models']).to include(
6872
'Some::CombinedThing' => {
6973
'id' => 'Some::CombinedThing',
7074
'properties' => {
71-
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
75+
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
76+
'created_at' => { 'type' => 'dateTime', 'description' => 'Creation of something.' }
7277
}
7378
})
7479

0 commit comments

Comments
 (0)