@@ -85,6 +85,94 @@ For both raddocs and apitome, start rails server. Then
8585
8686See the ` example `  folder for a sample Rails app that has been documented.  The sample app demonstrates the : open_api  format.
8787
88+ ## Example of spec file  
89+ 
90+ ``` ruby 
91+   #  spec/acceptance/orders_spec.rb
92+   require  ' rails_helper' 
93+   require  ' rspec_api_documentation/dsl' 
94+   resource ' Orders'   do 
95+     explanation " Orders resource" 
96+     
97+     header " Content-Type"  , " application/json" 
98+ 
99+     get ' /orders'   do 
100+       #  This is manual way to describe complex parameters
101+       parameter :one_level_array , type:  :array , items:  {type:  :string , enum:  [' string1'  , ' string2'  ]}, default:  [' string1'  ]
102+       parameter :two_level_array , type:  :array , items:  {type:  :array , items:  {type:  :string }}
103+       
104+       let(:one_level_array ) { [' string1'  , ' string2'  ] }
105+       let(:two_level_array ) { [[' 123'  , ' 234'  ], [' 111'  ]] }
106+ 
107+       #  This is automatic way
108+       #  It's possible because we extract parameters definitions from the values
109+       parameter :one_level_arr , with_example:  true 
110+       parameter :two_level_arr , with_example:  true 
111+ 
112+       let(:one_level_arr ) { [' value1'  , ' value2'  ] }
113+       let(:two_level_arr ) { [[5.1 , 3.0 ], [1.0 , 4.5 ]] }
114+ 
115+       context ' 200'   do 
116+         example_request ' Getting a list of orders'   do 
117+           expect(status).to eq(200 )
118+         end 
119+       end 
120+     end 
121+ 
122+     put ' /orders/:id'   do 
123+ 
124+       with_options scope:  :data , with_example:  true  do 
125+         parameter :name , ' The order name'  , required:  true 
126+         parameter :amount 
127+         parameter :description , ' The order description' 
128+       end 
129+ 
130+       context " 200"   do 
131+         let(:id ) { 1  }
132+ 
133+         example ' Update an order'   do 
134+           request =  {
135+             data:  {
136+               name:  ' order'  ,
137+               amount:  1 ,
138+               description:  ' fast order' 
139+             }
140+           }
141+           
142+           #  It's also possible to extract types of parameters when you pass data through `do_request` method.
143+           do_request(request)
144+           
145+           expected_response =  {
146+             data:  {
147+               name:  ' order'  ,
148+               amount:  1 ,
149+               description:  ' fast order' 
150+             }
151+           }
152+           expect(status).to eq(200 )
153+           expect(response_body).to eq(expected_response)
154+         end 
155+       end 
156+ 
157+       context " 400"   do 
158+         let(:id ) { " a"   }
159+ 
160+         example_request ' Invalid request'   do 
161+           expect(status).to eq(400 )
162+         end 
163+       end 
164+       
165+       context " 404"   do 
166+         let(:id ) { 0  }
167+         
168+         example_request ' Order is not found'   do 
169+           expect(status).to eq(404 )
170+         end 
171+       end 
172+     end 
173+   end 
174+ ``` 
175+ 
88176
89177## Configuration options  
90178``` ruby 
@@ -319,19 +407,20 @@ paths:
319407      description: This description came from configuration file 
320408      hide: true 
321409``` 
322- 
323- ## Example of acceptance spec file  
324- 
410+ #### Example of spec file with : open_api  format  
325411``` ruby 
326-   #  spec/acceptance/orders_spec.rb
327-   require  ' rails_helper' 
328-   require  ' rspec_api_documentation/dsl' 
329412  resource ' Orders'   do 
330413    explanation " Orders resource" 
331414
415+     authentication :apiKey , :api_key , description:  ' Private key for API access'  , name:  ' HEADER_KEY' 
332416    header " Content-Type"  , " application/json" 
417+     
418+     let(:api_key ) { generate_api_key }
333419
334420    get ' /orders'   do 
421+       route_summary " This URL allows users to interact with all orders." 
422+       route_description " Long description." 
423+ 
335424      #  This is manual way to describe complex parameters
336425      parameter :one_level_array , type:  :array , items:  {type:  :string , enum:  [' string1'  , ' string2'  ]}, default:  [' string1'  ]
337426      parameter :two_level_array , type:  :array , items:  {type:  :array , items:  {type:  :string }}
@@ -350,11 +439,13 @@ paths:
350439      context ' 200'   do 
351440        example_request ' Getting a list of orders'   do 
352441          expect(status).to eq(200 )
442+           expect(response_body).to eq(< response> )
353443        end 
354444      end 
355445    end 
356446
357447    put ' /orders/:id'   do 
448+       route_summary " This is used to update orders." 
358449
359450      with_options scope:  :data , with_example:  true  do 
360451        parameter :name , ' The order name'  , required:  true 
@@ -385,7 +476,7 @@ paths:
385476            }
386477          }
387478          expect(status).to eq(200 )
388-           expect(response_body).to eq(expected_response )
479+           expect(response_body).to eq(< response > )
389480        end 
390481      end 
391482
0 commit comments