Skip to content

Commit 36ab805

Browse files
lstollcyberdelia
authored andcommitted
Don't need pointers to have nilable interface, string or map. (#49)
This types can be nilable, so don't need the additional indirection to differ between empty and nil.
1 parent 4828431 commit 36ab805

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

gen.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ func (s *Schema) goType(required bool, force bool) (goType string) {
222222
}
223223
// Types allow null
224224
if contains("null", types) || !(required || force) {
225-
return "*" + goType
225+
// Don't need a pointer for these types to be "nilable"
226+
if goType != "interface{}" && !strings.HasPrefix(goType, "[]") && !strings.HasPrefix(goType, "map[") {
227+
return "*" + goType
228+
}
226229
}
227230
return goType
228231
}

gen_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ var typeTests = []struct {
192192
},
193193
Type: "*time.Time",
194194
},
195+
{
196+
Schema: &Schema{
197+
Type: []interface{}{"null", "array"},
198+
Items: &Schema{
199+
Type: "string",
200+
},
201+
},
202+
Type: "[]string",
203+
},
204+
{
205+
Schema: &Schema{
206+
Type: "any",
207+
},
208+
Type: "interface{}",
209+
},
195210
}
196211

197212
func TestSchemaType(t *testing.T) {

0 commit comments

Comments
 (0)