-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_test.v
88 lines (72 loc) · 2.52 KB
/
parameter_test.v
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
module openapi
import os
fn test_parameter_header_struct() ? {
content := os.read_file(@VMODROOT + '/testdata/parameter_header.json')?
parameter := decode<Parameter>(content)?
assert parameter.name == 'token'
assert parameter.location == 'header'
assert parameter.description == 'token to be passed as a header'
assert parameter.required == true
assert parameter.style == 'simple'
}
fn test_parameter_path_struct() ? {
content := os.read_file(@VMODROOT + '/testdata/parameter_path.json')?
parameter := decode<Parameter>(content)?
assert parameter.name == 'username'
assert parameter.location == 'path'
assert parameter.description == 'username to fetch'
assert parameter.required == true
assert parameter.style == 'simple'
}
fn test_parameter_query_struct() ? {
content := os.read_file(@VMODROOT + '/testdata/parameter_query.json')?
parameter := decode<Parameter>(content)?
assert parameter.name == 'id'
assert parameter.location == 'query'
assert parameter.description == 'ID of the object to fetch'
assert parameter.required == false
assert parameter.style == 'form'
assert parameter.explode == true
}
fn test_parameter_free_struct() ? {
content := os.read_file(@VMODROOT + '/testdata/parameter_free.json')?
parameter := decode<Parameter>(content)?
assert parameter.name == 'freeForm'
assert parameter.location == 'query'
assert parameter.description == ''
assert parameter.required == false
assert parameter.style == 'form'
assert parameter.explode == true
}
fn test_parameter_complex_struct() ? {
content := os.read_file(@VMODROOT + '/testdata/parameter_complex.json')?
parameter := decode<Parameter>(content)?
assert parameter.name == 'coordinates'
assert parameter.location == 'query'
assert parameter.description == ''
assert parameter.required == false
assert parameter.style == 'form'
assert parameter.explode == true
assert parameter.content.len == 1
assert 'application/json' in parameter.content
}
fn test_parameter_struct_without_in() ? {
content := '{ "name": "freeForm" }'
info := decode<Parameter>(content) or { return }
assert false
}
fn test_parameter_struct_without_name() ? {
content := '{ "in": "query" }'
info := decode<Parameter>(content) or { return }
assert false
}
fn test_parameter_struct_without_required() ? {
content := '{ "name": "freeForm", "in": "path" }'
info := decode<Parameter>(content) or { return }
assert false
}
fn test_parameter_struct_without_in_wrong() ? {
content := '{ "name": "freeForm", "in": "aled" }'
info := decode<Parameter>(content) or { return }
assert false
}