-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths_test.go
68 lines (61 loc) · 1.62 KB
/
paths_test.go
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
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
)
func TestPaths_JSON(t *testing.T) {
t.Parallel()
testJSON(t, []byte(`{
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"responses": {
"200": {
"description": "A list of pets.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/pet"
}
}
}
}
}
}
}
}
}`), &openapi.Paths{})
}
func TestPaths_Validate_Error(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
paths openapi.Paths
err string
}{
{openapi.Paths{"foo": {}}, `["foo"]: path must start with a /`},
{openapi.Paths{"/": {
Get: &openapi.Operation{
Servers: openapi.Servers{{}},
},
}}, `["/"].GET.servers[0].url is required`},
{openapi.Paths{"/": {
Get: &openapi.Operation{OperationID: "myOperation"},
Patch: &openapi.Operation{OperationID: "myOperation"},
}}, `["/"].GET.operationId ("myOperation") is invalid: must be unique` + "\n" +
`["/"].PATCH.operationId ("myOperation") is invalid: must be unique`},
{openapi.Paths{"/user/{id}": {
Get: &openapi.Operation{},
}}, `["/user/{id}"].GET.parameters: {id} not defined`},
} {
t.Run(tc.err, func(t *testing.T) {
t.Parallel()
if err := tc.paths.Validate(); err == nil {
t.Fatal("expected error")
} else if err.Error() != tc.err {
t.Fatalf("got: %v, want: %v", err, tc.err)
}
})
}
}