Skip to content

Allow Classes for type declarations inside documentation #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.8.1 (Next)

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

### 0.8.0 (August 30, 2014)

Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def is_primitive?(type)
end

def generate_typeref(type)
type = type.to_s.sub(/^[A-Z]/) { |f| f.downcase } if type.is_a?(Class)
if is_primitive? type
{ 'type' => type }
else
Expand Down
11 changes: 8 additions & 3 deletions spec/api_global_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ module Entities
module Some
class Thing < Grape::Entity
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
expose :name, documentation: { type: String, desc: 'Name of something.' }
end

class CombinedThing < Grape::Entity
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
expose :created_at, documentation: { type: DateTime, desc: 'Creation of something.' }
end
end
end
Expand Down Expand Up @@ -47,7 +49,8 @@ def app
'Some::Thing' => {
'id' => 'Some::Thing',
'properties' => {
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
}
})
end
Expand All @@ -60,15 +63,17 @@ def app
'Some::Thing' => {
'id' => 'Some::Thing',
'properties' => {
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
'name' => { 'type' => 'string', 'description' => 'Name of something.' }
}
})

expect(json['models']).to include(
'Some::CombinedThing' => {
'id' => 'Some::CombinedThing',
'properties' => {
'text' => { 'type' => 'string', 'description' => 'Content of something.' }
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
'created_at' => { 'type' => 'dateTime', 'description' => 'Creation of something.' }
}
})

Expand Down