diff --git a/parser/example.go b/parser/example.go index de91506..b10faf3 100644 --- a/parser/example.go +++ b/parser/example.go @@ -18,7 +18,11 @@ func (d *Definition) Example(o Object) (map[string]interface{}, error) { if err != nil { return nil, err } - obj[field.NameLowerCamel] = example + if field.Type.Multiple { + obj[field.NameLowerCamel] = []interface{}{example, example} + } else { + obj[field.NameLowerCamel] = example + } continue } obj[field.NameLowerCamel] = field.Example diff --git a/parser/example_test.go b/parser/example_test.go index 53f767c..0b2c1c3 100644 --- a/parser/example_test.go +++ b/parser/example_test.go @@ -36,6 +36,16 @@ func TestObjectExample(t *testing.T) { CleanObjectName: "obj2", }, }, + { + Name: "SomeObject", + NameLowerCamel: "someObject", + Type: FieldType{ + TypeName: "obj3", + IsObject: true, + CleanObjectName: "obj3", + Multiple: false, + }, + }, { Name: "Tags", NameLowerCamel: "tags", @@ -57,8 +67,24 @@ func TestObjectExample(t *testing.T) { }, }, } + obj3 := Object{ + Name: "obj3", + Fields: []Field{ + { + Name: "Tags", + NameLowerCamel: "tags", + Example: []interface{}{"one", "two", "three"}, + Type: FieldType{ + TypeName: "obj2", + CleanObjectName: "obj2", + Multiple: true, + IsObject: true, + }, + }, + }, + } def := &Definition{ - Objects: []Object{obj1, obj2}, + Objects: []Object{obj1, obj2, obj3}, } example, err := def.Example(obj1) is.NoErr(err) @@ -82,7 +108,7 @@ func TestObjectExample(t *testing.T) { exampleJSON, err := def.Example(obj1) is.NoErr(err) - is.Equal(len(exampleJSON), 5) + is.Equal(len(exampleJSON), 6) is.Equal(len(exampleJSON["tags"].([]interface{})), 3) is.Equal(exampleJSON["tags"].([]interface{})[0], "security")