forked from ruby-grape/grape-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grape-swagger-helper_spec.rb
88 lines (74 loc) · 2.63 KB
/
grape-swagger-helper_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'spec_helper'
describe "helpers" do
before(:all) do
class HelperTestAPI < Grape::API
add_swagger_documentation
end
@api = Object.new
# after injecting grape-swagger into the Test API we get the helper methods
# back from the first endpoint's class (the API mounted by grape-swagger
# to serve the swagger_doc
@api.extend HelperTestAPI.endpoints.first.options[:app].helpers
end
context "parsing parameters" do
it "should parse params as query strings for a GET" do
params = {
name: {type: 'String', :desc => "A name", required: true },
level: 'max'
}
path = "/coolness"
method = "GET"
@api.parse_params(params, path, method).should ==
[
{paramType: "query", name: :name, description:"A name", dataType: "String", required: true},
{paramType: "query", name: :level, description:"", dataType: "String", required: false}
]
end
it "should parse params as body for a POST" do
params = {
name: {type: 'String', :desc =>"A name", required: true },
level: 'max'
}
path = "/coolness"
method = "POST"
@api.parse_params(params, path, method).should ==
[
{paramType: "body", name: :name, description:"A name", dataType: "String", required: true},
{paramType: "body", name: :level, description:"", dataType: "String", required: false}
]
end
end
context "parsing the path" do
it "should parse the path" do
path = ":abc/def(.:format)"
@api.parse_path(path, nil).should == "{abc}/def.{format}"
end
it "should parse a path that has vars with underscores in the name" do
path = "abc/:def_g(.:format)"
@api.parse_path(path, nil).should == "abc/{def_g}.{format}"
end
it "should parse a path that has vars with numbers in the name" do
path = "abc/:sha1(.:format)"
@api.parse_path(path, nil).should == "abc/{sha1}.{format}"
end
it "should parse a path that has multiple variables" do
path1 = "abc/:def/:geh(.:format)"
path2 = "abc/:def:geh(.:format)"
@api.parse_path(path1, nil).should == "abc/{def}/{geh}.{format}"
@api.parse_path(path2, nil).should == "abc/{def}{geh}.{format}"
end
it "should parse the path with a specified version" do
path = ":abc/{version}/def(.:format)"
@api.parse_path(path, 'v1').should == "{abc}/v1/def.{format}"
end
end
context "parsing header parameters" do
it "should parse params for the header" do
params = {"XAuthToken" => { description: "A required header.", required: true}}
@api.parse_header_params(params).should ==
[
{paramType: "header", name: "XAuthToken", description:"A required header.", dataType: "String", required: true}
]
end
end
end