Repository navigation
Expand file tree
/
Copy pathparameter_test.go
More file actions
124 lines (120 loc) · 4.1 KB
/
Copy pathparameter_test.go
File metadata and controls
124 lines (120 loc) · 4.1 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package openapi_test
import (
"encoding/json/jsontext"
"testing"
"github.com/MarkRosemaker/openapi"
)
func TestParameter_Validate_Error(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
p openapi.Parameter
err string
}{
{openapi.Parameter{}, "name is required"},
{openapi.Parameter{
Name: "myname",
}, "in is required"},
{openapi.Parameter{
Name: "myname",
In: "foo",
}, `in ("foo") is invalid, must be one of: "path", "query", "header", "cookie"`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
}, "required (false) is invalid: must be true for path parameters"},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
}, "schema or content is required"},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString, Required: []string{"id"}},
}, "schema.required is invalid: only valid for object type, got string"},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
AllowEmptyValue: true,
}, `allowEmptyValue (true) is invalid: can only be true for query parameters, got "path"`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
AllowReserved: true,
}, `allowReserved (true) is invalid: only applies to query parameters, got "path"`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
Content: openapi.Content{},
}, `schema and content are mutually exclusive`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Content: openapi.Content{},
}, `content is invalid: must contain exactly one entry, got 0`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Content: openapi.Content{"foo/bar; baz": {}},
}, `content["foo/bar; baz"]: mime: invalid media parameter`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Content: openapi.Content{"foo": {}},
Style: "foo",
}, `style ("foo") is invalid, must be one of: "matrix", "label", "form", "simple", "spaceDelimited", "pipeDelimited", "deepObject"`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Content: openapi.Content{"foo": {}},
Explode: yes,
}, `explode (true) is invalid: property has no effect when schema is not present`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
Explode: yes,
}, `explode (true) is invalid: property has no effect when schema type is not array or object, got "string"`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
Example: jsontext.Value("foo"),
Examples: openapi.Examples{},
}, `example and examples are mutually exclusive`},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationPath,
Required: true,
Schema: &openapi.Schema{Type: openapi.TypeString},
Extensions: []byte(`{"foo": "bar"}`),
}, `foo: ` + openapi.ErrUnknownField.Error()},
{openapi.Parameter{
Name: "myname",
In: openapi.ParameterLocationQuery,
Schema: &openapi.Schema{Type: openapi.TypeString},
Examples: openapi.Examples{
"foo": invalidExample,
},
}, `examples["foo"]: value and externalValue are mutually exclusive`},
} {
t.Run(tc.err, func(t *testing.T) {
if err := tc.p.Validate(); err == nil || err.Error() != tc.err {
t.Fatalf("want: %s, got: %s", tc.err, err)
}
})
}
}