1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package spec
16
17 import (
18 "testing"
19 )
20
21 func TestPropertySerialization(t *testing.T) {
22 strProp := StringProperty()
23 strProp.Enum = append(strProp.Enum, "a", "b")
24
25 prop := &Schema{SchemaProps: SchemaProps{
26 Items: &SchemaOrArray{Schemas: []Schema{
27 {SchemaProps: SchemaProps{Type: []string{"string"}}},
28 {SchemaProps: SchemaProps{Type: []string{"string"}}},
29 }},
30 }}
31
32 var propSerData = []struct {
33 Schema *Schema
34 JSON string
35 }{
36 {BooleanProperty(), `{"type":"boolean"}`},
37 {DateProperty(), `{"type":"string","format":"date"}`},
38 {DateTimeProperty(), `{"type":"string","format":"date-time"}`},
39 {Float64Property(), `{"type":"number","format":"double"}`},
40 {Float32Property(), `{"type":"number","format":"float"}`},
41 {Int32Property(), `{"type":"integer","format":"int32"}`},
42 {Int64Property(), `{"type":"integer","format":"int64"}`},
43 {MapProperty(StringProperty()), `{"type":"object","additionalProperties":{"type":"string"}}`},
44 {MapProperty(Int32Property()), `{"type":"object","additionalProperties":{"type":"integer","format":"int32"}}`},
45 {RefProperty("Dog"), `{"$ref":"Dog"}`},
46 {StringProperty(), `{"type":"string"}`},
47 {strProp, `{"type":"string","enum":["a","b"]}`},
48 {ArrayProperty(StringProperty()), `{"type":"array","items":{"type":"string"}}`},
49 {prop, `{"items":[{"type":"string"},{"type":"string"}]}`},
50 }
51
52 for _, v := range propSerData {
53 t.Log("roundtripping for", v.JSON)
54 assertSerializeJSON(t, v.Schema, v.JSON)
55 assertParsesJSON(t, v.JSON, v.Schema)
56 }
57
58 }
59
View as plain text