Skip to content

Commit

Permalink
Generate pointer type for array of objects (a-h#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineco authored and a-h committed Apr 14, 2018
1 parent 5460062 commit 7ced4c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func getTypeForField(parentTypeKey *url.URL, fieldName string, fieldGoName strin

// Find named array references.
if majorType == "array" {
s, _ := getTypeForField(parentTypeKey, fieldName, fieldGoName, fieldSchema.Items, types, false)
s, _ := getTypeForField(parentTypeKey, fieldName, fieldGoName, fieldSchema.Items, types, true)
subType = s
}

Expand Down Expand Up @@ -323,7 +323,6 @@ func getPrimitiveTypeName(schemaType string, subType string, pointer bool) (name
if pointer {
return "*" + subType, nil
}

return subType, nil
case "string":
return "string", nil
Expand Down
6 changes: 3 additions & 3 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestFieldGenerationWithArrayReferences(t *testing.T) {
}

testField(result["Property1"], "property1", "Property1", "string", false, t)
testField(result["Property2"], "property2", "Property2", "[]Address", true, t)
testField(result["Property2"], "property2", "Property2", "[]*Address", true, t)
testField(result["Property3"], "property3", "Property3", "[]map[string]int", false, t)
}

Expand Down Expand Up @@ -393,8 +393,8 @@ func TestNestedArrayGeneration(t *testing.T) {
if !ok {
t.Errorf("Expected to find the Cities field on the FavouriteBars, but didn't. The struct is %+v", fbStruct)
}
if f.Type != "[]City" {
t.Errorf("Expected to find that the Cities array was of type City, but it was of %s", f.Type)
if f.Type != "[]*City" {
t.Errorf("Expected to find that the Cities array was of type *City, but it was of %s", f.Type)
}

f, ok = fbStruct.Fields["Tags"]
Expand Down

0 comments on commit 7ced4c9

Please sign in to comment.