-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema_test.go
64 lines (59 loc) · 1.32 KB
/
schema_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
package openapi_test
import (
"encoding/json"
"testing"
"github.com/chanced/openapi"
"github.com/chanced/uri"
)
func TestSchema(t *testing.T) {
bs := []byte(`true`)
var s openapi.Schema
err := json.Unmarshal(bs, &s)
if err != nil {
t.Error(err)
}
sb, err := s.MarshalJSON()
if err != nil {
t.Error(err)
}
if string(sb) != "true" {
t.Errorf("expected %q, got %q", "true", string(sb))
}
var s2 openapi.Schema
bs = []byte(`{"keyword": "value"}`)
err = json.Unmarshal(bs, &s2)
if err != nil {
t.Error(err)
}
if string(s2.Keywords["keyword"]) != `"value"` {
t.Errorf("expected %q, got %q", "value", s2.Keywords["keyword"])
}
br, err := s2.MarshalJSON()
if err != nil {
t.Error(err)
}
_ = br
// fmt.Println(string(br))
}
func TestClone(t *testing.T) {
s := openapi.Schema{
If: &openapi.Schema{
Format: "format",
},
Schema: uri.MustParse("https://json-schema.org/draft/2019-09/schema"),
ID: uri.MustParse("http://example.com/schema"),
Ref: &openapi.SchemaRef{
Ref: uri.MustParse("http://example.com/schema2"),
Resolved: &openapi.Schema{
ID: uri.MustParse("http://example.com/resolved"),
},
},
}
s2 := s.Clone()
if s2.If.Format != "format" {
t.Errorf("expected %q, got %q", "format", s2.If.Format)
}
if s2.Ref.Resolved == nil {
t.Error("expected resolved schema, got nil")
}
}