Skip to content

Commit

Permalink
Add tests to account for documented Hashes and Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Schuster committed Jun 10, 2016
1 parent 10a3b65 commit af54546
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
#### Features

* [#448](https://github.com/ruby-grape/grape-swagger/pull/448): Header parameters are now prepended to the parameter list - [@anakinj](https://github.com/anakinj).
* [#444](https://github.com/ruby-grape/grape-swagger/pull/444): With multi types parameter the first type is use as the documentation type [@scauglog](https://github.com/scauglog)
* [#444](https://github.com/ruby-grape/grape-swagger/pull/444): With multi types parameter the first type is use as the documentation type [@scauglog](https://github.com/scauglog).
* Your contribution here.

#### Fixes

* [#450](https://github.com/ruby-grape/grape-swagger/pull/438): Do not add :description to definitions if :description is missing on path - [@texpert](https://github.com/texpert).
* [#447](https://github.com/ruby-grape/grape-swagger/pull/447): Version part of the url is now ignored when generating tags for endpoint - [@anakinj](https://github.com/anakinj).
* [#444](https://github.com/ruby-grape/grape-swagger//pull/444): Default value provided in the documentation hash, override the grape default [@scauglog](https://github.com/scauglog)
* [#443](https://github.com/ruby-grape/grape-swagger/issues/443): Type provided in the documentation hash, override the grape type [@scauglog](https://github.com/scauglog)
* [#444](https://github.com/ruby-grape/grape-swagger//pull/444): Default value provided in the documentation hash, override the grape default [@scauglog](https://github.com/scauglog).
* [#443](https://github.com/ruby-grape/grape-swagger/issues/443): Type provided in the documentation hash, override the grape type [@scauglog](https://github.com/scauglog).
* [#453](https://github.com/ruby-grape/grape-swagger/pull/453): Include documented Hashes in documentation output - [@aschuster3](https://github.com/aschuster3).
* Your contribution here.

### 0.21.0 (June 1, 2016)

Expand Down
8 changes: 7 additions & 1 deletion spec/support/model_parsers/entity_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class RecursiveModel < Grape::Entity
expose :name, documentation: { type: String, desc: 'The name.' }
expose :children, using: self, documentation: { type: 'RecursiveModel', is_array: true, desc: 'The child nodes.' }
end

class DocumentedHashAndArrayModel < Grape::Entity
expose :raw_hash, documentation: { type: Hash, desc: 'Example Hash.' }
expose :raw_array, documentation: { type: Array, desc: 'Example Array' }
end
end
end

Expand All @@ -124,7 +129,8 @@ class RecursiveModel < Grape::Entity
'ApiError' => { 'type' => 'object', 'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'status code' }, 'message' => { 'type' => 'string', 'description' => 'error message' } } },
'ResponseItem' => { 'type' => 'object', 'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int32' }, 'name' => { 'type' => 'string' } } },
'UseResponse' => { 'type' => 'object', 'properties' => { 'description' => { 'type' => 'string' }, '$responses' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/ResponseItem' } } } },
'RecursiveModel' => { 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'The name.' }, 'children' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/RecursiveModel' }, 'description' => 'The child nodes.' } } }
'RecursiveModel' => { 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'The name.' }, 'children' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/RecursiveModel' }, 'description' => 'The child nodes.' } } },
'DocumentedHashAndArrayModel' => { 'type' => 'object', 'properties' => { 'raw_hash' => { 'type' => 'object', 'description' => 'Example Hash.' }, 'raw_array' => { 'type' => 'array', 'description' => 'Example Array' } } }
}
end

Expand Down
10 changes: 10 additions & 0 deletions spec/support/model_parsers/mock_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class QueryInput < OpenStruct; end
class ApiError < OpenStruct; end
class SecondApiError < OpenStruct; end
class RecursiveModel < OpenStruct; end
class DocumentedHashAndArrayModel < OpenStruct; end
end
end

Expand Down Expand Up @@ -83,6 +84,15 @@ class RecursiveModel < OpenStruct; end
'description' => "it's a mock"
}
}
},
'DocumentedHashAndArrayModel' => {
'type' => 'object',
'properties' => {
'mock_data' => {
'type' => 'string',
'description' => "it's a mock"
}
}
}
}
end
Expand Down
7 changes: 7 additions & 0 deletions spec/support/model_parsers/representable_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ class RecursiveModel < Representable::Decorator
property :name, documentation: { type: String, desc: 'The name.' }
property :children, decorator: self, documentation: { type: 'RecursiveModel', is_array: true, desc: 'The child nodes.' }
end

class DocumentedHashAndArrayModel < Representable::Decorator
include Representable::JSON

property :raw_hash, documentation: { type: Hash, desc: 'Example Hash.' }
property :raw_array, documentation: { type: Array, desc: 'Example Array' }
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class ModelApi < Grape::API
add_swagger_documentation models: [
::Entities::UseResponse,
::Entities::ApiError,
::Entities::RecursiveModel
::Entities::RecursiveModel,
::Entities::DocumentedHashAndArrayModel
]
end
end
Expand Down

0 comments on commit af54546

Please sign in to comment.