From af545465d025a197a027b98f25d7a9efa51a8a5c Mon Sep 17 00:00:00 2001 From: Andrew Schuster Date: Fri, 10 Jun 2016 15:38:28 -0400 Subject: [PATCH] Add tests to account for documented Hashes and Arrays --- CHANGELOG.md | 9 ++++++--- spec/support/model_parsers/entity_parser.rb | 8 +++++++- spec/support/model_parsers/mock_parser.rb | 10 ++++++++++ spec/support/model_parsers/representable_parser.rb | 7 +++++++ .../api_swagger_v2_definitions-models_spec.rb | 3 ++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f5505a..addaf938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/spec/support/model_parsers/entity_parser.rb b/spec/support/model_parsers/entity_parser.rb index a0123dae..05a3e1b0 100644 --- a/spec/support/model_parsers/entity_parser.rb +++ b/spec/support/model_parsers/entity_parser.rb @@ -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 @@ -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 diff --git a/spec/support/model_parsers/mock_parser.rb b/spec/support/model_parsers/mock_parser.rb index 3d5f4ad0..91be4c99 100644 --- a/spec/support/model_parsers/mock_parser.rb +++ b/spec/support/model_parsers/mock_parser.rb @@ -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 @@ -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 diff --git a/spec/support/model_parsers/representable_parser.rb b/spec/support/model_parsers/representable_parser.rb index 2f8be824..8093b3d5 100644 --- a/spec/support/model_parsers/representable_parser.rb +++ b/spec/support/model_parsers/representable_parser.rb @@ -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 diff --git a/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb b/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb index 3da049f3..6cd3583e 100644 --- a/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +++ b/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb @@ -11,7 +11,8 @@ class ModelApi < Grape::API add_swagger_documentation models: [ ::Entities::UseResponse, ::Entities::ApiError, - ::Entities::RecursiveModel + ::Entities::RecursiveModel, + ::Entities::DocumentedHashAndArrayModel ] end end