Skip to content

Commit edb15b5

Browse files
blakenumbata
authored andcommitted
Add test
1 parent bb91823 commit edb15b5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'body parameter definitions' do
6+
before :all do
7+
module TheBodyApi
8+
class Endpoint < Grape::API
9+
resource :endpoint do
10+
desc 'The endpoint' do
11+
headers XAuthToken: {
12+
description: 'Valdates your identity',
13+
required: true
14+
}
15+
params body_param: { type: 'String', desc: 'param', documentation: { in: 'body' } },
16+
body_type_as_const_param: { type: String, desc: 'string_param', documentation: { in: 'body' } }
17+
end
18+
19+
post do
20+
{ 'declared_params' => declared(params) }
21+
end
22+
end
23+
24+
add_swagger_documentation openapi_version: '3.0'
25+
end
26+
end
27+
end
28+
29+
def app
30+
TheBodyApi::Endpoint
31+
end
32+
33+
subject do
34+
get '/swagger_doc'
35+
JSON.parse(last_response.body)
36+
end
37+
38+
context 'a definition is generated for the endpoints parameters defined within the desc block' do
39+
specify do
40+
expect(subject['components']['schemas']['postEndpoint']['properties']).to eql(
41+
'body_param' => { 'type' => 'string', 'description' => 'param' },
42+
'body_type_as_const_param' => { 'type' => 'string', 'description' => 'string_param' }
43+
)
44+
45+
expect(subject['paths']['/endpoint']['post']['parameters'].any? { |p| p['name'] == 'XAuthToken' && p['in'] == 'header' }).to eql(true)
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)