forked from emicklei/swagger2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_builder_test.go
More file actions
52 lines (47 loc) · 1.14 KB
/
schema_builder_test.go
File metadata and controls
52 lines (47 loc) · 1.14 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
package swagger2
import (
"encoding/json"
"net"
"testing"
)
type fakeint int
type Annoted struct {
Name string `description:"name" modelDescription:"a test"`
Happy bool `json:"happy"`
Stati string `enum:"off|on" default:"on" modelDescription:"more description"`
ID string `unique:"true"`
FakeInt fakeint `type:"integer"`
IP net.IP `type:"string"`
}
func TestSchemaPrimitives(t *testing.T) {
for _, each := range []struct {
value interface{}
result string
}{
{"string", `{"type":"string"}`},
{42, `{"type":"integer"}`},
{int8(42), `{"type":"integer"}`},
{int16(42), `{"type":"integer"}`},
{uint8(42), `{"type":"integer"}`},
{uint16(42), `{"type":"integer"}`},
{int32(42), `{"type":"integer"}`},
{int64(42), `{"type":"integer"}`},
{uint32(42), `{"type":"integer"}`},
{uint64(42), `{"type":"integer"}`},
{false, `{"type":"bool"}`},
{nil, `null`},
} {
b := NewSchemaBuilder()
{
got := doc(b.Build(each.value))
want := each.result
if got != want {
t.Errorf("got %v want %v", got, want)
}
}
}
}
func doc(v interface{}) string {
data, _ := json.Marshal(v)
return string(data)
}