Skip to content

Commit 6d4bfbc

Browse files
committed
Merge pull request #154 from mrmargolis/master
Allow Classes for type declarations inside documentation
2 parents 19001f3 + 0a91765 commit 6d4bfbc

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.8.1 (Next)
22

33
* Your contribution here.
4+
* [#154](https://github.com/tim-vandecasteele/grape-swagger/pull/154): Allow Classes for type declarations inside documentation - [@mrmargolis](https://github.com/mrmargolis).
45

56
### 0.8.0 (August 30, 2014)
67

lib/grape-swagger.rb

+1
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.is_a?(Class)
429430
if is_primitive? type
430431
{ 'type' => type }
431432
else

spec/api_global_models_spec.rb

+8-3
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)