-
-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathissue341_test.go
80 lines (72 loc) · 1.4 KB
/
issue341_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
69
70
71
72
73
74
75
76
77
78
79
80
package openapi3
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestIssue341(t *testing.T) {
sl := NewLoader()
sl.IsExternalRefsAllowed = true
doc, err := sl.LoadFromFile("testdata/main.yaml")
require.NoError(t, err)
err = doc.Validate(sl.Context)
require.NoError(t, err)
err = sl.ResolveRefsIn(doc, nil)
require.NoError(t, err)
bs, err := doc.MarshalJSON()
require.NoError(t, err)
require.JSONEq(t, `{
"info": {
"title": "test file",
"version": "n/a"
},
"openapi": "3.0.0",
"paths": {
"/testpath": {
"$ref": "testpath.yaml#/paths/~1testpath"
}
}
}`, string(bs))
require.Equal(t, &Types{"string"}, doc.
Paths.Value("/testpath").
Get.
Responses.Value("200").Value.
Content["application/json"].
Schema.Value.
Type)
doc.InternalizeRefs(context.Background(), nil)
bs, err = doc.MarshalJSON()
require.NoError(t, err)
require.JSONEq(t, `{
"components": {
"responses": {
"testpath_testpath_200_response": {
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
},
"description": "a custom response"
}
}
},
"info": {
"title": "test file",
"version": "n/a"
},
"openapi": "3.0.0",
"paths": {
"/testpath": {
"get": {
"responses": {
"200": {
"$ref": "#/components/responses/testpath_testpath_200_response"
}
}
}
}
}
}`, string(bs))
}