2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								require  'spec_helper'  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								describe  'exposing'  do  
						 
					
						
							
								
									
										
										
										
											2015-12-18 05:12:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  include_context  " the api entities " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  before  :all  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    module  TheApi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      class  ResponseApi  <  Grape :: API 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        format  :json 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        desc  'This returns something' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          params :  Entities :: UseResponse . documentation , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          failure :  [ { code :  400 ,  message :  'NotFound' ,  model :  Entities :: ApiError } ] 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        post  '/params_response'  do 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								          {  " declared_params "  = >  declared ( params )  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        desc  'This returns something' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          entity :  Entities :: UseResponse , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          failure :  [ { code :  400 ,  message :  'NotFound' ,  model :  Entities :: ApiError } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        get  '/entity_response'  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          {  " declared_params "  = >  declared ( params )  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        add_swagger_documentation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  def  app 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    TheApi :: ResponseApi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  describe  " uses entity as response object "  do 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    subject  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      get  '/swagger_doc/entity_response' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      JSON . parse ( last_response . body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    specify  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      expect ( subject ) . to  eql ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " info " = > { " title " = > " API title " ,  " version " = > " v1 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " swagger " = > " 2.0 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " produces " = > [ " application/json " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " host " = > " example.org " , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 23:37:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " tags "  = >  [ { " name " = > " params_response " ,  " description " = > " Operations about params_responses " } ,  { " name " = > " entity_response " ,  " description " = > " Operations about entity_responses " } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " schemes " = > [ " https " ,  " http " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " paths " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          " /entity_response " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " get " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								              " produces " = > [ " application/json " ] , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 23:37:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " tags " = > [ " entity_response " ] , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-16 00:53:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " operationId " = > " getEntityResponse " , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " responses " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " 200 " = > { " description " = > " This returns something " ,  " schema " = > { " $ref " = > " # /definitions/UseResponse " } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " 400 " = > { " description " = > " NotFound " ,  " schema " = > { " $ref " = > " # /definitions/ApiError " } } } } } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " definitions " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          " ResponseItem " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " type " = > " object " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " properties " = > { " id " = > { " type " = > " integer " } ,  " name " = > { " type " = > " string " } } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          " UseResponse " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " type " = > " object " , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-04 09:08:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " properties " = > { " description " = > { " type " = > " string " } ,  " $responses " = > { " type " = > " array " ,  " items " = > { " $ref " = > " # /definitions/ResponseItem " } } } } , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          " ApiError " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " type " = > " object " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " properties " = > { " code " = > { " type " = > " integer " } ,  " message " = > { " type " = > " string " } } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } } ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  describe  " uses params as response object "  do 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    subject  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      get  '/swagger_doc/params_response' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      JSON . parse ( last_response . body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # usage of grape-entity 0.4.8 preduces a wrong definition for ParamsResponse, this one: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # "definitions" => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    #   "ParamsResponse"=>{"properties"=>{"description"=>{"type"=>"string"}}}, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    #   "ApiError"=>{"type"=>"object", "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # (`$response` property is missing) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    specify  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      expect ( subject ) . to  eql ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " info " = > { " title " = > " API title " ,  " version " = > " v1 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " swagger " = > " 2.0 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " produces " = > [ " application/json " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " host " = > " example.org " , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 23:37:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " tags "  = >  [ { " name " = > " params_response " ,  " description " = > " Operations about params_responses " } ,  { " name " = > " entity_response " ,  " description " = > " Operations about entity_responses " } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " schemes " = > [ " https " ,  " http " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " paths " = > { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          " /params_response " = > { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " post " = > { 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " produces " = > [ " application/json " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								              " parameters " = > [ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                { " in " = > " formData " ,  " name " = > " description " ,  " description " = > nil ,  " type " = > " string " ,  " required " = > false ,  " allowMultiple " = > false } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " in " = > " formData " ,  " name " = > " $responses " ,  " description " = > nil ,  " type " = > " string " ,  " required " = > false ,  " allowMultiple " = > true } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-09 23:37:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " tags " = > [ " params_response " ] , 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-16 00:53:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " operationId " = > " postParamsResponse " , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								              " responses " = > { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " 201 " = > { " description " = > " This returns something " ,  " schema " = > { " $ref " = > " # /definitions/ParamsResponse " } } , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " 400 " = > { " description " = > " NotFound " ,  " schema " = > { " $ref " = > " # /definitions/ApiError " } } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " definitions " = > { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-29 06:22:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          " ParamsResponse " = > { " properties " = > { " description " = > { " type " = > " string " } ,  " $responses " = > { " type " = > " string " } } } , 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 01:40:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          " ApiError " = > { " type " = > " object " ,  " properties " = > { " code " = > { " type " = > " integer " } ,  " message " = > { " type " = > " string " } } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } } ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-09 20:40:33 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								end