| 
									
										
										
										
											2017-03-08 16:32:31 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2017-03-28 17:15:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 09:12:26 +08:00
										 |  |  | RSpec.shared_context 'entity swagger example' do | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  |   before :all do | 
					
						
							|  |  |  |     module Entities | 
					
						
							|  |  |  |       class Something < Grape::Entity | 
					
						
							|  |  |  |         expose :id, documentation: { type: Integer, desc: 'Identity of Something' } | 
					
						
							|  |  |  |         expose :text, documentation: { type: String, desc: 'Content of something.' } | 
					
						
							|  |  |  |         expose :links, documentation: { type: 'link', is_array: true } | 
					
						
							|  |  |  |         expose :others, documentation: { type: 'text', is_array: false } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class EnumValues < Grape::Entity | 
					
						
							|  |  |  |         expose :gender, documentation: { type: 'string', desc: 'Content of something.', values: %w(Male Female) } | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         expose :number, documentation: { type: 'integer', desc: 'Content of something.', values: [1, 2] } | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class AliasedThing < Grape::Entity | 
					
						
							|  |  |  |         expose :something, as: :post, using: Entities::Something, documentation: { type: 'Something', desc: 'Reference to something.' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class FourthLevel < Grape::Entity | 
					
						
							|  |  |  |         expose :text, documentation: { type: 'string' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class ThirdLevel < Grape::Entity | 
					
						
							|  |  |  |         expose :parts, using: Entities::FourthLevel, documentation: { type: 'FourthLevel' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class SecondLevel < Grape::Entity | 
					
						
							|  |  |  |         expose :parts, using: Entities::ThirdLevel, documentation: { type: 'ThirdLevel' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class FirstLevel < Grape::Entity | 
					
						
							|  |  |  |         expose :parts, using: Entities::SecondLevel, documentation: { type: 'SecondLevel' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class QueryInputElement < Grape::Entity | 
					
						
							|  |  |  |         expose :key, documentation: { | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           type: String, desc: 'Name of parameter', required: true | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  |         expose :value, documentation: { | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           type: String, desc: 'Value of parameter', required: true | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class QueryInput < Grape::Entity | 
					
						
							|  |  |  |         expose :elements, using: Entities::QueryInputElement, documentation: { | 
					
						
							|  |  |  |           type: 'QueryInputElement', | 
					
						
							|  |  |  |           desc: 'Set of configuration', | 
					
						
							|  |  |  |           param_type: 'body', | 
					
						
							|  |  |  |           is_array: true, | 
					
						
							|  |  |  |           required: true | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class ApiError < Grape::Entity | 
					
						
							|  |  |  |         expose :code, documentation: { type: Integer, desc: 'status code' } | 
					
						
							|  |  |  |         expose :message, documentation: { type: String, desc: 'error message' } | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-05-07 09:12:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 05:06:03 +08:00
										 |  |  |       module NestedModule | 
					
						
							|  |  |  |         class ApiResponse < Grape::Entity | 
					
						
							|  |  |  |           expose :status, documentation: { type: String } | 
					
						
							|  |  |  |           expose :error, documentation: { type: ::Entities::ApiError } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 09:12:26 +08:00
										 |  |  |       class SecondApiError < Grape::Entity | 
					
						
							|  |  |  |         expose :code, documentation: { type: Integer } | 
					
						
							|  |  |  |         expose :severity, documentation: { type: String } | 
					
						
							|  |  |  |         expose :message, documentation: { type: String } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class ResponseItem < Grape::Entity | 
					
						
							|  |  |  |         expose :id, documentation: { type: Integer } | 
					
						
							|  |  |  |         expose :name, documentation: { type: String } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class OtherItem < Grape::Entity | 
					
						
							|  |  |  |         expose :key, documentation: { type: Integer } | 
					
						
							|  |  |  |         expose :symbol, documentation: { type: String } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class UseResponse < Grape::Entity | 
					
						
							|  |  |  |         expose :description, documentation: { type: String } | 
					
						
							|  |  |  |         expose :items, as: '$responses', using: Entities::ResponseItem, documentation: { is_array: true } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class UseItemResponseAsType < Grape::Entity | 
					
						
							|  |  |  |         expose :description, documentation: { type: String } | 
					
						
							|  |  |  |         expose :responses, documentation: { type: Entities::ResponseItem, is_array: false } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class UseAddress < Grape::Entity | 
					
						
							|  |  |  |         expose :street, documentation: { type: String, desc: 'street' } | 
					
						
							|  |  |  |         expose :postcode, documentation: { type: String, desc: 'postcode' } | 
					
						
							|  |  |  |         expose :city, documentation: { type: String, desc: 'city' } | 
					
						
							|  |  |  |         expose :country, documentation: { type: String, desc: 'country' } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class UseNestedWithAddress < Grape::Entity | 
					
						
							|  |  |  |         expose :name, documentation: { type: String } | 
					
						
							|  |  |  |         expose :address, using: Entities::UseAddress | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class TypedDefinition < Grape::Entity | 
					
						
							|  |  |  |         expose :prop_integer,   documentation: { type: Integer, desc: 'prop_integer description' } | 
					
						
							|  |  |  |         expose :prop_long,      documentation: { type: Numeric, desc: 'prop_long description' } | 
					
						
							|  |  |  |         expose :prop_float,     documentation: { type: Float, desc: 'prop_float description' } | 
					
						
							|  |  |  |         expose :prop_double,    documentation: { type: BigDecimal, desc: 'prop_double description' } | 
					
						
							|  |  |  |         expose :prop_string,    documentation: { type: String, desc: 'prop_string description' } | 
					
						
							|  |  |  |         expose :prop_symbol,    documentation: { type: Symbol, desc: 'prop_symbol description' } | 
					
						
							|  |  |  |         expose :prop_date,      documentation: { type: Date, desc: 'prop_date description' } | 
					
						
							|  |  |  |         expose :prop_date_time, documentation: { type: DateTime, desc: 'prop_date_time description' } | 
					
						
							|  |  |  |         expose :prop_time,      documentation: { type: Time, desc: 'prop_time description' } | 
					
						
							|  |  |  |         expose :prop_password,  documentation: { type: 'password', desc: 'prop_password description' } | 
					
						
							|  |  |  |         expose :prop_email,     documentation: { type: 'email', desc: 'prop_email description' } | 
					
						
							|  |  |  |         expose :prop_boolean,   documentation: { type: Virtus::Attribute::Boolean, desc: 'prop_boolean description' } | 
					
						
							|  |  |  |         expose :prop_file,      documentation: { type: File, desc: 'prop_file description' } | 
					
						
							|  |  |  |         expose :prop_json,      documentation: { type: JSON, desc: 'prop_json description' } | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-05-11 03:42:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       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 | 
					
						
							| 
									
										
										
										
											2016-06-14 20:12:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       class DocumentedHashAndArrayModel < Grape::Entity | 
					
						
							|  |  |  |         expose :raw_hash, documentation: { type: Hash, desc: 'Example Hash.', documentation: { in: 'body' } } | 
					
						
							|  |  |  |         expose :raw_array, documentation: { type: Array, desc: 'Example Array', documentation: { in: 'body' } } | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 09:12:26 +08:00
										 |  |  |   let(:swagger_definitions_models) do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       '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' } } }, | 
					
						
							| 
									
										
										
										
											2016-05-11 03:42:06 +08:00
										 |  |  |       'UseResponse' => { 'type' => 'object', 'properties' => { 'description' => { 'type' => 'string' }, '$responses' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/ResponseItem' } } } }, | 
					
						
							| 
									
										
										
										
											2016-06-14 20:12:46 +08:00
										 |  |  |       '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' } } } | 
					
						
							| 
									
										
										
										
											2016-05-07 09:12:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:swagger_nested_type) do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       'ApiError' => { 'type' => 'object', 'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'status code' }, 'message' => { 'type' => 'string', 'description' => 'error message' } }, 'description' => 'This returns something' }, | 
					
						
							|  |  |  |       'ResponseItem' => { 'type' => 'object', 'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int32' }, 'name' => { 'type' => 'string' } } }, | 
					
						
							|  |  |  |       'UseItemResponseAsType' => { 'type' => 'object', 'properties' => { 'description' => { 'type' => 'string' }, 'responses' => { '$ref' => '#/definitions/ResponseItem' } }, 'description' => 'This returns something' } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:swagger_entity_as_response_object) do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       'ApiError' => { 'type' => 'object', 'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'status code' }, 'message' => { 'type' => 'string', 'description' => 'error message' } }, 'description' => 'This returns something' }, | 
					
						
							|  |  |  |       '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' } } }, 'description' => 'This returns something' } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:swagger_params_as_response_object) do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       'ApiError' => { 'type' => 'object', 'properties' => { 'code' => { 'description' => 'status code', 'type' => 'integer', 'format' => 'int32' }, 'message' => { 'description' => 'error message', 'type' => 'string' } }, 'description' => 'This returns something' } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:swagger_typed_defintion) do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       'prop_boolean' => { 'description' => 'prop_boolean description', 'type' => 'boolean' }, | 
					
						
							|  |  |  |       'prop_date' => { 'description' => 'prop_date description', 'type' => 'string', 'format' => 'date' }, | 
					
						
							|  |  |  |       'prop_date_time' => { 'description' => 'prop_date_time description', 'type' => 'string', 'format' => 'date-time' }, | 
					
						
							|  |  |  |       'prop_double' => { 'description' => 'prop_double description', 'type' => 'number', 'format' => 'double' }, | 
					
						
							|  |  |  |       'prop_email' => { 'description' => 'prop_email description', 'type' => 'string', 'format' => 'email' }, | 
					
						
							|  |  |  |       'prop_file' => { 'description' => 'prop_file description', 'type' => 'file' }, | 
					
						
							|  |  |  |       'prop_float' => { 'description' => 'prop_float description', 'type' => 'number', 'format' => 'float' }, | 
					
						
							|  |  |  |       'prop_integer' => { 'description' => 'prop_integer description', 'type' => 'integer', 'format' => 'int32' }, | 
					
						
							|  |  |  |       'prop_json' => { 'description' => 'prop_json description', 'type' => 'json' }, | 
					
						
							|  |  |  |       'prop_long' => { 'description' => 'prop_long description', 'type' => 'integer', 'format' => 'int64' }, | 
					
						
							|  |  |  |       'prop_password' => { 'description' => 'prop_password description', 'type' => 'string', 'format' => 'password' }, | 
					
						
							|  |  |  |       'prop_string' => { 'description' => 'prop_string description', 'type' => 'string' }, | 
					
						
							|  |  |  |       'prop_symbol' => { 'description' => 'prop_symbol description', 'type' => 'string' }, | 
					
						
							|  |  |  |       'prop_time' => { 'description' => 'prop_time description', 'type' => 'string', 'format' => 'date-time' } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:59:11 +08:00
										 |  |  |   let(:swagger_json) do | 
					
						
							| 
									
										
										
										
											2015-12-19 01:40:53 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |       'info' => { | 
					
						
							|  |  |  |         'title' => 'The API title to be displayed on the API homepage.', | 
					
						
							|  |  |  |         'description' => 'A description of the API.', | 
					
						
							|  |  |  |         'termsOfServiceUrl' => 'www.The-URL-of-the-terms-and-service.com', | 
					
						
							|  |  |  |         'contact' => { 'name' => 'Contact name', 'email' => 'Contact@email.com', 'url' => 'Contact URL' }, | 
					
						
							|  |  |  |         'license' => { 'name' => 'The name of the license.', 'url' => 'www.The-URL-of-the-license.org' }, | 
					
						
							|  |  |  |         'version' => '0.0.1' | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |       'swagger' => '2.0', | 
					
						
							|  |  |  |       'produces' => ['application/json'], | 
					
						
							|  |  |  |       'host' => 'example.org', | 
					
						
							|  |  |  |       'basePath' => '/api', | 
					
						
							|  |  |  |       'tags' => [ | 
					
						
							|  |  |  |         { 'name' => 'other_thing', 'description' => 'Operations about other_things' }, | 
					
						
							|  |  |  |         { 'name' => 'thing', 'description' => 'Operations about things' }, | 
					
						
							|  |  |  |         { 'name' => 'thing2', 'description' => 'Operations about thing2s' }, | 
					
						
							|  |  |  |         { 'name' => 'dummy', 'description' => 'Operations about dummies' } | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |       ], | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |       'paths' => { | 
					
						
							|  |  |  |         '/v3/other_thing/{elements}' => { | 
					
						
							|  |  |  |           'get' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'nested route inside namespace', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'nested route inside namespace', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [{ 'in' => 'body', 'name' => 'elements', 'description' => 'Set of configuration', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true }], | 
					
						
							|  |  |  |             'responses' => { '200' => { 'description' => 'nested route inside namespace', 'schema' => { '$ref' => '#/definitions/QueryInput' } } }, | 
					
						
							|  |  |  |             'tags' => ['other_thing'], | 
					
						
							|  |  |  |             'operationId' => 'getV3OtherThingElements', | 
					
						
							|  |  |  |             'x-amazon-apigateway-auth' => { 'type' => 'none' }, | 
					
						
							|  |  |  |             'x-amazon-apigateway-integration' => { 'type' => 'aws', 'uri' => 'foo_bar_uri', 'httpMethod' => 'get' } | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         '/thing' => { | 
					
						
							|  |  |  |           'get' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This gets Things.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This gets Things.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [ | 
					
						
							|  |  |  |               { 'in' => 'query', 'name' => 'id', 'description' => 'Identity of Something', 'type' => 'integer', 'format' => 'int32', 'required' => false }, | 
					
						
							|  |  |  |               { 'in' => 'query', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => false }, | 
					
						
							|  |  |  |               { 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'link' }, 'required' => false }, | 
					
						
							|  |  |  |               { 'in' => 'query', 'name' => 'others', 'type' => 'text', 'required' => false } | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'responses' => { '200' => { 'description' => 'This gets Things.' }, '401' => { 'description' => 'Unauthorized', 'schema' => { '$ref' => '#/definitions/ApiError' } } }, | 
					
						
							|  |  |  |             'tags' => ['thing'], | 
					
						
							|  |  |  |             'operationId' => 'getThing' | 
					
						
							| 
									
										
										
										
											2016-03-30 06:43:33 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'post' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This creates Thing.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This creates Thing.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'consumes' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [ | 
					
						
							|  |  |  |               { 'in' => 'formData', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => true }, | 
					
						
							|  |  |  |               { 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true } | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'responses' => { '201' => { 'description' => 'This creates Thing.', 'schema' => { '$ref' => '#/definitions/Something' } }, '422' => { 'description' => 'Unprocessible Entity' } }, | 
					
						
							|  |  |  |             'tags' => ['thing'], | 
					
						
							|  |  |  |             'operationId' => 'postThing' | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         '/thing/{id}' => { | 
					
						
							|  |  |  |           'get' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This gets Thing.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This gets Thing.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }], | 
					
						
							|  |  |  |             'responses' => { '200' => { 'description' => 'getting a single thing' }, '401' => { 'description' => 'Unauthorized' } }, | 
					
						
							|  |  |  |             'tags' => ['thing'], | 
					
						
							|  |  |  |             'operationId' => 'getThingId' | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'put' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This updates Thing.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This updates Thing.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'consumes' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [ | 
					
						
							|  |  |  |               { 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }, | 
					
						
							|  |  |  |               { 'in' => 'formData', 'name' => 'text', 'description' => 'Content of something.', 'type' => 'string', 'required' => false }, | 
					
						
							|  |  |  |               { 'in' => 'formData', 'name' => 'links', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false } | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'responses' => { '200' => { 'description' => 'This updates Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } }, | 
					
						
							|  |  |  |             'tags' => ['thing'], | 
					
						
							|  |  |  |             'operationId' => 'putThingId' | 
					
						
							| 
									
										
										
										
											2016-04-08 09:05:35 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'delete' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This deletes Thing.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This deletes Thing.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }], | 
					
						
							|  |  |  |             'responses' => { '200' => { 'description' => 'This deletes Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } }, | 
					
						
							|  |  |  |             'tags' => ['thing'], | 
					
						
							|  |  |  |             'operationId' => 'deleteThingId' | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         '/thing2' => { | 
					
						
							|  |  |  |           'get' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'This gets Things.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'This gets Things.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } }, | 
					
						
							|  |  |  |             'tags' => ['thing2'], | 
					
						
							|  |  |  |             'operationId' => 'getThing2' | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         '/dummy/{id}' => { | 
					
						
							|  |  |  |           'delete' => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:23:16 +08:00
										 |  |  |             'summary' => 'dummy route.', | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'description' => 'dummy route.', | 
					
						
							|  |  |  |             'produces' => ['application/json'], | 
					
						
							|  |  |  |             'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }], | 
					
						
							|  |  |  |             'responses' => { '204' => { 'description' => 'dummy route.' }, '401' => { 'description' => 'Unauthorized' } }, | 
					
						
							|  |  |  |             'tags' => ['dummy'], | 
					
						
							|  |  |  |             'operationId' => 'deleteDummyId' | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |       'definitions' => { | 
					
						
							|  |  |  |         'QueryInput' => { | 
					
						
							|  |  |  |           'type' => 'object', | 
					
						
							| 
									
										
										
										
											2016-10-14 17:56:33 +08:00
										 |  |  |           'required' => ['elements'], | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'properties' => { 'elements' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/QueryInputElement' }, 'description' => 'Set of configuration' } }, | 
					
						
							|  |  |  |           'description' => 'nested route inside namespace' | 
					
						
							| 
									
										
										
										
											2016-05-01 18:31:44 +08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         'QueryInputElement' => { | 
					
						
							|  |  |  |           'type' => 'object', | 
					
						
							| 
									
										
										
										
											2016-10-14 17:56:33 +08:00
										 |  |  |           'required' => %w(key value), | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'properties' => { 'key' => { 'type' => 'string', 'description' => 'Name of parameter' }, 'value' => { 'type' => 'string', 'description' => 'Value of parameter' } } | 
					
						
							| 
									
										
										
										
											2016-05-01 18:31:44 +08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         'ApiError' => { | 
					
						
							|  |  |  |           'type' => 'object', | 
					
						
							|  |  |  |           'properties' => { 'code' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'status code' }, 'message' => { 'type' => 'string', 'description' => 'error message' } }, | 
					
						
							|  |  |  |           'description' => 'This gets Things.' | 
					
						
							| 
									
										
										
										
											2016-05-01 18:31:44 +08:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         'Something' => { | 
					
						
							|  |  |  |           'type' => 'object', | 
					
						
							|  |  |  |           'properties' => { | 
					
						
							|  |  |  |             'id' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Identity of Something' }, | 
					
						
							|  |  |  |             'text' => { 'type' => 'string', 'description' => 'Content of something.' }, | 
					
						
							| 
									
										
										
										
											2016-06-08 06:56:00 +08:00
										 |  |  |             'links' => { 'type' => 'array', 'items' => { 'type' => 'link' } }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |             'others' => { 'type' => 'text' } | 
					
						
							| 
									
										
										
										
											2016-05-01 18:31:44 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |           'description' => 'This gets Things.' | 
					
						
							| 
									
										
										
										
											2016-05-11 04:01:13 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-10-01 04:59:11 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |   let(:http_verbs) { %w(get post put delete) } | 
					
						
							| 
									
										
										
										
											2015-10-01 04:59:11 +08:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def mounted_paths | 
					
						
							| 
									
										
										
										
											2016-10-31 19:14:08 +08:00
										 |  |  |   %w(/thing /other_thing /dummy) | 
					
						
							| 
									
										
										
										
											2015-10-03 21:31:30 +08:00
										 |  |  | end |