-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathexample_test.go
More file actions
58 lines (49 loc) · 1.17 KB
/
example_test.go
File metadata and controls
58 lines (49 loc) · 1.17 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
package diff_test
import (
"fmt"
"os"
"github.com/getkin/kin-openapi/openapi3"
"github.com/oasdiff/oasdiff/diff"
"go.yaml.in/yaml/v3"
)
func ExampleGet() {
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
s1, err := loader.LoadFromFile("../data/simple1.yaml")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load spec: %v", err)
return
}
s2, err := loader.LoadFromFile("../data/simple2.yaml")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load spec: %v", err)
return
}
diffReport, err := diff.Get(diff.NewConfig(), s1, s2)
if err != nil {
fmt.Fprintf(os.Stderr, "diff failed with %v", err)
return
}
bytes, err := yaml.Marshal(diffReport)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to marshal result with %v", err)
return
}
fmt.Printf("%s\n", bytes)
// Output:
// paths:
// modified:
// /api/test:
// operations:
// added:
// - POST
// deleted:
// - GET
// endpoints:
// added:
// - method: POST
// path: /api/test
// deleted:
// - method: GET
// path: /api/test
}