File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'headers' do
6
+ include_context "#{ MODEL_PARSER } swagger example"
7
+
8
+ before :all do
9
+ module TheApi
10
+ class HeadersApi < Grape ::API
11
+ format :json
12
+
13
+ desc 'This returns something' ,
14
+ failure : [ { code : 400 , model : Entities ::ApiError } ] ,
15
+ headers : {
16
+ 'X-Rate-Limit-Limit' => {
17
+ 'description' => 'The number of allowed requests in the current period' ,
18
+ 'type' => 'integer'
19
+ }
20
+ } ,
21
+
22
+ entity : Entities ::UseResponse
23
+ params do
24
+ optional :param_x , type : String , desc : 'This is a parameter' , documentation : { param_type : 'query' }
25
+ end
26
+ get '/use_headers' do
27
+ { 'declared_params' => declared ( params ) }
28
+ end
29
+
30
+ add_swagger_documentation openapi_version : '3.0'
31
+ end
32
+ end
33
+ end
34
+
35
+ def app
36
+ TheApi ::HeadersApi
37
+ end
38
+
39
+ subject do
40
+ get '/swagger_doc'
41
+ JSON . parse ( last_response . body )
42
+ end
43
+
44
+ specify do
45
+ parameters = subject [ 'paths' ] [ '/use_headers' ] [ 'get' ] [ 'parameters' ]
46
+ expect ( parameters ) . to include (
47
+ 'in' => 'header' ,
48
+ 'name' => 'X-Rate-Limit-Limit' ,
49
+ 'description' => 'The number of allowed requests in the current period' ,
50
+ 'schema' => { 'format' => 'int32' , 'type' => 'integer' } ,
51
+ 'required' => false
52
+ )
53
+ expect ( parameters . size ) . to eq ( 2 )
54
+ expect ( parameters . first [ 'in' ] ) . to eq ( 'header' )
55
+ expect ( parameters . last [ 'in' ] ) . to eq ( 'query' )
56
+ end
57
+ end
You can’t perform that action at this time.
0 commit comments