-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathmodel_openapiv3_test.go
55 lines (46 loc) · 1.18 KB
/
model_openapiv3_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
package surface_v1
import (
"os"
"testing"
openapiv3 "github.com/google/gnostic/openapiv3"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/testing/protocmp"
)
func TestModelOpenAPIV3(t *testing.T) {
refFile := "testdata/v3.0/petstore.json"
modelFile := "testdata/v3.0/petstore.model.json"
bFile, err := os.ReadFile(refFile)
if err != nil {
t.Logf("Failed to read file: %+v", err)
t.FailNow()
}
bModel, err := os.ReadFile(modelFile)
if err != nil {
t.Logf("Failed to read file: %+v", err)
t.FailNow()
}
docv3, err := openapiv3.ParseDocument(bFile)
if err != nil {
t.Logf("Failed to parse document: %+v", err)
t.FailNow()
}
m, err := NewModelFromOpenAPI3(docv3, refFile)
if err != nil {
t.Logf("Failed to create model: %+v", err)
t.FailNow()
}
var model Model
if err := protojson.Unmarshal(bModel, &model); err != nil {
t.Logf("Failed to unmarshal model: %+v", err)
t.FailNow()
}
cmpOpts := []cmp.Option{
protocmp.Transform(),
}
if diff := cmp.Diff(&model, m, cmpOpts...); diff != "" {
t.Errorf("Model mismatch (-want +got):\n%s", diff)
}
x, _ := protojson.Marshal(m)
t.Logf("Model: %s", x)
}